Files
tg_post_min/app/infra/metrics.py
Andrey K. Choi c16ec54891 Bot become a Community Guard & Post send manager
added: dictionary support for censore
message/user management with dict triggers
2025-08-22 21:44:14 +09:00

16 lines
708 B
Python

import os
from prometheus_client import Counter, Histogram, start_http_server
# Счётчики/гистограммы для модерации и команд
MSG_PROCESSED = Counter("mod_messages_processed_total", "Incoming messages processed")
MSG_BLOCKED = Counter("mod_messages_blocked_total", "Incoming messages blocked")
MOD_LAT = Histogram("moderation_latency_seconds", "Latency of moderation checks",
buckets=(0.02, 0.05, 0.1, 0.2, 0.5, 1, 2))
def start_metrics_server(port: int):
try:
start_http_server(port)
except Exception:
# не валим бота, если порт занят/метрики не взлетели
pass