{"id":15062621,"url":"https://github.com/apollo-roboto/discord.py-ext-prometheus","last_synced_at":"2025-04-10T10:08:52.101Z","repository":{"id":65334777,"uuid":"576108811","full_name":"Apollo-Roboto/discord.py-ext-prometheus","owner":"Apollo-Roboto","description":"Add Prometheus to your Discord bot with this handy extension","archived":false,"fork":false,"pushed_at":"2024-03-10T20:18:15.000Z","size":39,"stargazers_count":14,"open_issues_count":2,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-21T07:28:00.976Z","etag":null,"topics":["discord","discord-bot","grafana","grafana-dashboard","prometheus","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/discord-ext-prometheus/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Apollo-Roboto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"apolloroboto"}},"created_at":"2022-12-09T02:57:34.000Z","updated_at":"2024-06-09T20:30:56.082Z","dependencies_parsed_at":"2023-02-19T02:15:44.510Z","dependency_job_id":"d7e8df94-69f3-42f8-b4ad-3d6ad42f5325","html_url":"https://github.com/Apollo-Roboto/discord.py-ext-prometheus","commit_stats":{"total_commits":17,"total_committers":3,"mean_commits":5.666666666666667,"dds":"0.23529411764705888","last_synced_commit":"84f052263f44d6e51224506c071106de8c870dec"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apollo-Roboto%2Fdiscord.py-ext-prometheus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apollo-Roboto%2Fdiscord.py-ext-prometheus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apollo-Roboto%2Fdiscord.py-ext-prometheus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apollo-Roboto%2Fdiscord.py-ext-prometheus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Apollo-Roboto","download_url":"https://codeload.github.com/Apollo-Roboto/discord.py-ext-prometheus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248198884,"owners_count":21063628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","discord-bot","grafana","grafana-dashboard","prometheus","python"],"created_at":"2024-09-24T23:43:52.844Z","updated_at":"2025-04-10T10:08:52.086Z","avatar_url":"https://github.com/Apollo-Roboto.png","language":"Python","funding_links":["https://ko-fi.com/apolloroboto"],"categories":[],"sub_categories":[],"readme":"\n# discord-ext-prometheus\n\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\u0026logoColor=gold)\n![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)\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\u0026query=%24.downloads\u0026logo=Grafana\u0026label=downloads\u0026color=orange)\n\nThis is a extension library for [discord.py](https://github.com/Rapptz/discord.py) 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_seconds`      | 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\nThis extension won't do much by itself, you must have an instance of [Prometheus](https://prometheus.io/) configured to collect those metrics and an instance of [Grafana](https://grafana.com/grafana/) to visualize it.\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    bot = commands.Bot(\n        command_prefix=\"!\",\n        intents=Intents.all(),\n    )\n\n    await bot.add_cog(PrometheusCog(bot))\n\n    await 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    bot = commands.Bot(\n        command_prefix=\"!\",\n        intents=Intents.all(),\n    )\n\n    await bot.add_cog(PrometheusCog(bot))\n\n    @bot.listen()\n    async def on_ready():\n        logging.info(f\"Logged in as {bot.user.name}#{bot.user.discriminator}\")\n\n    logging.info(\"Starting the bot\")\n    await bot.start(\"YOUR TOKEN\")\n\nasyncio.run(main())\n```\n\n## Changing 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\n## Configuring Prometheus\n\nHere is a quick example scrape config that you would write in `prometheus.yml`. *(make sure to replace name and host accordinly)*\n\n```yaml\nscrape_configs:\n  - job_name: \"discordBot{{ name }}\"\n    static_configs:\n      - targets: [\"{{ host }}:8000\"]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapollo-roboto%2Fdiscord.py-ext-prometheus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapollo-roboto%2Fdiscord.py-ext-prometheus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapollo-roboto%2Fdiscord.py-ext-prometheus/lists"}