diff --git a/aprsd/plugin.py b/aprsd/plugin.py index 10ed29a..686f633 100644 --- a/aprsd/plugin.py +++ b/aprsd/plugin.py @@ -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 diff --git a/aprsd/stats.py b/aprsd/stats.py index f498601..502075d 100644 --- a/aprsd/stats.py +++ b/aprsd/stats.py @@ -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 diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 8baf6e9..501ef8c 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -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)