Skip to main content

PyPi

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

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))

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discord_ext_prometheus-0.1.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

discord_ext_prometheus-0.1.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file discord_ext_prometheus-0.1.1.tar.gz.

File metadata

  • Download URL: discord_ext_prometheus-0.1.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for discord_ext_prometheus-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4cd790332210c4be793bbf54958a9a45b39b96ad32cfd6a81ab2035429c446c9
MD5 a04834694ba80502687f7af95ebf9638
BLAKE2b-256 6813252aab655b4e42e09947ff8f61209e07f191621812ba8005811996bd478d

See more details on using hashes here.

File details

Details for the file discord_ext_prometheus-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for discord_ext_prometheus-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cbc34cecda1377d6e40bd3bf975fb9c12176a0f6717c57aaf0e4a4b71778550c
MD5 a6c0d42d3ee94eb59b6099b0a826148e
BLAKE2b-256 ba5d74c43340524834cb61d1993f83ca473140d93ff87f0488aa8964440eef6e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page