diff options
author | Sven Mäder <maeder@phys.ethz.ch> | 2018-02-20 13:33:47 +0100 |
---|---|---|
committer | Sven Mäder <maeder@phys.ethz.ch> | 2018-02-20 13:40:35 +0100 |
commit | 4c5587b8d56c90077826ec8e10d6576d2cc65446 (patch) | |
tree | 80fab34241973b8b19deae2d0fa9a7b09c462ed3 | |
parent | cfbd413031ea9542600ed9b3fbff65e9307ccf6e (diff) |
Modify according PR comments
Always find new peers when peers dict() is empty.
Do not check `peer_rescan` config, assume that the user reads the
description.
Module will push charts to netdata (create) only if charts have any
data after update.
-rw-r--r-- | conf.d/python.d/ntpd.conf | 3 | ||||
-rw-r--r-- | python.d/ntpd.chart.py | 28 |
2 files changed, 11 insertions, 20 deletions
diff --git a/conf.d/python.d/ntpd.conf b/conf.d/python.d/ntpd.conf index afe81cdee0..fcb02f9eb8 100644 --- a/conf.d/python.d/ntpd.conf +++ b/conf.d/python.d/ntpd.conf @@ -62,7 +62,8 @@ # peer_filter: '127\..*' # regex to exclude peers # # by default local peers are hidden # # use `''` to show all peers. -# peer_rescan: 60 # interval to check for new/changed peers +# peer_rescan: 60 # interval (>0) to check for new/changed peers +# # use `1` to check on every update # # ---------------------------------------------------------------------- # AUTO-DETECTION JOBS diff --git a/python.d/ntpd.chart.py b/python.d/ntpd.chart.py index ead98c85c0..a2c5ad75d9 100644 --- a/python.d/ntpd.chart.py +++ b/python.d/ntpd.chart.py @@ -12,7 +12,6 @@ from bases.FrameworkServices.SocketService import SocketService update_every = 1 priority = 60000 retries = 60 -peer_rescan = 60 # NTP Control Message Protocol constants MODE = 6 @@ -226,6 +225,7 @@ class Service(SocketService): SocketService.__init__(self, configuration=configuration, name=name) self.order = list(ORDER) self.definitions = dict(CHARTS) + self.definitions.update(PEER_CHARTS) self.port = 'ntp' self.dgram_socket = True @@ -234,6 +234,7 @@ class Service(SocketService): self.request = str() self.retries = 0 self.show_peers = self.configuration.get('show_peers', False) + self.peer_rescan = self.configuration.get('peer_rescan', 60) def check(self): """ @@ -242,23 +243,12 @@ class Service(SocketService): """ self._parse_config() - if self.show_peers: - self.definitions.update(PEER_CHARTS) - - peer_filter = self.configuration.get('peer_filter', r'127\..*') - try: - self.peer_filter = re.compile(r'^((0\.0\.0\.0)|({0}))$'.format(peer_filter)) - except re.error as error: - self.error('Compile pattern error (peer_filter) : {0}'.format(error)) - return None - - try: - self.peer_rescan = int(self.configuration.get('peer_rescan', peer_rescan)) - if self.peer_rescan <= 0: - raise ValueError('int > 0 expected: {0}'.format(self.peer_rescan)) - except ValueError as error: - self.error('Value error (peer_rescan) : {0}'.format(error)) - return None + peer_filter = self.configuration.get('peer_filter', r'127\..*') + try: + self.peer_filter = re.compile(r'^((0\.0\.0\.0)|({0}))$'.format(peer_filter)) + except re.error as error: + self.error('Compile pattern error (peer_filter) : {0}'.format(error)) + return None self.request = self.system.request raw_systemvars = self._get_raw_data() @@ -285,7 +275,7 @@ class Service(SocketService): if not self.show_peers: return data - if self.runs_counter == 1 or self.runs_counter % self.peer_rescan or self.retries > 8: + if not self.peers or self.runs_counter % self.peer_rescan == 0 or self.retries > 8: self.find_new_peers() for peer in self.peers.values(): |