Add ntp connection status metric

Also add new ntp-server dimension

Change-Id: I0caf4ccc51693d0008fa509526a633280955cd6a
Closes-Bug: #1616434
This commit is contained in:
Michael James Hoppal 2016-08-31 10:13:10 -06:00
parent 63bd7586e7
commit 1a9d3a8616
2 changed files with 8 additions and 5 deletions

View File

@ -1189,7 +1189,8 @@ The NTP checks return the following metrics:
| Metric Name | Dimensions | Semantics |
| ----------- | ---------- | --------- |
| ntp.offset | hostname | Time offset in seconds |
| ntp.offset | hostname, ntp_server | Time offset in seconds |
| ntp.connection_status | hostname, ntp_server | Value of ntp server connection status (0=Healthy) |
## Postfix Checks
This section describes the Postfix checks that can be performed by the Agent. The Postfix checks gathers metrics on the Postfix. The Postfix checks requires a configuration file called postfix.yaml to be available in the agent conf.d configuration directory. The config file must contain the name, directory and queue that you are interested in monitoring.

View File

@ -1,4 +1,4 @@
# (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP
# (C) Copyright 2015,2016 Hewlett Packard Enterprise Development LP
import ntplib
@ -22,11 +22,12 @@ class NtpCheck(AgentCheck):
'version': int(instance.get('version', DEFAULT_NTP_VERSION)),
'timeout': float(instance.get('timeout', DEFAULT_TIMEOUT)),
}
dimensions['ntp_server'] = req_args['host']
try:
ntp_stats = ntplib.NTPClient().request(**req_args)
except ntplib.NTPException:
self.log.error("Could not connect to NTP Server")
raise
except ntplib.NTPException as err:
self.log.error("Could not connect to NTP Server: %s" % err)
self.gauge('ntp.connection_status', 1, dimensions=dimensions)
else:
ntp_offset = ntp_stats.offset
@ -34,3 +35,4 @@ class NtpCheck(AgentCheck):
# case the agent host's clock is messed up.
ntp_ts = ntp_stats.recv_time
self.gauge('ntp.offset', ntp_offset, timestamp=ntp_ts, dimensions=dimensions)
self.gauge('ntp.connection_status', 0, timestamp=ntp_ts, dimensions=dimensions)