rename core-server
This commit is contained in:
19
apps/core-server/modules/discord.ts
Normal file
19
apps/core-server/modules/discord.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Client, GatewayIntentBits } from "discord.js";
|
||||
|
||||
const client = new Client({
|
||||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers],
|
||||
});
|
||||
|
||||
const token = process.env.DISCORD_BOT_TOKEN;
|
||||
|
||||
if (!token) {
|
||||
throw new Error("DISCORD_BOT_TOKEN environment variable is not set.");
|
||||
}
|
||||
|
||||
client.login(token);
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log(`Logged in as ${client.user?.tag}`);
|
||||
});
|
||||
|
||||
export default client;
|
||||
36
apps/core-server/modules/prometheus.ts
Normal file
36
apps/core-server/modules/prometheus.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { prisma } from "@repo/db";
|
||||
import promClient from "prom-client";
|
||||
|
||||
export const promRegister = new promClient.Registry();
|
||||
promClient.collectDefaultMetrics({ register: promRegister });
|
||||
|
||||
export const connectedPilots = new promClient.Gauge({
|
||||
name: "connected_pilots",
|
||||
help: "Counts connected pilots",
|
||||
registers: [promRegister],
|
||||
collect: async () => {
|
||||
const count = await prisma.connectedAircraft.count({
|
||||
where: {
|
||||
logoutTime: null,
|
||||
},
|
||||
});
|
||||
connectedPilots.set(count);
|
||||
},
|
||||
});
|
||||
|
||||
export const connectedDispatcher = new promClient.Gauge({
|
||||
name: "connected_dispatcher",
|
||||
help: "Counts connected dispatchers",
|
||||
registers: [promRegister],
|
||||
collect: async () => {
|
||||
const count = await prisma.connectedDispatcher.count({
|
||||
where: {
|
||||
logoutTime: null,
|
||||
},
|
||||
});
|
||||
connectedDispatcher.set(count);
|
||||
},
|
||||
});
|
||||
|
||||
promRegister.registerMetric(connectedPilots);
|
||||
promRegister.registerMetric(connectedDispatcher);
|
||||
Reference in New Issue
Block a user