Added tracking plugin processing

This patch adds plugin rx/tx processing of packets.
This tracks how many messages a plugin processes (recieves) and
how many packets result in a plugin sending a message out.

This patch also adds a new plugins tab on the admin page.
This commit is contained in:
Hemna 2021-08-20 16:25:54 -04:00
parent 86777d838c
commit 8e627c98b3
5 changed files with 49 additions and 3 deletions

View File

@ -61,6 +61,10 @@ class APRSDFlask(flask_classful.FlaskView):
watch_count = 0
watch_age = 0
pm = plugin.PluginManager()
plugins = pm.get_plugins()
plugin_count = len(plugins)
return flask.render_template(
"index.html",
initial_stats=stats,
@ -69,6 +73,7 @@ class APRSDFlask(flask_classful.FlaskView):
config_json=json.dumps(self.config),
watch_count=watch_count,
watch_age=watch_age,
plugin_count=plugin_count,
)
@auth.login_required

View File

@ -48,7 +48,8 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
"""The base class for all APRSD Plugins."""
config = None
message_counter = 0
rx_count = 0
tx_count = 0
version = "1.0"
# Holds the list of APRSDThreads that the plugin creates
@ -103,6 +104,12 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
"""Gives the plugin writer the ability start a background thread."""
return []
def rx_inc(self):
self.rx_count += 1
def tx_inc(self):
self.tx_count += 1
def stop_threads(self):
"""Stop any threads this plugin might have created."""
for thread in self.threads:
@ -137,7 +144,10 @@ class APRSDWatchListPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
result = messaging.NULL_MESSAGE
if wl.callsign_in_watchlist(packet["from"]):
# packet is from a callsign in the watch list
self.rx_inc()
result = self.process()
if result:
self.tx_inc()
wl.update_seen(packet)
return result
@ -185,8 +195,10 @@ class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
and message
):
if re.search(self.command_regex, message):
self.message_counter += 1
self.rx_inc()
result = self.process(packet)
if result:
self.tx_inc()
<<<<<<< HEAD
To reply with a message over the air, return a string

View File

@ -193,7 +193,10 @@ class APRSDStats:
)
for p in plugins:
plugin_stats[full_name_with_qualname(p)] = p.message_count
plugin_stats[full_name_with_qualname(p)] = {
"rx": p.rx_count,
"tx": p.tx_count,
}
wl = packets.WatchList()

View File

@ -58,6 +58,23 @@ function update_watchlist_from_packet(callsign, val) {
//console.log(watchlist)
}
function update_plugins( data ) {
var plugindiv = $("#pluginDiv");
var html_str = '<table class="ui celled striped table"><thead><tr><th>Plugin Name</th><th>Processed Packets</th><th>Sent Packets</th></tr></thead><tbody>'
plugindiv.html('')
var plugins = data["stats"]["plugins"];
var keys = Object.keys(plugins);
keys.sort();
for (var i=0; i<keys.length; i++) { // now lets iterate in sort order
var key = keys[i];
var val = plugins[key];
html_str += '<tr><td class="collapsing">' + key + '</td><td>' + val["rx"] + '</td><td>' + val["tx"] + '</td></tr>';
}
html_str += "</tbody></table>";
plugindiv.append(html_str);
}
function update_packets( data ) {
var packetsdiv = $("#packetsDiv");
//nuke the contents first, then add to it.
@ -120,6 +137,7 @@ function start_update() {
success: function(data) {
update_stats(data);
update_watchlist(data);
update_plugins(data);
},
complete: function() {
setTimeout(statsworker, 10000);

View File

@ -71,6 +71,7 @@
<div class="active item" data-tab="charts-tab">Charts</div>
<div class="item" data-tab="msgs-tab">Messages</div>
<div class="item" data-tab="watch-tab">Watch List</div>
<div class="item" data-tab="plugin-tab">Plugins</div>
<div class="item" data-tab="config-tab">Config</div>
<div class="item" data-tab="raw-tab">Raw JSON</div>
</div>
@ -129,6 +130,13 @@
<div id="watchDiv" class="ui mini text">Loading</div>
</div>
<div class="ui bottom attached tab segment" data-tab="plugin-tab">
<h3 class="ui dividing header">
Plugins Loaded (<span id="plugin_count">{{ plugin_count }}</span>)
</h3>
<div id="pluginDiv" class="ui mini text">Loading</div>
</div>
<div class="ui bottom attached tab segment" data-tab="config-tab">
<h3 class="ui dividing header">Config</h3>
<pre id="configjson" class="language-json">{{ config_json|safe }}</pre>