Skip to main content

An extension for the discord.py library that enables Prometheus metrics

Project description

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 modals
  • on_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

from discord.ext.prometheus import *

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

from discord.ext.prometheus import *
import logging

logging.getLogger().addHandler(PrometheusLoggingHandler())

async def main():
	bot = commands.Bot(
		command_prefix='!',
		intents=Intents.all(),
	)

	await bot.add_cog(PrometheusCog(bot))

	logging.info('Starting the bot')
	await bot.start('YOUR TOKEN')

	@bot.listen()
	async def on_ready():
		logging.info(f'Logged in as {bot.user.name}#{bot.user.discriminator}')

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


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.0.4.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

discord_ext_prometheus-0.0.4-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for discord_ext_prometheus-0.0.4.tar.gz
Algorithm Hash digest
SHA256 521e4eed7f01ca2d9f9c3658f32d14f2a30241d78d58352610b7a4b51fed03bd
MD5 dd0fa57285e6ff8f21ada0dcc2d1f7c7
BLAKE2b-256 901240432c44eb4ee5772445a01fe9ee9db0126ede78a5caee98b3fd016651b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for discord_ext_prometheus-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8cc817f2fb7cf56e3f9f0b7976158140ea317e6a1301134065c3148979910222
MD5 632d6fd1f781d597983fa7a77522efe4
BLAKE2b-256 d62dc861cf613327c4e35aee051f692d0e15b8c6d00b6f799e1564df17c2219a

See more details on using hashes here.

Supported by

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