Skip to content

Commit 9505525

Browse files
committed
Add prometheus
1 parent b62b5ab commit 9505525

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

bot/bot.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import nextcord
22
from nextcord.ext import commands
33
from shared.config import CHANNEL_ID, DISCORD_TOKEN, GUILD_ID
4+
from prometheus_client import start_http_server, Gauge
5+
import time
6+
7+
BOT_STATUS = Gauge('discord_bot_status', 'Status of the Discord bot', ['bot_name'])
8+
bot_name = 'Kernel'
49

510
# Create an instance of the bot with all intents enabled
611
intents = nextcord.Intents.all()
@@ -36,17 +41,30 @@ async def update_message(content):
3641

3742
@bot.event
3843
async def on_ready():
39-
await bot.tree.sync()
4044
"""
4145
An event listener for when the bot is ready and operational.
4246
4347
Prints a message to the console to indicate that the bot is ready.
4448
"""
45-
print('Bot is ready.')
49+
print(f'{bot_name} has connected to Discord!')
50+
# Mark the bot as "up" when it is online
51+
BOT_STATUS.labels(bot_name=bot_name).set(1)
4652

4753
# Importing slash commands and context menus
4854
# from . import slash_commands, context_menus
4955

56+
@bot.event
57+
async def on_disconnect():
58+
print(f'{bot_name} has disconnected from Discord!')
59+
# Mark the bot as "down" when it is offline
60+
BOT_STATUS.labels(bot_name=bot_name).set(0)
61+
62+
def start_prometheus_server():
63+
# Start a Prometheus HTTP server on port 8000
64+
start_http_server(8000)
65+
print("Prometheus server started on port 8000")
66+
5067
if __name__ == '__main__':
68+
start_prometheus_server()
5169
# Run the bot with the specified token
5270
bot.run(DISCORD_TOKEN)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ requests
44
python-dotenv
55
asyncio
66
feedparser
7+
prometheus_client

0 commit comments

Comments
 (0)