From 1319dceb038cd68f055eaa426cb071f2a9d6e1ab Mon Sep 17 00:00:00 2001 From: Chua Hui Shun Date: Thu, 16 Nov 2023 20:52:16 +0800 Subject: [PATCH] Add prometheus (#20) --- api.py | 6 ++++-- main.py | 1 - requirements.txt | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api.py b/api.py index d912cd5..35eddb9 100644 --- a/api.py +++ b/api.py @@ -10,14 +10,16 @@ from teleapi import endpoints as teleapi from threading import Thread from fastapi import FastAPI, Response +from prometheus_fastapi_instrumentator import Instrumentator import config from bot.ptb import lifespan -cpu_usage = Gauge("cpu_usage", "CPU Usage") -memory_usage = Gauge("memory_usage", "Memory Usage") app = FastAPI(lifespan=lifespan) if config.ENV else FastAPI() +Instrumentator().instrument(app).expose(app) +cpu_usage = Gauge("cpu_usage", "CPU Usage") +memory_usage = Gauge("memory_usage", "Memory Usage") @app.get("/") diff --git a/main.py b/main.py index 16ed275..917c42f 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ -import asyncio from http import HTTPStatus from fastapi import Request, Response from telegram.ext import ( diff --git a/requirements.txt b/requirements.txt index d6f8cbb..23b095f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -44,6 +44,7 @@ pathspec==0.9.0 platformdirs==2.5.2 pluggy==1.0.0 prometheus-client==0.16.0 +prometheus-fastapi-instrumentator==6.1.0 protobuf==3.20.1 psutil==5.9.5 pyaes==1.6.1