diff --git a/.gitignore b/.gitignore index 376fb63..f0785a9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ TIME.py .vscode tests qeqeqe -env \ No newline at end of file +env +handlers/userdata.json \ No newline at end of file diff --git a/bot.py b/bot.py index f500670..1b85b7f 100644 --- a/bot.py +++ b/bot.py @@ -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('Всем пока.') diff --git a/db_logic/user_stuff.py b/db_logic/user_stuff.py index af419b5..d49fb1e 100644 --- a/db_logic/user_stuff.py +++ b/db_logic/user_stuff.py @@ -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.chat.id, 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}') diff --git a/handlers/metrics.py b/handlers/metrics.py new file mode 100644 index 0000000..f4450d6 --- /dev/null +++ b/handlers/metrics.py @@ -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()) diff --git a/requairements.txt b/requairements.txt index 5fbc629..6c333d4 100644 --- a/requairements.txt +++ b/requairements.txt @@ -1,3 +1,4 @@ aiogram==2.15 python-arango -pyyaml \ No newline at end of file +pyyaml +prometheus-client \ No newline at end of file