An extension for the discord.py library that enables Prometheus metrics
Project description
discord-ext-prometheus
This is a library that makes it easy to add prometheus metrics to your Python Discord bot.
Installation
pip install discord-ext-prometheus
Exposed Metrics
Name | Documentation | Labels |
---|---|---|
discord_connected |
Determines if the bot is connected to Discord | shard |
discord_latency |
Latency to Discord | shard |
discord_event_on_interaction |
Amount of interactions | shard , interaction , command |
discord_event_on_command |
Amount of commands | shard , command |
discord_stat_total_guilds |
Amount of guild this bot is a member of | None |
discord_stat_total_channels |
Amount of channels this bot is has access to | None |
discord_stat_total_users |
Amount of users this bot can see | None |
discord_stat_total_commands |
Amount of commands | None |
logging |
Log entries | logger , level |
Notes:
on_interaction
are application interactions such as slash commands or modalson_command
are traditional message commands (usualy using the command prefix)
Grafana Dashboard
TODO
How to use
Once the cog is added to your bot, the Prometheus metric endpoint can be accessed
at localhost:8000/metrics
.
Sample code with the Prometheus Cog
import asyncio
from discord.ext import commands
from discord.ext.prometheus import PrometheusCog
async def main():
bot = commands.Bot(
command_prefix='!',
intents=Intents.all(),
)
await bot.add_cog(PrometheusCog(bot))
await bot.start('YOUR TOKEN')
asyncio.run(main())
Sample code with logging metrics
import asyncio
import logging
from discord.ext import commands
from discord.ext.prometheus import PrometheusCog, PrometheusLoggingHandler
logging.getLogger().addHandler(PrometheusLoggingHandler())
async def main():
bot = commands.Bot(
command_prefix='!',
intents=Intents.all(),
)
await bot.add_cog(PrometheusCog(bot))
@bot.listen()
async def on_ready():
logging.info(f'Logged in as {bot.user.name}#{bot.user.discriminator}')
logging.info('Starting the bot')
await bot.start('YOUR TOKEN')
asyncio.run(main())
Change the Prometheus port
The default port is 8000
but can be changed while creating the cog.
await bot.add_cog(PrometheusCog(bot, port=7000))
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
File details
Details for the file discord_ext_prometheus-0.0.5.tar.gz
.
File metadata
- Download URL: discord_ext_prometheus-0.0.5.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b55dcd8677150a9f5d9b7be6bfe3d082beddeae909ea9b6573b7a5500b5277c |
|
MD5 | 85fda916d4030473bd010061ffb19329 |
|
BLAKE2b-256 | d8a25a515e5733e111f921bcbe2b28c441939c9225167a59f06f37ca6a84f97f |
File details
Details for the file discord_ext_prometheus-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: discord_ext_prometheus-0.0.5-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fa729731f47907dd9d39abf0a2350b64613e26ad8d772128e44f9e803feeb98 |
|
MD5 | 660330f1fbe6deba4224bda047dd08ad |
|
BLAKE2b-256 | 547369ab671be885a4c30d6df4da9ecd3cd9dcef4813f37d1b20301223156f8f |