From 1a9d3a861652eeba431b15e20b94c02b4d781340 Mon Sep 17 00:00:00 2001 From: Michael James Hoppal Date: Wed, 31 Aug 2016 10:13:10 -0600 Subject: [PATCH] Add ntp connection status metric Also add new ntp-server dimension Change-Id: I0caf4ccc51693d0008fa509526a633280955cd6a Closes-Bug: #1616434 --- docs/Plugins.md | 3 ++- monasca_agent/collector/checks_d/ntp.py | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/Plugins.md b/docs/Plugins.md index 1ca107ac..45fb6e23 100644 --- a/docs/Plugins.md +++ b/docs/Plugins.md @@ -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. diff --git a/monasca_agent/collector/checks_d/ntp.py b/monasca_agent/collector/checks_d/ntp.py index d2d5453f..7c9d45da 100644 --- a/monasca_agent/collector/checks_d/ntp.py +++ b/monasca_agent/collector/checks_d/ntp.py @@ -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)