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 None
discord_event_on_interaction Amount of interactions command
discord_event_on_command Amount of commands 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
  • 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.3.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

discord_ext_prometheus-0.0.3-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for discord_ext_prometheus-0.0.3.tar.gz
Algorithm Hash digest
SHA256 501e3025194702c5174ca0da3fede486fde2ded14e7c5e00b293f30ee8b5b089
MD5 c254b6a59aa7a30e5de63acc5aae10b9
BLAKE2b-256 4421842d282f18229ad80d4f04e64518e693250513963d572996d3ba47c7eddb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for discord_ext_prometheus-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c180f002968af009c0ae1351e462188a7d6743ea7e3581a01e76b24d625cf385
MD5 ff3ccb07642b4e83e9bdc182c5869a93
BLAKE2b-256 653a82c566f1751eb9a1494db81594c423dfcbbb5e9d9244a5b50d3cd866c9a4

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