diff --git a/chatmaild/pyproject.toml b/chatmaild/pyproject.toml index 32b495b8..90c1fe9a 100644 --- a/chatmaild/pyproject.toml +++ b/chatmaild/pyproject.toml @@ -22,6 +22,7 @@ where = ['src'] doveauth = "chatmaild.doveauth:main" filtermail = "chatmaild.filtermail:main" echobot = "chatmaild.echo:main" +chatmail-metrics = "chatmaild.metrics:main" [project.entry-points.pytest11] "chatmaild.testplugin" = "chatmaild.tests.plugin" diff --git a/chatmaild/src/chatmaild/metrics.py b/chatmaild/src/chatmaild/metrics.py new file mode 100644 index 00000000..1d4132a9 --- /dev/null +++ b/chatmaild/src/chatmaild/metrics.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +from pathlib import Path +import time +import sys + + +def main(): + vmail_dir = sys.argv[1] + accounts = 0 + ci_accounts = 0 + + for path in Path(vmail_dir).iterdir(): + accounts += 1 + if path.name.startswith("ci-"): + ci_accounts += 1 + + timestamp = int(time.time() * 1000) + print(f"accounts {accounts} {timestamp}") + print(f"ci_accounts {ci_accounts} {timestamp}") + + +if __name__ == "__main__": + main() diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index cdde08cd..ec5b6372 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -84,6 +84,18 @@ def _install_remote_venv_with_chatmaild(config) -> None: ], ) + files.template( + src=importlib.resources.files(__package__).joinpath("metrics.cron.j2"), + dest="/etc/cron.d/chatmail-metrics", + user="root", + group="root", + mode="644", + config={ + "mail_domain": config.mail_domain, + "execpath": f"{remote_venv_dir}/bin/chatmail-metrics", + }, + ) + # install systemd units for fn in ( "doveauth", diff --git a/cmdeploy/src/cmdeploy/metrics.cron.j2 b/cmdeploy/src/cmdeploy/metrics.cron.j2 new file mode 100644 index 00000000..fbf768ea --- /dev/null +++ b/cmdeploy/src/cmdeploy/metrics.cron.j2 @@ -0,0 +1 @@ +*/5 * * * * root {{ config.execpath }} /home/vmail/mail/{{ config.mail_domain }} >/var/www/html/metrics diff --git a/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 b/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 index b0768edb..91cfd1db 100644 --- a/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 +++ b/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 @@ -41,6 +41,10 @@ http { try_files $uri $uri/ =404; } + location /metrics { + default_type text/plain; + } + # add cgi-bin support include /usr/share/doc/fcgiwrap/examples/nginx.conf; }