diff --git a/packages/app-api/src/lib/metrics.ts b/packages/app-api/src/lib/metrics.ts index 19c38d3c4f..384c8a2439 100644 --- a/packages/app-api/src/lib/metrics.ts +++ b/packages/app-api/src/lib/metrics.ts @@ -1,9 +1,11 @@ import { Gauge, Counter, Pushgateway, Registry } from 'prom-client'; import { config } from '../config.js'; -const pushRegistry = new Registry(); +const playerSyncRegistry = new Registry(); +const kpiRegistry = new Registry(); -export const gateway = new Pushgateway(config.get('metrics.pushgatewayUrl'), {}, pushRegistry); +export const playerSyncGateway = new Pushgateway(config.get('metrics.pushgatewayUrl'), {}, playerSyncRegistry); +export const kpiGateway = new Pushgateway(config.get('metrics.pushgatewayUrl'), {}, kpiRegistry); const metricsPrefix = 'takaro_'; @@ -12,35 +14,35 @@ export const metrics = { domains: new Gauge({ name: `${metricsPrefix}domains`, help: 'Number of domains', - registers: [pushRegistry], + registers: [kpiRegistry], }), gameServers: new Gauge({ name: `${metricsPrefix}gameServers`, help: 'Number of gameServers', labelNames: ['domain'], - registers: [pushRegistry], + registers: [kpiRegistry], }), players: new Gauge({ name: `${metricsPrefix}players`, help: 'Number of players', labelNames: ['domain'], - registers: [pushRegistry], + registers: [kpiRegistry], }), users: new Gauge({ name: `${metricsPrefix}users`, help: 'Number of users', labelNames: ['domain'], - registers: [pushRegistry], + registers: [kpiRegistry], }), installedModules: new Gauge({ name: `${metricsPrefix}installedModules`, help: 'Number of installedModules', labelNames: ['domain', 'gameServer'], - registers: [pushRegistry], + registers: [kpiRegistry], }), // Domain metrics @@ -48,19 +50,19 @@ export const metrics = { name: `${metricsPrefix}player_ping`, help: 'Player ping', labelNames: ['domain', 'player', 'gameserver'], - registers: [pushRegistry], + registers: [playerSyncRegistry], }), players_online: new Gauge({ name: `${metricsPrefix}players_online`, help: 'Players online', labelNames: ['domain', 'gameserver'], - registers: [pushRegistry], + registers: [playerSyncRegistry], }), player_currency: new Gauge({ name: `${metricsPrefix}player_currency`, help: 'Player currency', labelNames: ['domain', 'player', 'gameserver'], - registers: [pushRegistry], + registers: [playerSyncRegistry], }), events: new Counter({ name: `${metricsPrefix}events`, diff --git a/packages/app-api/src/workers/kpiWorker.ts b/packages/app-api/src/workers/kpiWorker.ts index 0e0910e4bc..d01e37e4fc 100644 --- a/packages/app-api/src/workers/kpiWorker.ts +++ b/packages/app-api/src/workers/kpiWorker.ts @@ -6,7 +6,7 @@ import { GameServerService } from '../service/GameServerService.js'; import { PlayerService } from '../service/PlayerService.js'; import { DomainRepo } from '../db/domain.js'; import { UserService } from '../service/UserService.js'; -import { gateway, metrics } from '../lib/metrics.js'; +import { kpiGateway, metrics } from '../lib/metrics.js'; const log = logger('worker:kpi'); @@ -91,5 +91,5 @@ export async function processJob(_job: Job) { metrics.users.set(totals.users); metrics.installedModules.set(totals.installedModules); - await gateway.pushAdd({ jobName: 'playerSync' }); + await kpiGateway.pushAdd({ jobName: 'kpi' }); } diff --git a/packages/app-api/src/workers/playerSyncWorker.ts b/packages/app-api/src/workers/playerSyncWorker.ts index 45901cf236..20b122c45c 100644 --- a/packages/app-api/src/workers/playerSyncWorker.ts +++ b/packages/app-api/src/workers/playerSyncWorker.ts @@ -7,7 +7,7 @@ import { GameServerService } from '../service/GameServerService.js'; import { ctx } from '@takaro/util'; import { PlayerService } from '../service/PlayerService.js'; import { PlayerOnGameServerService, PlayerOnGameServerUpdateDTO } from '../service/PlayerOnGameserverService.js'; -import { gateway, metrics } from '../lib/metrics.js'; +import { playerSyncGateway, metrics } from '../lib/metrics.js'; const log = logger('worker:playerSync'); @@ -139,7 +139,7 @@ export async function processJob(job: Job) { ); const res = await Promise.allSettled(promises); - await gateway.pushAdd({ jobName: 'playerSync' }); + await playerSyncGateway.pushAdd({ jobName: gameServerId }); for (const r of res) { if (r.status === 'rejected') {