1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# -*- 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
def _get_data(self):
"""
Format data received from shell command
:return: dict
"""
try:
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 data parser exception")
return None
|