From 4292355310f651a20d6700257831c0a23f7abcc6 Mon Sep 17 00:00:00 2001 From: link2xt Date: Mon, 8 Jul 2024 13:40:11 +0000 Subject: [PATCH] Add nonci_accounts metric Calculating this with PromQL is not easy due to interpolation. Also add HELP and TYPE metadata for each metric. --- CHANGELOG.md | 3 +++ chatmaild/src/chatmaild/metrics.py | 13 +++++++++---- chatmaild/src/chatmaild/tests/test_metrics.py | 5 +++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c36515e..c0da524f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,9 @@ - DKIM-sign Content-Type and oversign all signed headers ([#296](https://github.com/deltachat/chatmail/pull/296)) +- Add nonci_accounts metric + ([#347](https://github.com/deltachat/chatmail/pull/347)) + ## 1.3.0 - 2024-06-06 - don't check necessary DNS records on cmdeploy init anymore diff --git a/chatmaild/src/chatmaild/metrics.py b/chatmaild/src/chatmaild/metrics.py index af7c1ab6..0b98ccae 100644 --- a/chatmaild/src/chatmaild/metrics.py +++ b/chatmaild/src/chatmaild/metrics.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 import sys -import time from pathlib import Path @@ -16,9 +15,15 @@ def main(vmail_dir=None): if path.name[:3] in ("ci-", "ac_"): ci_accounts += 1 - timestamp = int(time.time() * 1000) - print(f"accounts {accounts} {timestamp}") - print(f"ci_accounts {ci_accounts} {timestamp}") + print("# HELP total number of accounts") + print("# TYPE accounts gauge") + print(f"accounts {accounts}") + print("# HELP number of CI accounts") + print("# TYPE ci_accounts gauge") + print(f"ci_accounts {ci_accounts}") + print("# HELP number of non-CI accounts") + print("# TYPE nonci_accounts gauge") + print(f"nonci_accounts {accounts - ci_accounts}") if __name__ == "__main__": diff --git a/chatmaild/src/chatmaild/tests/test_metrics.py b/chatmaild/src/chatmaild/tests/test_metrics.py index c48c4a77..e8a2be28 100644 --- a/chatmaild/src/chatmaild/tests/test_metrics.py +++ b/chatmaild/src/chatmaild/tests/test_metrics.py @@ -8,9 +8,10 @@ def test_main(tmp_path, capsys): out, _ = capsys.readouterr() d = {} for line in out.split("\n"): - if line.strip(): - name, num, _ = line.split() + if line.strip() and not line.startswith("#"): + name, num = line.split() d[name] = int(num) assert d["accounts"] == 4 assert d["ci_accounts"] == 3 + assert d["nonci_accounts"] == 1