luci-app-statistics: Add initial support for chrony
authorHannu Nyman <hannu.nyman@iki.fi>
Tue, 22 Dec 2020 15:50:50 +0000 (17:50 +0200)
committerHannu Nyman <hannu.nyman@iki.fi>
Tue, 22 Dec 2020 15:54:18 +0000 (17:54 +0200)
Add initial support for chrony statistics.
At this point introduce time offset and stratum stats.

There is something strange with the host option.
Anything else than 'localhost' or '127.0.0.1' causes an error at
collectd start, even when /tmp/collectd/conf is directly edited

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
applications/luci-app-statistics/htdocs/luci-static/resources/statistics/rrdtool/definitions/chrony.js [new file with mode: 0644]
applications/luci-app-statistics/htdocs/luci-static/resources/view/statistics/plugins/chrony.js [new file with mode: 0644]
applications/luci-app-statistics/root/etc/config/luci_statistics
applications/luci-app-statistics/root/usr/share/luci/statistics/plugins/chrony.json [new file with mode: 0644]

diff --git a/applications/luci-app-statistics/htdocs/luci-static/resources/statistics/rrdtool/definitions/chrony.js b/applications/luci-app-statistics/htdocs/luci-static/resources/statistics/rrdtool/definitions/chrony.js
new file mode 100644 (file)
index 0000000..4730adf
--- /dev/null
@@ -0,0 +1,61 @@
+/* Licensed to the public under the Apache License 2.0. */
+
+'use strict';
+'require baseclass';
+'require uci';
+
+return baseclass.extend({
+       title: _('Chrony'),
+
+       rrdargs: function(graph, host, plugin, plugin_instance, dtype) {
+               var offset = {
+                       title: "%H: Chrony - time offset",
+                       vlabel: "Time offset (ms)",
+                       number_format: "%9.3lf ms",
+                       data: {
+                               types: [ "time_offset" ],
+                               options: {
+                                       time_offset_chrony: {
+                                               noarea: true,
+                                               overlay: true,
+                                               color: "ff0000",
+                                               title: "%di",
+                                               transform_rpn: "1000,*"
+                                       },
+                                       time_offset: {
+                                               noarea: true,
+                                               overlay: true,
+                                               title: "%di",
+                                               transform_rpn: "1000,*"
+                                       }
+                               }
+                       }
+               };
+
+               var stratum = {
+                       title: "%H: Chrony - clock stratum",
+                       vlabel: "Clock stratum",
+                       number_format: "%3.1lf%S",
+                       data: {
+                               types: [ "clock_stratum" ],
+                               options: {
+                                       clock_stratum_chrony: {
+                                               noarea: true,
+                                               overlay: true,
+                                               color: "ff0000",
+                                               title: "%di"
+                                       },
+                                       clock_stratum: {
+                                               noarea: true,
+                                               overlay: true,
+                                               title: "%di"
+                                       }
+                               }
+                       }
+               };
+
+               return [ offset, stratum ];
+
+       }
+});
+
diff --git a/applications/luci-app-statistics/htdocs/luci-static/resources/view/statistics/plugins/chrony.js b/applications/luci-app-statistics/htdocs/luci-static/resources/view/statistics/plugins/chrony.js
new file mode 100644 (file)
index 0000000..7dc98f3
--- /dev/null
@@ -0,0 +1,34 @@
+'use strict';
+'require baseclass';
+'require form';
+
+return baseclass.extend({
+       title: _('Chrony Plugin Configuration'),
+       description: _('The chrony plugin will monitor chrony NTP server statistics'),
+
+       addFormOptions: function(s) {
+               var o;
+
+               o = s.option(form.Flag, 'enable', _('Enable this plugin'));
+
+               o = s.option(form.Value, 'Host', _('Host running chrony'),
+                       _('Possibly bug in collectd. Only 127.0.0.1 and localhost work'));
+               o.default = '127.0.0.1';
+               o.datatype = 'or(hostname,ipaddr("nomask"))';
+               o.depends('enable', '1');
+
+               o = s.option(form.Value, 'Port', _('Port for chronyd'));
+               o.default = '323';
+               o.datatype = 'port';
+               o.depends('enable', '1');
+
+               o = s.option(form.Value, 'Timeout', _('Timeout for polling chrony'), _('Seconds'));
+               o.default = '2';
+               o.datatype = 'range(0, 255)';
+               o.depends('enable', '1');
+       },
+
+       configSummary: function(section) {
+               return _('Chrony monitoring enabled');
+       }
+});
index 3806ea71d5d09e241a847e02df596e0b7b4dba3f..3d4e80780d72121f0c5a9733decdccc00105947c 100644 (file)
@@ -59,6 +59,12 @@ config statistics 'collectd_apcups'
        option Host 'localhost'
        option Port '3551'
 
+config statistics 'collectd_chrony'
+       option enable '0'
+       option Host '127.0.0.1'
+       option Port '323'
+       option Timeout '2'
+
 config statistics 'collectd_conntrack'
        option enable '0'
 
diff --git a/applications/luci-app-statistics/root/usr/share/luci/statistics/plugins/chrony.json b/applications/luci-app-statistics/root/usr/share/luci/statistics/plugins/chrony.json
new file mode 100644 (file)
index 0000000..1eea36a
--- /dev/null
@@ -0,0 +1,9 @@
+{
+       "title": "Chrony",
+       "category": "network",
+       "legend": [
+               ["Host", "Port", "Timeout"],
+               [],
+               []
+       ]
+}