1
0
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:
Hemna 2021-04-02 18:54:00 -04:00
parent 3f21934c0f
commit 7b019d24f0
4 changed files with 25 additions and 14 deletions

View File

@ -1,7 +1,7 @@
import logging import logging
import aprsd import aprsd
from aprsd import plugin, trace from aprsd import plugin, stats, trace
LOG = logging.getLogger("APRSD") LOG = logging.getLogger("APRSD")
@ -20,4 +20,9 @@ class VersionPlugin(plugin.APRSDPluginBase):
@trace.trace @trace.trace
def command(self, fromcall, message, ack): def command(self, fromcall, message, ack):
LOG.info("Version COMMAND") 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"],
)

View File

@ -49,7 +49,7 @@ class APRSDStats:
@property @property
def uptime(self): def uptime(self):
with self.lock: with self.lock:
return str(datetime.datetime.now() - self.start_time) return datetime.datetime.now() - self.start_time
@property @property
def memory(self): def memory(self):
@ -183,7 +183,7 @@ class APRSDStats:
stats = { stats = {
"aprsd": { "aprsd": {
"version": aprsd.__version__, "version": aprsd.__version__,
"uptime": self.uptime, "uptime": utils.strfdelta(self.uptime),
"memory_current": self.memory, "memory_current": self.memory,
"memory_current_str": utils.human_size(self.memory), "memory_current_str": utils.human_size(self.memory),
"memory_peak": self.memory_peak, "memory_peak": self.memory_peak,

View File

@ -1,6 +1,5 @@
import abc import abc
import datetime import datetime
import gc
import logging import logging
import queue import queue
import threading import threading
@ -75,25 +74,24 @@ class KeepAliveThread(APRSDThread):
def loop(self): def loop(self):
if self.cntr % 6 == 0: if self.cntr % 6 == 0:
nuked = gc.collect()
tracker = messaging.MsgTrack() tracker = messaging.MsgTrack()
stats_obj = stats.APRSDStats() stats_obj = stats.APRSDStats()
now = datetime.datetime.now() now = datetime.datetime.now()
last_email = stats_obj.email_thread_time last_email = stats_obj.email_thread_time
if last_email: if last_email:
email_thread_time = str(now - last_email) email_thread_time = utils.strfdelta(now - last_email)
else: else:
email_thread_time = "N/A" 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() current, peak = tracemalloc.get_traced_memory()
stats_obj.set_memory(current) stats_obj.set_memory(current)
stats_obj.set_memory_peak(peak) stats_obj.set_memory_peak(peak)
LOG.debug( keepalive = (
"Uptime ({}) Tracker({}) " "Uptime {} Tracker {} "
"Msgs: TX:{} RX:{} Last: {} - EmailThread: {} - RAM: Current:{} Peak:{} Nuked: {}".format( "Msgs TX:{} RX:{} Last:{} Email:{} RAM Current:{} Peak:{}".format(
stats_obj.uptime, utils.strfdelta(stats_obj.uptime),
len(tracker), len(tracker),
stats_obj.msgs_tx, stats_obj.msgs_tx,
stats_obj.msgs_rx, stats_obj.msgs_rx,
@ -101,9 +99,10 @@ class KeepAliveThread(APRSDThread):
email_thread_time, email_thread_time,
utils.human_size(current), utils.human_size(current),
utils.human_size(peak), utils.human_size(peak),
nuked,
),
) )
)
LOG.debug(keepalive)
LOG.debug(len(keepalive))
self.cntr += 1 self.cntr += 1
time.sleep(10) time.sleep(10)
return True return True

View File

@ -368,3 +368,10 @@ def human_size(bytes, units=None):
if not units: if not units:
units = [" bytes", "KB", "MB", "GB", "TB", "PB", "EB"] units = [" bytes", "KB", "MB", "GB", "TB", "PB", "EB"]
return str(bytes) + units[0] if bytes < 1024 else human_size(bytes >> 10, units[1:]) 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)