Skip to content

Commit

Permalink
use the public API of nuodb_mgmt (#17)
Browse files Browse the repository at this point in the history
internals are subject to change. Future releases of pynuoadmin will break nuocd. Use public functions only
  • Loading branch information
Martin Kysel authored Nov 24, 2020
1 parent 16cbd1e commit 9767b03
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 59 deletions.
8 changes: 4 additions & 4 deletions nuocd/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ class Monitor:
# (ntime,startId,hostname,pid,dbname,timedelta,fromNodeId,total-ototal,name,numStalls,totalTimeStalls,maxStallTime)

def __init__(self, nuodb_process, conn, relative, args):
self._dbkey = conn._get_db_password(nuodb_process.db_name)
self._process = nuodb_process
self._fullstate = None
self._items = None
#self._interval = 1
self.__session = nuodb_mgmt._monitor_process(self._process.address, self._dbkey)

self.__session = conn.monitor_process(self._process.start_id)

def execute_query(self):
xml_msg = next(self.__session)
_, xml_msg = next(self.__session)
if xml_msg.tag == 'Items':
self._items = {}
for item in xml_msg.findall('Item'):
Expand All @@ -161,7 +161,7 @@ def execute_query(self):
else:
self._items[name] = None
print_("WARN: don't know how to handle item %s..." % (name,), file=sys.stderr)
xml_msg = next(self.__session)
_, xml_msg = next(self.__session)

if xml_msg.tag == 'Status':
#self._interval = 10
Expand Down
44 changes: 17 additions & 27 deletions nuocd/msgtrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,29 @@ class Monitor:

def __init__(self, nuodb_process, conn, relative, args):
self._process = nuodb_process
self._dbkey = conn._get_db_password(nuodb_process.db_name)
self._conn = conn
self._relative = relative
self._lastnow = None
self._stalls = {}
print(Monitor.header)

def execute_query(self):
session = nuodb_mgmt._get_authorized_session(self._process.address, self._dbkey, 'Query')

try:
msg = '<Request Service="Query" Type="MessageTrace"/>'
session.send(msg)
msg = session.recv()
now = datetime.now()
st = ElementTree.fromstring(msg)
mats = st.findall("MessageApplyTime")
laststalls = self._stalls
self._stalls = {}
for mat in mats:
total = int(mat.get("SampleTime"))
fromNodeId = mat.get("NodeId")
totals = mat.findall("Trace")
stalls = dict([(tr.get("Name"), (int(tr.get("NumStalls")),
int(tr.get("TotalStallTime")),
int(tr.get("MaxStallTime")))) for tr in totals])
self._stalls[fromNodeId] = (total, stalls)
ototal, ostalls = laststalls[fromNodeId] if fromNodeId in laststalls else (0, {})
self.process(now, fromNodeId, total, stalls, ototal, ostalls)
self._lastnow = now
finally:
if session:
session.close()
pass
now = datetime.now()
st = self._conn.send_query_request(self._process.start_id, "MessageTrace")
mats = st.findall("MessageApplyTime")
laststalls = self._stalls
self._stalls = {}
for mat in mats:
total = int(mat.get("SampleTime"))
fromNodeId = mat.get("NodeId")
totals = mat.findall("Trace")
stalls = dict([(tr.get("Name"), (int(tr.get("NumStalls")),
int(tr.get("TotalStallTime")),
int(tr.get("MaxStallTime")))) for tr in totals])
self._stalls[fromNodeId] = (total, stalls)
ototal, ostalls = laststalls[fromNodeId] if fromNodeId in laststalls else (0, {})
self.process(now, fromNodeId, total, stalls, ototal, ostalls)
self._lastnow = now

def process(self, now, fromNodeId, total, stalls, ototal, ostalls):
""" process one node listener (fromNodeId) at time now"""
Expand Down
44 changes: 16 additions & 28 deletions nuocd/synctrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class Monitor:
def __init__(self, nuodb_process, conn, relative, args):
self._process = nuodb_process
self._dbkey = conn._get_db_password(nuodb_process.db_name)
self._conn = conn
self._relative = relative
self._lastnow = None
self._stalls = (0, {})
Expand All @@ -34,35 +34,23 @@ def __init__(self, nuodb_process, conn, relative, args):
header = "#time,id,startId,host,pid,dbname,timedelta,totalSumStalls,name,numLocks,numUnlocks,numStalls,totalTimeStalls,maxStallTime"

def execute_query(self):
session = None
try:
session = nuodb_mgmt._get_authorized_session(self._process.address, self._dbkey, 'Query')
msg = '<Request Service="Query" Type="SyncTrace"/>'
session.send(msg)
msg = session.recv()
now = datetime.now()
st = ElementTree.fromstring(msg)
# if self._lastnow == None:
# print ElementTree.tostring(st)
pid = st.get("PID")
total = int(st.get("SampleTime"))
laststalls = self._stalls
now = datetime.now()
st = self._conn.send_query_request(self._process.start_id, "SyncTrace")
total = int(st.get("SampleTime"))
laststalls = self._stalls

def value(v):
return int(v) if v else 0
def value(v):
return int(v) if v else 0

stalls = dict([(tr.get("Name"), (value(tr.get("NumLocks")), value(tr.get("NumUnlocks")),
value(tr.get("NumStalls")), value(tr.get("TotalStallTime")),
value(tr.get("MaxStallTime"))
)
) for tr in st.findall("Trace")])
self._stalls = (total, stalls)
ototal, ostalls = laststalls
self.process(now, total, stalls, ototal, ostalls)
self._lastnow = now
finally:
if session:
session.close()
stalls = dict([(tr.get("Name"), (value(tr.get("NumLocks")), value(tr.get("NumUnlocks")),
value(tr.get("NumStalls")), value(tr.get("TotalStallTime")),
value(tr.get("MaxStallTime"))
)
) for tr in st.findall("Trace")])
self._stalls = (total, stalls)
ototal, ostalls = laststalls
self.process(now, total, stalls, ototal, ostalls)
self._lastnow = now

def process(self, now, total, stalls, ototal, ostalls):
""" process all sync points """
Expand Down

0 comments on commit 9767b03

Please sign in to comment.