Added message counts for each plugin.

This patch adds a message counter for each plugin.  When the regex for
a plugin passes and the message is pass into the plugin for processing,
that message is tracked.  This message count is reported by the stats
tracking object now for the web admin ui.
This commit is contained in:
Hemna 2021-06-17 16:27:35 -04:00
parent d8950f0995
commit 3ae5717452
3 changed files with 24 additions and 2 deletions

View File

@ -43,6 +43,7 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
def __init__(self, config):
"""The aprsd config object is stored."""
self.config = config
self.message_counter = 0
@property
def command_name(self):
@ -59,9 +60,14 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
"""Version"""
raise NotImplementedError
@property
def message_count(self):
return self.message_counter
@hookimpl
def run(self, fromcall, message, ack):
if re.search(self.command_regex, message):
self.message_counter += 1
return self.command(fromcall, message, ack)
@abc.abstractmethod

View File

@ -3,7 +3,7 @@ import logging
import threading
import aprsd
from aprsd import utils
from aprsd import plugin, utils
LOG = logging.getLogger("APRSD")
@ -181,6 +181,20 @@ class APRSDStats:
else:
last_aprsis_keepalive = "never"
pm = plugin.PluginManager()
plugins = pm.get_plugins()
plugin_stats = {}
def full_name_with_qualname(obj):
return "{}.{}".format(
obj.__class__.__module__,
obj.__class__.__qualname__,
)
for p in plugins:
LOG.debug(p)
plugin_stats[full_name_with_qualname(p)] = p.message_count
stats = {
"aprsd": {
"version": aprsd.__version__,
@ -209,6 +223,7 @@ class APRSDStats:
"recieved": self._email_rx,
"thread_last_update": last_update,
},
"plugins": plugin_stats,
}
return stats

View File

@ -143,7 +143,8 @@ class TestPlugin(unittest.TestCase):
actual = ping.run(fromcall, message, ack)
self.assertEqual(expected, actual)
def test_version(self):
@mock.patch("aprsd.plugin.PluginManager.get_plugins")
def test_version(self, mock_get_plugins):
expected = "APRSD ver:{} uptime:0:0:0".format(aprsd.__version__)
version = version_plugin.VersionPlugin(self.config)