forked from Pavel_Durov/python_bot
be be be
This commit is contained in:
parent
3b4454fd44
commit
f4a1cee509
@ -4,3 +4,5 @@ import yaml
|
|||||||
|
|
||||||
with open("config.yaml", 'r') as f:
|
with open("config.yaml", 'r') as f:
|
||||||
CONFIG = yaml.load(f, Loader=yaml.Loader)
|
CONFIG = yaml.load(f, Loader=yaml.Loader)
|
||||||
|
|
||||||
|
METRICS_INITIALIZED = False
|
@ -1,6 +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
|
||||||
|
|
||||||
class user_info_struct:
|
class user_info_struct:
|
||||||
user_id: str
|
user_id: str
|
||||||
@ -11,17 +12,15 @@ class user_info_struct:
|
|||||||
chat_id: int
|
chat_id: int
|
||||||
|
|
||||||
|
|
||||||
global initialized
|
|
||||||
initialized = False
|
|
||||||
|
|
||||||
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."""
|
||||||
|
|
||||||
if not initialized:
|
if not METRICS_INITIALIZED:
|
||||||
pipisa_length_metric = Gauge('user_length_total', 'Pipisa length', labelnames=['ChatID', 'Username'])
|
pipisa_length_metric = Gauge('user_length_total', 'Pipisa length', labelnames=['ChatID', 'Username'])
|
||||||
user_attempt_metric = Gauge('user_attempts_total', 'Attempts count', labelnames=['ChatID', 'Username'])
|
user_attempt_metric = Gauge('user_attempts_total', 'Attempts count', labelnames=['ChatID', 'Username'])
|
||||||
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'])
|
||||||
initialized = True
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user