be be bechka lo
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
hogweed1 2025-05-12 21:38:25 +10:00
parent 5f0d211a9b
commit 7e52c86067
2 changed files with 12 additions and 5 deletions

View File

@ -6,3 +6,7 @@ with open("config.yaml", 'r') as f:
CONFIG = yaml.load(f, Loader=yaml.Loader) CONFIG = yaml.load(f, Loader=yaml.Loader)
METRICS_INITIALIZED = False METRICS_INITIALIZED = False
pipisa_length_metric = None
user_attempt_metric = None
user_last_attempt_metric = None

View File

@ -1,7 +1,7 @@
import json import json
import time import time
from prometheus_client import Gauge, Info from prometheus_client import Gauge, Info
from global_conf import METRICS_INITIALIZED from global_conf import pipisa_length_metric, user_attempt_metric, user_last_attempt_metric
class user_info_struct: class user_info_struct:
user_id: str user_id: str
@ -16,12 +16,15 @@ class user_info_struct:
def metric_wrap(chatID:int, userName: str, length: int, attemptsCount: int): def metric_wrap(chatID:int, userName: str, length: int, attemptsCount: int):
"""Pass here chat ID, username, pipisa length and attempts count to wrap them into metric.""" """Pass here chat ID, username, pipisa length and attempts count to wrap them into metric."""
global METRICS_INITIALIZED global pipisa_length_metric
if not METRICS_INITIALIZED: if not pipisa_length_metric:
pipisa_length_metric = Gauge('user_length_total', 'Pipisa length', labelnames=['ChatID', 'Username']) pipisa_length_metric = Gauge('user_length_total', 'Pipisa length', labelnames=['ChatID', 'Username'])
global user_attempt_metric
if not user_attempt_metric:
user_attempt_metric = Gauge('user_attempts_total', 'Attempts count', labelnames=['ChatID', 'Username']) user_attempt_metric = Gauge('user_attempts_total', 'Attempts count', labelnames=['ChatID', 'Username'])
global user_last_attempt_metric
if not user_last_attempt_metric:
user_last_attempt_metric = Gauge('user_last_attempt_time', 'Last attempt time', labelnames=['ChatID', 'Username']) user_last_attempt_metric = Gauge('user_last_attempt_time', 'Last attempt time', labelnames=['ChatID', 'Username'])
METRICS_INITIALIZED = True
pipisa_length_metric.labels(chatID, userName).set(length) pipisa_length_metric.labels(chatID, userName).set(length)
user_attempt_metric.labels(chatID, userName).set(attemptsCount) user_attempt_metric.labels(chatID, userName).set(attemptsCount)