mirror of
https://github.com/craigerl/aprsd.git
synced 2024-11-18 06:11:49 -05:00
Updated stats output for KeepAlive thread
Also added the aprsd uptime to the VersionPlugin
This commit is contained in:
parent
3f21934c0f
commit
7b019d24f0
@ -1,7 +1,7 @@
|
||||
import logging
|
||||
|
||||
import aprsd
|
||||
from aprsd import plugin, trace
|
||||
from aprsd import plugin, stats, trace
|
||||
|
||||
LOG = logging.getLogger("APRSD")
|
||||
|
||||
@ -20,4 +20,9 @@ class VersionPlugin(plugin.APRSDPluginBase):
|
||||
@trace.trace
|
||||
def command(self, fromcall, message, ack):
|
||||
LOG.info("Version COMMAND")
|
||||
return "APRSD version '{}'".format(aprsd.__version__)
|
||||
stats_obj = stats.APRSDStats()
|
||||
s = stats_obj.stats()
|
||||
return "APRSD ver:{} uptime:{}".format(
|
||||
aprsd.__version__,
|
||||
s["aprsd"]["uptime"],
|
||||
)
|
||||
|
@ -49,7 +49,7 @@ class APRSDStats:
|
||||
@property
|
||||
def uptime(self):
|
||||
with self.lock:
|
||||
return str(datetime.datetime.now() - self.start_time)
|
||||
return datetime.datetime.now() - self.start_time
|
||||
|
||||
@property
|
||||
def memory(self):
|
||||
@ -183,7 +183,7 @@ class APRSDStats:
|
||||
stats = {
|
||||
"aprsd": {
|
||||
"version": aprsd.__version__,
|
||||
"uptime": self.uptime,
|
||||
"uptime": utils.strfdelta(self.uptime),
|
||||
"memory_current": self.memory,
|
||||
"memory_current_str": utils.human_size(self.memory),
|
||||
"memory_peak": self.memory_peak,
|
||||
|
@ -1,6 +1,5 @@
|
||||
import abc
|
||||
import datetime
|
||||
import gc
|
||||
import logging
|
||||
import queue
|
||||
import threading
|
||||
@ -75,25 +74,24 @@ class KeepAliveThread(APRSDThread):
|
||||
|
||||
def loop(self):
|
||||
if self.cntr % 6 == 0:
|
||||
nuked = gc.collect()
|
||||
tracker = messaging.MsgTrack()
|
||||
stats_obj = stats.APRSDStats()
|
||||
now = datetime.datetime.now()
|
||||
last_email = stats_obj.email_thread_time
|
||||
if last_email:
|
||||
email_thread_time = str(now - last_email)
|
||||
email_thread_time = utils.strfdelta(now - last_email)
|
||||
else:
|
||||
email_thread_time = "N/A"
|
||||
|
||||
last_msg_time = str(now - stats_obj.aprsis_keepalive)
|
||||
last_msg_time = utils.strfdelta(now - stats_obj.aprsis_keepalive)
|
||||
|
||||
current, peak = tracemalloc.get_traced_memory()
|
||||
stats_obj.set_memory(current)
|
||||
stats_obj.set_memory_peak(peak)
|
||||
LOG.debug(
|
||||
"Uptime ({}) Tracker({}) "
|
||||
"Msgs: TX:{} RX:{} Last: {} - EmailThread: {} - RAM: Current:{} Peak:{} Nuked: {}".format(
|
||||
stats_obj.uptime,
|
||||
keepalive = (
|
||||
"Uptime {} Tracker {} "
|
||||
"Msgs TX:{} RX:{} Last:{} Email:{} RAM Current:{} Peak:{}".format(
|
||||
utils.strfdelta(stats_obj.uptime),
|
||||
len(tracker),
|
||||
stats_obj.msgs_tx,
|
||||
stats_obj.msgs_rx,
|
||||
@ -101,9 +99,10 @@ class KeepAliveThread(APRSDThread):
|
||||
email_thread_time,
|
||||
utils.human_size(current),
|
||||
utils.human_size(peak),
|
||||
nuked,
|
||||
),
|
||||
)
|
||||
)
|
||||
LOG.debug(keepalive)
|
||||
LOG.debug(len(keepalive))
|
||||
self.cntr += 1
|
||||
time.sleep(10)
|
||||
return True
|
||||
|
@ -368,3 +368,10 @@ def human_size(bytes, units=None):
|
||||
if not units:
|
||||
units = [" bytes", "KB", "MB", "GB", "TB", "PB", "EB"]
|
||||
return str(bytes) + units[0] if bytes < 1024 else human_size(bytes >> 10, units[1:])
|
||||
|
||||
|
||||
def strfdelta(tdelta, fmt="{hours}:{minutes}:{seconds}"):
|
||||
d = {"days": tdelta.days}
|
||||
d["hours"], rem = divmod(tdelta.seconds, 3600)
|
||||
d["minutes"], d["seconds"] = divmod(rem, 60)
|
||||
return fmt.format(**d)
|
||||
|
Loading…
Reference in New Issue
Block a user