mirror of
https://github.com/thaldrin/thaldrin.git
synced 2024-08-14 23:57:21 +00:00
stat stuff
This commit is contained in:
parent
aece129f04
commit
67bd79fcd5
3 changed files with 40 additions and 2 deletions
|
@ -3,6 +3,19 @@ import { Context, Usage } from '../../utils/types';
|
||||||
import lingua from '../../utils/lingua';
|
import lingua from '../../utils/lingua';
|
||||||
import { MessageEmbed } from 'discord.js';
|
import { MessageEmbed } from 'discord.js';
|
||||||
import CommandUsage from '../../utils/command.usage';
|
import CommandUsage from '../../utils/command.usage';
|
||||||
|
import { commitHash } from "../../utils/git"
|
||||||
|
|
||||||
|
function uptime(ms: number) {
|
||||||
|
function pad(s: number) {
|
||||||
|
return (s < 10 ? '0' : '') + s;
|
||||||
|
}
|
||||||
|
var days = Math.floor(ms / (24 * ((60 * 60))));
|
||||||
|
var hours = Math.floor(ms / (60 * 60));
|
||||||
|
var minutes = Math.floor((ms % (60 * 60)) / 60);
|
||||||
|
var seconds = Math.floor(ms % 60);
|
||||||
|
return `${pad(days)}d ${pad(hours)}h ${pad(minutes)}m ${pad(seconds)}s`
|
||||||
|
// return pad(hours) + 'h ' + pad(minutes) + 'm ' + pad(seconds) + 's';
|
||||||
|
}
|
||||||
|
|
||||||
export = class Stats extends Command {
|
export = class Stats extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -15,8 +28,24 @@ export = class Stats extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
async command(ctx: Context) {
|
async command(ctx: Context) {
|
||||||
let Stats = await CommandUsage(ctx.client.commands)
|
// @ts-ignore
|
||||||
console.log(Stats)
|
const guilds = (await ctx.client.shard?.fetchClientValues(`guilds.cache.size`)).reduce((a, b) => a + b, 0)
|
||||||
|
const shards = ctx.client.shard?.count
|
||||||
|
const users = (await ctx.client.shard?.fetchClientValues(`users.cache.size`))?.reduce((a, b) => a + b, 0)
|
||||||
|
|
||||||
|
let MiscValues = [
|
||||||
|
`Uptime: **${uptime(process.uptime())}**`,
|
||||||
|
`Guilds: **${guilds}**`,
|
||||||
|
`Shards: **${shards}**`,
|
||||||
|
`Users: **${users}**`
|
||||||
|
]
|
||||||
|
|
||||||
|
let embed = new MessageEmbed().setColor(ctx.config.variables.color).setFooter(`${ctx.config.variables.name} v${ctx.config.pkg.version} [${commitHash}]`, ctx.config.variables.avatar)
|
||||||
|
.setTitle(`Statistics`)
|
||||||
|
.setDescription(`Visit [our System Dashboard](https://system.thaldr.in) for more in-depth stats`)
|
||||||
|
.addField(`Misc`, MiscValues.map((value) => `${value}`))
|
||||||
|
|
||||||
|
|
||||||
|
ctx.channel.send(embed)
|
||||||
}
|
}
|
||||||
}
|
}
|
3
src/utils/git.ts
Normal file
3
src/utils/git.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import { execSync } from 'child_process';
|
||||||
|
|
||||||
|
export const commitHash = execSync('git rev-parse HEAD', { encoding: 'utf8' }).slice(0, 8);
|
|
@ -9,6 +9,7 @@ export default class Prometheus {
|
||||||
public messagesSeen!: prom.Counter<string>
|
public messagesSeen!: prom.Counter<string>
|
||||||
public guildCount!: prom.Gauge<string>
|
public guildCount!: prom.Gauge<string>
|
||||||
public totalGuilds!: prom.Gauge<string>
|
public totalGuilds!: prom.Gauge<string>
|
||||||
|
public uptime!: prom.Gauge<string>
|
||||||
// public commmandsRan: prom.Counter<string>
|
// public commmandsRan: prom.Counter<string>
|
||||||
#server!: ReturnType<typeof createServer>
|
#server!: ReturnType<typeof createServer>
|
||||||
|
|
||||||
|
@ -32,6 +33,10 @@ export default class Prometheus {
|
||||||
name: "thaldrin_guilds_total",
|
name: "thaldrin_guilds_total",
|
||||||
help: "Total Number of Guilds Thaldrin is in"
|
help: "Total Number of Guilds Thaldrin is in"
|
||||||
})
|
})
|
||||||
|
this.uptime = new prom.Gauge({
|
||||||
|
name: "thaldrin_uptime",
|
||||||
|
help: "Thaldrin's Uptime"
|
||||||
|
})
|
||||||
|
|
||||||
this.#server = createServer(this.onRequest.bind(this));
|
this.#server = createServer(this.onRequest.bind(this));
|
||||||
this.#server.once('listening', () => Logger.info({ type: 'event:prometheusStart', message: `Prometheus: Listening at http://localhost:${vars.prometheus.port}` }));
|
this.#server.once('listening', () => Logger.info({ type: 'event:prometheusStart', message: `Prometheus: Listening at http://localhost:${vars.prometheus.port}` }));
|
||||||
|
@ -39,6 +44,7 @@ export default class Prometheus {
|
||||||
this.#server.listen(vars.prometheus.port);
|
this.#server.listen(vars.prometheus.port);
|
||||||
}
|
}
|
||||||
private async onRequest(req: IncomingMessage, res: ServerResponse) {
|
private async onRequest(req: IncomingMessage, res: ServerResponse) {
|
||||||
|
this.uptime.set(process.uptime())
|
||||||
if (req.url! === '/metrics') {
|
if (req.url! === '/metrics') {
|
||||||
res.writeHead(200, { 'Content-Type': prom.register.contentType });
|
res.writeHead(200, { 'Content-Type': prom.register.contentType });
|
||||||
res.write(await prom.register.metrics());
|
res.write(await prom.register.metrics());
|
||||||
|
|
Loading…
Reference in a new issue