summaryrefslogtreecommitdiffstats
path: root/python.d
diff options
context:
space:
mode:
authorDominik Schloesser <dsc@dosc.net>2017-08-27 18:27:52 +0200
committerDominik Schloesser <dsc@dosc.net>2017-08-27 18:27:52 +0200
commit244918fa4659082141ada17f799f708fad71c625 (patch)
treebc69c0851735476f77f5f8d01abe415222a23140 /python.d
parent8c8c7cd97e919365f3b2abe7771135a29414a2ae (diff)
Statistics for precision of local chrony
Diffstat (limited to 'python.d')
-rw-r--r--python.d/chrony.chart.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/python.d/chrony.chart.py b/python.d/chrony.chart.py
new file mode 100644
index 0000000000..a5afedda28
--- /dev/null
+++ b/python.d/chrony.chart.py
@@ -0,0 +1,94 @@
+# -*- coding: utf-8 -*-
+# Description: chrony netdata python.d module
+# Author: Dominik Schloesser (domschl)
+
+from base import ExecutableService
+
+# default module values (can be overridden per job in `config`)
+# update_every = 10
+priority = 60000
+retries = 10
+
+# charts order (can be overridden if you want less charts, or different order)
+ORDER = ['timediff', 'lastoffset', 'rmsoffset', 'rootdelay',
+ 'rootdispersion', 'skew', 'frequency', 'residualfreq']
+
+CHARTS = {
+ # id: {
+ # 'options': [name, title, units, family, context, charttype],
+ # 'lines': [
+ # [unique_dimension_name, name, algorithm, multiplier, divisor]
+ # ]}
+ 'timediff': {
+ 'options': [None, "Difference system time to NTP", "us", 'chrony', 'chrony.timediff', 'line'],
+ 'lines': [
+ ['timediff', None, 'absolute', 1, 1000]
+ ]},
+ 'lastoffset': {
+ 'options': [None, "Last offset", "us", 'chrony', 'chrony.lastoffset', 'line'],
+ 'lines': [
+ ['lastoffset', None, 'absolute', 1, 1000]
+ ]},
+ 'rmsoffset': {
+ 'options': [None, "RMS offset", "us", 'chrony', 'chrony.rmsoffset', 'line'],
+ 'lines': [
+ ['rmsoffset', None, 'absolute', 1, 1000]
+ ]},
+ 'rootdelay': {
+ 'options': [None, "Root delay", "us", 'chrony', 'chrony.rootdelay', 'line'],
+ 'lines': [
+ ['rootdelay', None, 'absolute', 1, 1000]
+ ]},
+ 'rootdispersion': {
+ 'options': [None, "Root dispersion", "us", 'chrony', 'chrony.rootdispersion', 'line'],
+ 'lines': [
+ ['rootdispersion', None, 'absolute', 1, 1000]
+ ]},
+ 'skew': {
+ 'options': [None, "Skew, error bound on frequency", "ppm", 'chrony', 'chrony.skew', 'line'],
+ 'lines': [
+ ['skew', None, 'absolute', 1, 1000]
+ ]},
+ 'frequency': {
+ 'options': [None, "Frequency", "ppm", 'chrony', 'chrony.frequency', 'line'],
+ 'lines': [
+ ['frequency', None, 'absolute', 1, 1000]
+ ]},
+ 'residualfreq': {
+ 'options': [None, "Residual frequency", "ppm", 'chrony', 'chrony.residualfreq', 'line'],
+ 'lines': [
+ ['residualfreq', None, 'absolute', 1, 1000]
+ ]}
+}
+
+
+class Service(ExecutableService):
+ def __init__(self, configuration=None, name=None):
+ ExecutableService.__init__(
+ self, configuration=configuration, name=name)
+ self.command = "chronyc -n tracking"
+ self.order = ORDER
+ self.definitions = CHARTS
+ self.error("Chrony netdata started")
+
+ def _get_data(self):
+ """
+ Format data received from shell command
+ :return: dict
+ """
+ try:
+ # self.error("Chrony:" + self._get_raw_data())
+ chrony_dict = {ln.split(':', 1)[0].strip(): ln.split(':', 1)[1].strip().split(' ')[0]
+ for ln in self._get_raw_data()[1:]}
+ return {'timediff': int(float(chrony_dict['System time']) * 1e9),
+ 'lastoffset': int(float(chrony_dict['Last offset']) * 1e9),
+ 'rmsoffset': int(float(chrony_dict['RMS offset']) * 1e9),
+ 'rootdelay': int(float(chrony_dict['Root delay']) * 1e9),
+ 'rootdispersion': int(float(chrony_dict['Root dispersion']) * 1e9),
+ 'skew': int(float(chrony_dict['Skew']) * 1e3),
+ 'frequency': int(float(chrony_dict['Frequency']) * 1e3),
+ 'residualfreq': int(float(chrony_dict['Residual freq']) * 1e3)
+ }
+ except (ValueError, AttributeError):
+ self.error("Chrony parser exception")
+ return None