1
0
mirror of https://github.com/osmarks/autobotrobot synced 2024-11-05 00:06:17 +00:00

fix prometheus sstuff

This commit is contained in:
osmarks 2021-01-27 20:35:32 +00:00
parent 4e1dc6b337
commit 8f25254204
5 changed files with 24 additions and 11 deletions

View File

@ -6,11 +6,9 @@ import discord
from datetime import datetime
import re
import collections
import prometheus_client
import util
achievements_achieved = prometheus_client.Counter("abr_achievements", "Achievements achieved by users")
import metrics
Achievement = collections.namedtuple("Achievement", ["name", "condition", "description"])
@ -43,7 +41,7 @@ async def achieve(bot: commands.Bot, message: discord.Message, achievement):
e = util.make_embed(description=description, title="Achievement achieved!", color=util.hashbow(achievement))
e.set_thumbnail(url=await util.get_asset(bot, f"achievements/{achievement}.png"))
await channel.send(embed=e)
achievements_achieved.inc()
metrics.achievements_achieved.inc()
await bot.database.execute("INSERT INTO achievements VALUES (?, ?, ?)", (uid, achievement, util.timestamp()))
await bot.database.commit()
logging.info("awarded achievement %s to %s", message.author.name, achievement)

View File

@ -2,16 +2,14 @@ import util
import random
import logging
import discord
import prometheus_client
heavserver_members = prometheus_client.Gauge("abr_heavserver_members", "Current member count of heavserver")
import metrics
def setup(bot):
@bot.listen()
async def on_member_join(member):
if member.guild.id == util.config["heavserver"]["id"]:
logging.info("%s (%d) joined heavserver", member.display_name, member.id)
heavserver_members.set(len(bot.get_guild(util.config["heavserver"]["id"]).members))
if member.bot:
await member.add_roles(discord.utils.get(member.guild.roles, id=util.config["heavserver"]["quarantine_role"]))
await member.add_roles(discord.utils.get(member.guild.roles, id=random.choice(util.config["heavserver"]["moderator_roles"][:])))

View File

@ -225,6 +225,21 @@ async def on_ready():
await bot.change_presence(status=discord.Status.online,
activity=discord.Activity(name=f"{bot.command_prefix}help", type=discord.ActivityType.listening))
visible_users = prometheus_client.Gauge("abr_visible_users", "Users the bot can see")
def get_visible_users():
return len(bot.users)
visible_users.set_function(get_visible_users)
heavserver_members = prometheus_client.Gauge("abr_heavserver_members", "Current member count of heavserver")
def get_heavserver_members():
return len(bot.get_guild(util.config["heavserver"]["id"]).members)
heavserver_members.set_function(get_heavserver_members)
guild_count = prometheus_client.Gauge("abr_guilds", "Guilds the bot is in")
def get_guild_count():
return len(bot.guilds)
guild_count.set_function(get_guild_count)
async def run_bot():
bot.database = await db.init(config["database"])
for ext in util.extensions:

4
src/metrics.py Normal file
View File

@ -0,0 +1,4 @@
import prometheus_client
achievements_achieved = prometheus_client.Counter("abr_achievements", "Achievements achieved by users")
reminders_fired = prometheus_client.Counter("abr_reminders", "Reminders successfully delivered to users")

View File

@ -2,11 +2,9 @@ import json
import logging
from datetime import datetime, timezone
import discord.ext.tasks as tasks
import prometheus_client
import util
reminders_fired = prometheus_client.Counter("abr_reminders", "Reminders successfully delivered to users")
import metrics
def setup(bot):
@bot.command(brief="Set a reminder to be reminded about later.", rest_is_raw=True, help="""Sets a reminder which you will (probably) be reminded about at/after the specified time.
@ -89,7 +87,7 @@ def setup(bot):
print("trying", method_name, rid)
try:
await func(extra, text)
reminders_fired.inc()
metrics.reminders_fired.inc()
to_expire.append((1, rid)) # 1 = expired normally
break
except Exception as e: logging.warning("failed to send %d to %s", rid, method_name, exc_info=e)