Skip to content

Commit

Permalink
Use prometheus-specific names for ntpmon_info metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgear committed Jan 7, 2024
1 parent 9a08b3e commit 720f73a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
30 changes: 26 additions & 4 deletions src/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,18 @@ def __init__(self, args: argparse.Namespace) -> None:
]

infotypes: ClassVar[Dict[str, Tuple[str, str, str]]] = {
"ntpmon_rss": ("i", "_bytes", "The resident set size of the ntpmon process"),
"ntpmon_uptime": (None, "_seconds", "Time for which the ntpmon process has been running"),
"ntpmon_vms": ("i", "_bytes", "The virtual memory size of the ntpmon process"),
"resident_set_size": ("i", "_bytes", "The resident set size of the ntpmon process"),
"virtual_memory_size": ("i", "_bytes", "The virtual memory size of the ntpmon process"),
}

infotypes_labelled: ClassVar[Dict[str, Tuple[str, str, str]]] = {
"uptime": (None, "_seconds", "Time for which the ntpmon process has been running"),
}

info_rewrites: ClassVar[Dict[str, str]] = {
"ntpmon_rss": "resident_set_size",
"ntpmon_uptime": "uptime",
"ntpmon_vms": "virtual_memory_size",
}

peerstatslabels: ClassVar[List[str]] = [
Expand Down Expand Up @@ -184,10 +193,23 @@ def __init__(self, args: argparse.Namespace) -> None:
}

def send_info(self, metrics: dict, debug: bool = False) -> None:
# rewrite info metric names for prometheus
for i in self.info_rewrites:
if i in metrics:
metrics[self.info_rewrites[i]] = metrics[i]
del(metrics[i])
self.send_stats(
"ntpmon_info",
"ntpmon",
metrics,
self.infotypes,
[],
[],
debug=debug,
)
self.send_stats(
"ntpmon",
metrics,
self.infotypes_labelled,
[x for x in self.infolabels if x in metrics],
[metrics[x] for x in self.infolabels if x in metrics],
debug=debug,
Expand Down
6 changes: 3 additions & 3 deletions unit_tests/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def test_get_info() -> None:

assert i["implementation_name"] == "myntp"
assert i["implementation_version"] == "1.2.3-beta1"
assert i["ntpmon_rss"] > 1000
assert i["ntpmon_uptime"] > 0.000001
assert i["ntpmon_vms"] > i["ntpmon_rss"]
assert i["resident_set_size"] > 1000
assert i["uptime"] > 0.000001
assert i["virtual_memory_size"] > i["resident_set_size"]
assert [int(x) for x in i["python_version"].split(".")] >= [3, 8, 0]


Expand Down

0 comments on commit 720f73a

Please sign in to comment.