discord-ext-prometheus


Namediscord-ext-prometheus JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryAn extension for the discord.py library that enables Prometheus metrics
upload_time2024-06-12 02:52:13
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords analytics bot discord extension metrics prometheus
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# 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)
![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)
![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 extension library for [discord.py](https://github.com/Rapptz/discord.py) 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_seconds`      | 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())
```

## Changing 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": null,
    "name": "discord-ext-prometheus",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "Analytics, Bot, Discord, Extension, Metrics, Prometheus",
    "author": null,
    "author_email": "Apollo-Roboto <Apollo_Roboto@outlook.com>",
    "download_url": "https://files.pythonhosted.org/packages/89/ea/e2e04399a96e37b6ca936d1347529195f7e429bd42eabcecf465fd462a2f/discord_ext_prometheus-0.2.0.tar.gz",
    "platform": null,
    "description": "\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&logoColor=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&query=%24.downloads&logo=Grafana&label=downloads&color=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\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",
    "bugtrack_url": null,
    "license": null,
    "summary": "An extension for the discord.py library that enables Prometheus metrics",
    "version": "0.2.0",
    "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": "397666df49e157afcb582d969285ff5729b9464f167bffe12a7daef185650e91",
                "md5": "a3729d0625a4bf415df1859cb34745b1",
                "sha256": "fbf15acc4323e29b76862ee5394e105b37041cc3c99a13eaa07fa9a6dc17f994"
            },
            "downloads": -1,
            "filename": "discord_ext_prometheus-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a3729d0625a4bf415df1859cb34745b1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5854,
            "upload_time": "2024-06-12T02:52:12",
            "upload_time_iso_8601": "2024-06-12T02:52:12.623697Z",
            "url": "https://files.pythonhosted.org/packages/39/76/66df49e157afcb582d969285ff5729b9464f167bffe12a7daef185650e91/discord_ext_prometheus-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "89eae2e04399a96e37b6ca936d1347529195f7e429bd42eabcecf465fd462a2f",
                "md5": "3a1b33590c39ca1a503323ec71f8b5b9",
                "sha256": "016962b7d1350e99769cf67ed037f0d067f5043ddf9d15cfc92fa26875fd1a32"
            },
            "downloads": -1,
            "filename": "discord_ext_prometheus-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3a1b33590c39ca1a503323ec71f8b5b9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10059,
            "upload_time": "2024-06-12T02:52:13",
            "upload_time_iso_8601": "2024-06-12T02:52:13.977857Z",
            "url": "https://files.pythonhosted.org/packages/89/ea/e2e04399a96e37b6ca936d1347529195f7e429bd42eabcecf465fd462a2f/discord_ext_prometheus-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-12 02:52:13",
    "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,
    "lcname": "discord-ext-prometheus"
}
        
Elapsed time: 0.42807s