Skip to content

Commit

Permalink
Add ntpmon_version tag to prometheus and telegraf metrics
Browse files Browse the repository at this point in the history
If someone wants this for collectd and can explain how to do it, please get in touch.
  • Loading branch information
paulgear committed Jan 2, 2024
1 parent f3d9c3c commit 7d68986
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import metrics
import outputs
import version

from classifier import MetricClassifier

Expand Down Expand Up @@ -90,6 +91,7 @@ def alert(self, checkobjs: dict, output: outputs.Output, debug: bool = False) ->
self.mc.classify_metrics(self.metrics)
(m, rc) = self.mc.worst_metric(self.checks)
self.metrics["result"] = self.return_code()
self.metrics["ntpmon_version"] = version.get_version()
output.send_summary_stats(self.metrics, debug)
output.send_peer_counts(self.metrics, debug)

Expand Down
12 changes: 10 additions & 2 deletions src/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Output:

summarytypes: ClassVar[Dict[str, str]] = {
"frequency": "frequency/frequency_offset",
"ntpmon_version": None,
"offset": "offset/time_offset",
"reach": "reachability/percent",
"rootdelay": "rootdelay/root_delay",
Expand Down Expand Up @@ -96,7 +97,7 @@ def send_stats(self, metrics: dict, types: dict, debug: bool = False, hostname:
if hostname is None:
hostname = self.args.hostname
for metric in sorted(types.keys()):
if metric in metrics:
if metric in metrics and types[metric] is not None:
print(self.formatstr % (hostname, types[metric], self.args.interval, metrics[metric]))

def send_summary_stats(self, metrics: dict, debug: bool = False) -> None:
Expand Down Expand Up @@ -186,7 +187,14 @@ def send_peer_counts(self, metrics: dict, debug: bool = False) -> None:
)

def send_summary_stats(self, metrics: dict, debug: bool = False) -> None:
self.send_stats("ntpmon", metrics, self.summarystatstypes, debug=debug)
self.send_stats(
"ntpmon",
metrics,
self.summarystatstypes,
labelnames=["ntpmon_version"],
labels=[metrics["ntpmon_version"]],
debug=debug,
)

def send_stats(
self,
Expand Down

0 comments on commit 7d68986

Please sign in to comment.