Aiogram`s exporter for Prometheus
Project description
aiogram Prometheus Exporter
Module for exporting monitoring values for Prometheus
Installation
pip install aiogram-prometheus
Quick start
import asyncio
import logging
from aiogram import Bot, Dispatcher
from aiogram.fsm.storage.memory import MemoryStorage
from aiogram.types import Message
from decouple import config
from aiogram_prometheus import (
DispatcherAiogramCollector,
PrometheusMetricMessageMiddleware,
PrometheusMetricStorageMixin,
PrometheusPrometheusMetricRequestMiddleware,
PushGatewayClient,
StorageAiogramCollector,
)
logging.basicConfig(level='DEBUG')
logger = logging.getLogger(__name__)
bot = Bot('TOKEN')
# Metric requests
# which are made by the target bot
bot.session.middleware(PrometheusPrometheusMetricRequestMiddleware())
# Metric storage
# Change "MemoryStorage" to your storage
class _Storage(PrometheusMetricStorageMixin, MemoryStorage):
pass
storage_collector = StorageAiogramCollector()
storage = _Storage(storage_collector)
dp = Dispatcher(storage=storage)
# Metric message
# which are processed by the dispatcher
dp.message.middleware(PrometheusMetricMessageMiddleware())
# Metric base info
DispatcherAiogramCollector(dp)
@dp.startup()
async def on_startup(bot: Bot):
# Make connect to your `PUSHGATEWAY` server
# For More: https://prometheus.io/docs/practices/pushing/
client = PushGatewayClient('http://localhost:9091/', 'job-name')
client.schedule_push()
@dp.message()
async def handle(message: Message) -> None:
await message.reply('Ok')
asyncio.run(dp.start_polling(bot))
Contribute
Issue Tracker: https://gitlab.com/rocshers/python/aiogram-prometheus/-/issues
Source Code: https://gitlab.com/rocshers/python/aiogram-prometheus
Before adding changes:
make install-dev
After changes:
make format test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for aiogram_prometheus-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2fde315f8543b22650c1ba343bc578da20fb384e6a0491f0332241060f43e9c |
|
MD5 | e83947f7975c5678850673676c7fa171 |
|
BLAKE2b-256 | 6d93a7e3f608f6c0a073c2be3e1fb6c32d0a766d10037bab52ef56b19e9ebf9b |