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.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea7f46bc0a398223b93035724ed0b142245b46a3a2cef55ebecd97e903cf66c5 |
|
MD5 | 3cd8269d09330e31ec0c183a434bcac7 |
|
BLAKE2b-256 | 9a953a1615d4cbc594c2dd2af07be05b8b1cb5248bf580b0510931983124d9d6 |