put prometheus stuff everywhere

This commit is contained in:
Lio Young 2021-05-14 21:49:47 +02:00
parent 6f894b31cf
commit 858f4f500f
No known key found for this signature in database
GPG Key ID: 789795A11879E169
5 changed files with 29 additions and 9 deletions

View File

@ -1,12 +1,13 @@
import Logger from "../utils/logger"
import config from "../../config"
import { Guild } from "discord.js"
import Prom from "../utils/init.prometheus";
export = {
name: "guildCreate",
// @ts-ignore
run: async (client, guild: Guild) => {
console.log(guild)
Prom.guildCount.inc()
Prom.totalGuilds.set(client.guilds.cache.size)
Logger.info({
type: "event:guildCreate",
message: `New Guild: ${guild.name} [${guild.id}]`

View File

@ -123,6 +123,7 @@ export = {
}
Prom.commandsExecuted.inc()
let { data: command_usage_data, command_usage_error } = await supabase.from<Usage>('usage').update({ amount: (usage_check_data[0] || { amount: 0 }).amount + 1 }).select().eq("name", cmd.name)
Logger.info({
type: "command:executed",

View File

@ -1,10 +1,11 @@
import Logger from "../utils/logger"
import config from "../../config"
import prom from "../utils/init.prometheus"
export = {
name: "ready",
// @ts-ignore
run: async (client: any) => {
prom.totalGuilds.set(client.guilds.cache.size)
Logger.info({
type: "event:ready",
message: `${config.variables.name} has started`

View File

@ -0,0 +1,16 @@
import Logger from "../utils/logger"
import { Guild } from "discord.js"
import Prom from "../utils/init.prometheus";
export = {
name: "guildDelete",
// @ts-ignore
run: async (client, guild: Guild) => {
Prom.guildCount.dec()
Prom.totalGuilds.set(client.guilds.cache.size)
Logger.info({
type: "event:guildDelete",
message: `Left Guild: ${guild.name} [${guild.id}]`
})
}
}

View File

@ -1,7 +1,4 @@
//! Code taken from NinoDiscord/Nino
import prom from "prom-client"
import { createServer, IncomingMessage, ServerResponse } from 'http'
import vars from "../../variables"
@ -10,7 +7,8 @@ import Logger from "./logger"
export default class Prometheus {
public commandsExecuted!: prom.Counter<string>
public messagesSeen!: prom.Counter<string>
public guildCount!: prom.Counter<string>
public guildCount!: prom.Gauge<string>
public totalGuilds!: prom.Gauge<string>
// public commmandsRan: prom.Counter<string>
#server!: ReturnType<typeof createServer>
@ -28,9 +26,12 @@ export default class Prometheus {
})
this.guildCount = new prom.Gauge({
name: "thaldrin_guild_count",
help: "Number of Guilds Thaldrin is in"
help: "Number of Guilds Thaldrin joined this Lifecycle"
})
this.totalGuilds = new prom.Gauge({
name: "thaldrin_guilds_total",
help: "Total Number of Guilds Thaldrin is in"
})
this.#server = createServer(this.onRequest.bind(this));
this.#server.once('listening', () => Logger.info(`Prometheus: Listening at http://localhost:${vars.prometheus.port}`));