luci-app-statistics: enhance tcpconns plugin

Modernize tcpconns plugin to match the features in collectd:

* Support summary of all ports
* 'All listening ports' can be concurrent to specified ports,
  not just alternative

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
This commit is contained in:
Hannu Nyman 2023-05-30 19:27:47 +03:00
parent 9b12a48c3f
commit c9c395920e
3 changed files with 19 additions and 13 deletions

View file

@ -19,25 +19,30 @@ return baseclass.extend({
o = s.option(form.DynamicList, 'LocalPorts', _('Monitor local ports')); o = s.option(form.DynamicList, 'LocalPorts', _('Monitor local ports'));
o.optional = true; o.optional = true;
o.datatype = 'port'; o.datatype = 'port';
o.default = '22 80'; o.default = '22';
o.depends({ enable: '1', ListeningPorts: '0' }); o.depends('enable', '1');
o = s.option(form.DynamicList, 'RemotePorts', _('Monitor remote ports')); o = s.option(form.DynamicList, 'RemotePorts', _('Monitor remote ports'));
o.optional = true; o.optional = true;
o.datatype = 'port'; o.datatype = 'port';
o.depends({ enable: '1', ListeningPorts: '0' }); o.depends('enable', '1');
o = s.option(form.Flag, 'AllPortsSummary', _('Summary of all ports'));
o.rmempty = false;
o.depends('enable', '1');
}, },
configSummary: function(section) { configSummary: function(section) {
var lports = L.toArray(section.LocalPorts), var lports = L.toArray(section.LocalPorts),
rports = L.toArray(section.RemotePorts); rports = L.toArray(section.RemotePorts),
listen = section.ListeningPorts == '1',
summary = section.AllPortsSummary == '1';
if (section.ListeningPorts == '1') return _('Monitoring %s and %s, %s %s').format(
return _('Monitoring local listen ports'); N_(lports.length, 'one local', '%d local').format(lports.length),
else N_(rports.length, 'one remote port', '%d remote ports').format(rports.length),
return _('Monitoring %s and %s').format( listen ? _('all local listening ports,') : '',
N_(lports.length, 'one local port', '%d local ports').format(lports.length), summary ? _('summary of all ports') : _('no summary')
N_(rports.length, 'one remote port', '%d remote ports').format(rports.length) );
);
} }
}); });

View file

@ -203,7 +203,8 @@ config statistics 'collectd_splash_leases'
config statistics 'collectd_tcpconns' config statistics 'collectd_tcpconns'
option enable '0' option enable '0'
option ListeningPorts '0' option ListeningPorts '0'
option LocalPorts '22 80' list LocalPorts '22'
option AllPortsSummary '0'
config statistics 'collectd_thermal' config statistics 'collectd_thermal'
option enable '0' option enable '0'

View file

@ -3,7 +3,7 @@
"category": "network", "category": "network",
"legend": [ "legend": [
[], [],
["ListeningPorts"], ["ListeningPorts", "AllPortsSummary"],
["LocalPorts", "RemotePorts"] ["LocalPorts", "RemotePorts"]
] ]
} }