luci-app-statistics: enhance tcpconns plugin
authorHannu Nyman <hannu.nyman@iki.fi>
Tue, 30 May 2023 16:27:47 +0000 (19:27 +0300)
committerHannu Nyman <hannu.nyman@iki.fi>
Wed, 31 May 2023 15:11:49 +0000 (18:11 +0300)
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>
applications/luci-app-statistics/htdocs/luci-static/resources/view/statistics/plugins/tcpconns.js
applications/luci-app-statistics/root/etc/config/luci_statistics
applications/luci-app-statistics/root/usr/share/luci/statistics/plugins/tcpconns.json

index 84471ebb872d595dd224f00c354bf40d4bc820c1..526b10f3c3cec89564939b1538cbd243dfd4e61c 100644 (file)
@@ -19,25 +19,30 @@ return baseclass.extend({
                o = s.option(form.DynamicList, 'LocalPorts', _('Monitor local ports'));
                o.optional = true;
                o.datatype = 'port';
-               o.default = '22 80';
-               o.depends({ enable: '1', ListeningPorts: '0' });
+               o.default = '22';
+               o.depends('enable', '1');
 
                o = s.option(form.DynamicList, 'RemotePorts', _('Monitor remote ports'));
                o.optional = true;
                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) {
                var lports = L.toArray(section.LocalPorts),
-                   rports = L.toArray(section.RemotePorts);
-
-               if (section.ListeningPorts == '1')
-                       return _('Monitoring local listen ports');
-               else
-                       return _('Monitoring %s and %s').format(
-                               N_(lports.length, 'one local port', '%d local ports').format(lports.length),
-                               N_(rports.length, 'one remote port', '%d remote ports').format(rports.length)
-                       );
+                   rports = L.toArray(section.RemotePorts),
+                   listen = section.ListeningPorts == '1',
+                   summary = section.AllPortsSummary == '1';
+
+               return _('Monitoring %s and %s, %s %s').format(
+                       N_(lports.length, 'one local', '%d local').format(lports.length),
+                       N_(rports.length, 'one remote port', '%d remote ports').format(rports.length),
+                       listen ? _('all local listening ports,') : '',
+                       summary ? _('summary of all ports') : _('no summary')
+               );
        }
 });
index bb9ca15e8e98edd7205d81601e2d7652329112ea..2008a7966a585266a29a080ae06577e47429574c 100644 (file)
@@ -203,7 +203,8 @@ config statistics 'collectd_splash_leases'
 config statistics 'collectd_tcpconns'
        option enable '0'
        option ListeningPorts '0'
-       option LocalPorts '22 80'
+       list LocalPorts '22'
+       option AllPortsSummary '0'
 
 config statistics 'collectd_thermal'
        option enable '0'
index f932994b43f7ec8b8dce0a80d538bdfe2b76fc6c..e26e8acffb2fd10860a166212cd466ce7896ddd1 100644 (file)
@@ -3,7 +3,7 @@
        "category": "network",
        "legend": [
                [],
-               ["ListeningPorts"],
+               ["ListeningPorts", "AllPortsSummary"],
                ["LocalPorts", "RemotePorts"]
        ]
 }