# discord-ext-prometheus
![PyPi Version](https://img.shields.io/pypi/v/discord-ext-prometheus.svg)
![PyPI Python Version](https://img.shields.io/pypi/pyversions/discord-ext-prometheus.svg?logo=python&logoColor=gold)
![License MIT](https://img.shields.io/pypi/l/discord-ext-prometheus)
![Grafana Dashboard Downloads](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgrafana.com%2Fapi%2Fdashboards%2F17670&query=%24.downloads&logo=Grafana&label=downloads&color=orange)
This is a library that makes it easy to add prometheus metrics to your Python Discord bot.
# Installation
```bash
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](https://grafana.com/api/dashboards/17670/images/13525/image)
Available to import from [Grafana dashboards](https://grafana.com/grafana/dashboards/17670-discord-bot/)
# 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
```python
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
```python
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.
```python
await bot.add_cog(PrometheusCog(bot, port=7000))
```
Raw data
{
"_id": null,
"home_page": "",
"name": "discord-ext-prometheus",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "Analytics,Bot,Discord,Extension,Metrics,Prometheus",
"author": "",
"author_email": "Apollo-Roboto <Apollo_Roboto@outlook.com>",
"download_url": "https://files.pythonhosted.org/packages/30/62/614dc7154e8fb2aa457986713e0d41b924f3c795602a5bac19cfbc796335/discord_ext_prometheus-0.1.5.tar.gz",
"platform": null,
"description": "\n# discord-ext-prometheus\n![PyPi Version](https://img.shields.io/pypi/v/discord-ext-prometheus.svg)\n![PyPI Python Version](https://img.shields.io/pypi/pyversions/discord-ext-prometheus.svg?logo=python&logoColor=gold)\n![License MIT](https://img.shields.io/pypi/l/discord-ext-prometheus)\n![Grafana Dashboard Downloads](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgrafana.com%2Fapi%2Fdashboards%2F17670&query=%24.downloads&logo=Grafana&label=downloads&color=orange)\n\nThis is a library that makes it easy to add prometheus metrics to your Python Discord bot.\n\n# Installation\n\n```bash\npip install discord-ext-prometheus\n```\n\n# Exposed Metrics\n\n| Name | Documentation | Labels |\n|--------------------------------|-----------------------------------------------|-----------------------------------|\n| `discord_connected` | Determines if the bot is connected to Discord | `shard` |\n| `discord_latency` | Latency to Discord | `shard` |\n| `discord_event_on_interaction` | Amount of interactions called by users | `shard`, `interaction`, `command` |\n| `discord_event_on_command` | Amount of commands called by users | `shard`, `command` |\n| `discord_stat_total_guilds` | Amount of guild this bot is a member of | None |\n| `discord_stat_total_channels` | Amount of channels this bot is has access to | None |\n| `discord_stat_total_users` | Amount of users this bot can see | None |\n| `discord_stat_total_commands` | Amount of commands | None |\n| `logging` | Log entries | `logger`, `level` |\n\nNotes:\n- `on_interaction` are application interactions such as slash commands or modals\n- `on_command` are traditional message commands (usualy using the command prefix)\n\n# Grafana Dashboard\n\n![Dashboard Preview](https://grafana.com/api/dashboards/17670/images/13525/image)\n\nAvailable to import from [Grafana dashboards](https://grafana.com/grafana/dashboards/17670-discord-bot/)\n\n# How to use\n\nOnce the cog is added to your bot, the Prometheus metric endpoint can be accessed\nat `localhost:8000/metrics`.\n\n## Sample code with the Prometheus Cog\n\n```python\nimport asyncio\nfrom discord import Intents\nfrom discord.ext import commands\nfrom discord.ext.prometheus import PrometheusCog\n\nasync def main():\n\tbot = commands.Bot(\n\t\tcommand_prefix='!',\n\t\tintents=Intents.all(),\n\t)\n\n\tawait bot.add_cog(PrometheusCog(bot))\n\n\tawait bot.start('YOUR TOKEN')\n\nasyncio.run(main())\n```\n\n## Sample code with logging metrics\n\n```python\nimport asyncio\nimport logging\nfrom discord import Intents\nfrom discord.ext import commands\nfrom discord.ext.prometheus import PrometheusCog, PrometheusLoggingHandler\n\nlogging.getLogger().addHandler(PrometheusLoggingHandler())\n\nasync def main():\n\tbot = commands.Bot(\n\t\tcommand_prefix='!',\n\t\tintents=Intents.all(),\n\t)\n\n\tawait bot.add_cog(PrometheusCog(bot))\n\n\t@bot.listen()\n\tasync def on_ready():\n\t\tlogging.info(f'Logged in as {bot.user.name}#{bot.user.discriminator}')\n\n\tlogging.info('Starting the bot')\n\tawait bot.start('YOUR TOKEN')\n\nasyncio.run(main())\n```\n\n## Change the Prometheus port\n\nThe default port is `8000` but can be changed while creating the cog.\n\n```python\nawait bot.add_cog(PrometheusCog(bot, port=7000))\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "An extension for the discord.py library that enables Prometheus metrics",
"version": "0.1.5",
"project_urls": {
"Source": "https://github.com/Apollo-Roboto/discord.py-ext-prometheus"
},
"split_keywords": [
"analytics",
"bot",
"discord",
"extension",
"metrics",
"prometheus"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b66d5eaed1bc5185ca6a62c41ec7bc5b2179be5e100e2a8e5ebff9e0b5a06f23",
"md5": "ff16a075e7e600cc596859cc9407098b",
"sha256": "7a8ffd09c74e91ff8781db1899d86d9cef8112aee87e326583498c95812aad3d"
},
"downloads": -1,
"filename": "discord_ext_prometheus-0.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ff16a075e7e600cc596859cc9407098b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5707,
"upload_time": "2023-09-29T03:22:13",
"upload_time_iso_8601": "2023-09-29T03:22:13.909873Z",
"url": "https://files.pythonhosted.org/packages/b6/6d/5eaed1bc5185ca6a62c41ec7bc5b2179be5e100e2a8e5ebff9e0b5a06f23/discord_ext_prometheus-0.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3062614dc7154e8fb2aa457986713e0d41b924f3c795602a5bac19cfbc796335",
"md5": "3ffe6e5e992700f1c40e2c4f26260e8b",
"sha256": "031f93b6f50e0430c410c4f91b3940ac563d7a461421064078fded5abe74c9b2"
},
"downloads": -1,
"filename": "discord_ext_prometheus-0.1.5.tar.gz",
"has_sig": false,
"md5_digest": "3ffe6e5e992700f1c40e2c4f26260e8b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9738,
"upload_time": "2023-09-29T03:22:15",
"upload_time_iso_8601": "2023-09-29T03:22:15.423180Z",
"url": "https://files.pythonhosted.org/packages/30/62/614dc7154e8fb2aa457986713e0d41b924f3c795602a5bac19cfbc796335/discord_ext_prometheus-0.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-29 03:22:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Apollo-Roboto",
"github_project": "discord.py-ext-prometheus",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "discord-ext-prometheus"
}