Metrics added

This commit is contained in:
RakVhalate 2025-05-08 12:19:36 +10:00
parent a67531ce98
commit 1f3b4ec80f
5 changed files with 34 additions and 3 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ TIME.py
tests
qeqeqe
env
handlers/userdata.json

3
bot.py
View File

@ -4,6 +4,7 @@ from create_bot import dp
import handlers
import json, logging
from global_conf import CONFIG
from prometheus_client import start_http_server
@ -44,7 +45,7 @@ logging.getLogger("aiogram").addFilter(filter_grammar_messages)
if __name__ == '__main__':
#print(CONFIG)
start_http_server(1337)
logging.info('Бот в строю.')
executor.start_polling(dp, skip_updates=True)
logging.info('Всем пока.')

View File

@ -1,4 +1,5 @@
from db_logic import collections
from handlers.metrics import metric_wrap
import datetime, logging
@ -58,6 +59,7 @@ def update_dick_size(message, user, updatedDick ):
overwrite_mode='update'
)
metric_wrap(message.from_user.full_name,updatedDick,user['attempts'] + 1)
logging.info(f'Успешно апдейтнули пипису @{message.from_user.username}')
except Exception as e2:
logging.error(f'ошибка DB в /dick :: обновление пиписы @{message.from_user.username}')

26
handlers/metrics.py Normal file
View File

@ -0,0 +1,26 @@
import json
import time
from prometheus_client import Gauge, Info
class user_info_struct:
user_id: str
user_fullname: str
dick_size: int
datetimes: str
attemptsCount: int
chat_id: 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."""
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_last_attempt_metric = Gauge('user_last_attempt_time', 'Last attempt time', labelnames=['ChatID', 'Username'])
pipisa_length_metric.labels(chatID, userName).set(length)
user_attempt_metric.labels(chatID, userName).set(attemptsCount)
user_last_attempt_metric.labels(chatID, userName).set(time.time_ns())

View File

@ -1,3 +1,4 @@
aiogram==2.15
python-arango
pyyaml
prometheus-client