Skip to main content

discord-ext-prometheus

PyPI Version PyPI Python Version Code style: black License MIT Grafana Dashboard Downloads

This is a extension library for discord.py 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_seconds Latency to Discord shard
discord_event_on_interaction Amount of interactions called by users shard, interaction, command
discord_event_on_command Amount of commands called by users 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 modals
  • on_command are traditional message commands (usualy using the command prefix)

Grafana Dashboard

Dashboard Preview

Available to import from Grafana dashboards.

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 import Intents
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 import Intents
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())

Changing the Prometheus port

The default port is 8000 but can be changed while creating the cog.

await bot.add_cog(PrometheusCog(bot, port=7000))

Metadata

Release files for discord-ext-prometheus 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for discord-ext-prometheus 0.2.1
File Size Uploaded
discord_ext_prometheus-0.2.1.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for discord-ext-prometheus 0.2.1
File Interpreter ABI Platform
discord_ext_prometheus-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.2 kB

Release files / discord_ext_prometheus-0.2.1.tar.gz

Download URL discord_ext_prometheus-0.2.1.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a65c176d2205868bfa6cf0ad01633cc3846939696d59c21dcc4a27c949dec368
BLAKE2b-256 checksum
How to use checksums
a8e4553725e355e632a73dc27f251f40c8b57400c9ffb496504013f7b02f5741
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release files / discord_ext_prometheus-0.2.1-py3-none-any.whl

Download URL discord_ext_prometheus-0.2.1-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2e13115c3f0fbb1a3fd3d67bff2711604742fb8742cc5e9eb80488854bf12f8
BLAKE2b-256 checksum
How to use checksums
2d0141648aaa4eb04f0be18ce5565ab7034c4dbf3b9fcc970222d24bb226a8bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

1 release file

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page