Modified
Prometheus Extension for discord.py
Published
()
By ApolloRoboto
Originally created in 2022
As I was on a DevOps team at the time, I wanted to put the Prometheus metrics into everything. So naturally I implemented it for my own Discord bot too.
Implementation
This was built for the discord.py library. I made it as easy as possible to add, being inspired from other similar extensions, it’s a simple cog that you can add with add_cog().
import os
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(os.environ["DISCORD_TOKEN"])
if __name__ == "__main__":
asyncio.run(main())And from there, your metrics are accessible at localhost:8000/metrics
Grafana

The Grafana dashboard shows a bunch of overall metrics:
- Multiple discord bot support.
- All called commands, including buttons and other Discord interactions.
- Stats like the amount of users and servers each bot sees.
- Up time and connection status with latency.
- Log rates (optional)
So it has everything you need to get a good overview on how your bots are doing. And it seems like developers are enjoying it too as It got 20 stars on GitHub at the time of writing.
