From 774350778b59d67b137791ae67a26469db43fffc Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 29 Oct 2025 12:08:18 +0000 Subject: [PATCH] feat: remove /metrics from the website Similar data is already generated by fsreport available for the relay operator and metrics for prometheus are generated by mtail. Closes --- chatmaild/pyproject.toml | 1 - chatmaild/src/chatmaild/metrics.py | 32 ------------------- chatmaild/src/chatmaild/tests/test_metrics.py | 24 -------------- cmdeploy/src/cmdeploy/deployers.py | 18 ++++------- cmdeploy/src/cmdeploy/metrics.cron.j2 | 1 - cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 | 4 --- doc/source/overview.rst | 6 ---- 7 files changed, 7 insertions(+), 79 deletions(-) delete mode 100644 chatmaild/src/chatmaild/metrics.py delete mode 100644 chatmaild/src/chatmaild/tests/test_metrics.py delete mode 100644 cmdeploy/src/cmdeploy/metrics.cron.j2 diff --git a/chatmaild/pyproject.toml b/chatmaild/pyproject.toml index 1eb00c0a..db3d7bbd 100644 --- a/chatmaild/pyproject.toml +++ b/chatmaild/pyproject.toml @@ -24,7 +24,6 @@ where = ['src'] [project.scripts] doveauth = "chatmaild.doveauth:main" chatmail-metadata = "chatmaild.metadata:main" -chatmail-metrics = "chatmaild.metrics:main" chatmail-expire = "chatmaild.expire:main" chatmail-fsreport = "chatmaild.fsreport:main" lastlogin = "chatmaild.lastlogin:main" diff --git a/chatmaild/src/chatmaild/metrics.py b/chatmaild/src/chatmaild/metrics.py deleted file mode 100644 index 646b48f7..00000000 --- a/chatmaild/src/chatmaild/metrics.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python3 -import sys -from pathlib import Path - - -def main(vmail_dir=None): - if vmail_dir is None: - vmail_dir = sys.argv[1] - - accounts = 0 - ci_accounts = 0 - - for path in Path(vmail_dir).iterdir(): - if not path.joinpath("cur").is_dir(): - continue - accounts += 1 - if path.name[:3] in ("ci-", "ac_"): - ci_accounts += 1 - - 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__": - main() diff --git a/chatmaild/src/chatmaild/tests/test_metrics.py b/chatmaild/src/chatmaild/tests/test_metrics.py deleted file mode 100644 index 0a8e5cb3..00000000 --- a/chatmaild/src/chatmaild/tests/test_metrics.py +++ /dev/null @@ -1,24 +0,0 @@ -from chatmaild.metrics import main - - -def test_main(tmp_path, capsys): - paths = [] - for x in ("ci-asllkj", "ac_12l3kj", "qweqwe", "ci-l1k2j31l2k3"): - p = tmp_path.joinpath(x) - p.mkdir() - p.joinpath("cur").mkdir() - paths.append(p) - - tmp_path.joinpath("nomailbox").mkdir() - - main(tmp_path) - out, _ = capsys.readouterr() - d = {} - for line in out.split("\n"): - 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 diff --git a/cmdeploy/src/cmdeploy/deployers.py b/cmdeploy/src/cmdeploy/deployers.py index 897ae6f0..21ac3db5 100644 --- a/cmdeploy/src/cmdeploy/deployers.py +++ b/cmdeploy/src/cmdeploy/deployers.py @@ -123,7 +123,6 @@ def _install_remote_venv_with_chatmaild() -> None: def _configure_remote_venv_with_chatmaild(config) -> None: remote_base_dir = "/usr/local/lib/chatmaild" - remote_venv_dir = f"{remote_base_dir}/venv" remote_chatmail_inipath = f"{remote_base_dir}/chatmail.ini" root_owned = dict(user="root", group="root", mode="644") @@ -134,16 +133,13 @@ def _configure_remote_venv_with_chatmaild(config) -> None: **root_owned, ) - files.template( - src=get_resource("metrics.cron.j2"), - dest="/etc/cron.d/chatmail-metrics", - user="root", - group="root", - mode="644", - config={ - "mailboxes_dir": config.mailboxes_dir, - "execpath": f"{remote_venv_dir}/bin/chatmail-metrics", - }, + files.file( + path="/etc/cron.d/chatmail-metrics", + present=False, + ) + files.file( + path="/var/www/html/metrics", + present=False, ) diff --git a/cmdeploy/src/cmdeploy/metrics.cron.j2 b/cmdeploy/src/cmdeploy/metrics.cron.j2 deleted file mode 100644 index 8bf036ad..00000000 --- a/cmdeploy/src/cmdeploy/metrics.cron.j2 +++ /dev/null @@ -1 +0,0 @@ -*/5 * * * * root {{ config.execpath }} {{ config.mailboxes_dir }} >/var/www/html/metrics diff --git a/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 b/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 index 67e77a80..ddb3a905 100644 --- a/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 +++ b/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 @@ -79,10 +79,6 @@ http { try_files $uri $uri/ =404; } - location /metrics { - default_type text/plain; - } - location /new { {% if config.tls_cert_mode != "self" %} if ($request_method = GET) { diff --git a/doc/source/overview.rst b/doc/source/overview.rst index dcc7f7ea..fd2c9401 100644 --- a/doc/source/overview.rst +++ b/doc/source/overview.rst @@ -109,10 +109,6 @@ short overview of ``chatmaild`` services: is contacted by Dovecot when a user logs in and stores the date of the login. -- `metrics `_ - collects some metrics and displays them at - ``https://example.org/metrics``. - ``www/`` ~~~~~~~~~ @@ -142,11 +138,9 @@ Chatmail relay dependency diagram nginx-internal --- autoconfig.xml; certs-nginx[("`TLS certs /var/lib/acme`")] --> nginx-internal; - systemd-timer --- chatmail-metrics; systemd-timer --- acmetool; systemd-timer --- chatmail-expire-daily; systemd-timer --- chatmail-fsreport-daily; - chatmail-metrics --- website; acmetool --> certs[("`TLS certs /var/lib/acme`")]; nginx-external --- |993|dovecot;