-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
112 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import promClient, { Counter } from 'prom-client'; | ||
import { promAgent } from './promAgent'; | ||
|
||
interface CounterConfig { | ||
name: string; | ||
help: string; | ||
labelNames?: string[]; | ||
} | ||
|
||
export class PromMetricCounter { | ||
private counter: Counter; | ||
private labelNames: string[]; | ||
|
||
constructor(counterConfig: CounterConfig) { | ||
promAgent.registerMetric(counterConfig.name); | ||
|
||
this.counter = new promClient.Counter(counterConfig); | ||
this.labelNames = counterConfig.labelNames; | ||
} | ||
|
||
public inc(num: number, labels?: Record<string, string>) { | ||
if (labels) { | ||
this.validateLabels(labels); | ||
this.counter.inc(labels, num); | ||
} else { | ||
this.counter.inc(num); | ||
} | ||
} | ||
|
||
private validateLabels(labels: Record<string, string>) { | ||
const invalidLabels = Object.keys(labels).filter( | ||
(label) => !this.labelNames.includes(label), | ||
); | ||
|
||
if (invalidLabels.length > 0) { | ||
throw new Error(`Invalid labels provided: ${invalidLabels.join(', ')}.`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { PromMetricCounter } from '../clients/victoriaMetrics/promMetricCounter'; | ||
|
||
export const gamesPlayedMetric = new PromMetricCounter({ | ||
name: 'games_played_total', | ||
help: 'test', | ||
labelNames: ['status'], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { allSockets } from '../sockets/sockets'; | ||
import { PromMetricGauge } from '../clients/victoriaMetrics/promMetricGauge'; | ||
import { PromMetricCounter } from '../clients/victoriaMetrics/promMetricCounter'; | ||
|
||
const onlinePlayersMetric = new PromMetricGauge({ | ||
name: `online_players_total`, | ||
help: `Number of online players.`, | ||
collect() { | ||
this.set(allSockets.length); | ||
}, | ||
}); | ||
|
||
export const uniqueLoginsMetric = new PromMetricCounter({ | ||
name: 'unique_logins_total', | ||
help: 'Total number of unique logins over a 24h time period.', | ||
}); | ||
|
||
export const avatarSubmissionsMetric = new PromMetricCounter({ | ||
name: `custom_avatar_submissions_total`, | ||
help: `Total number of custom avatars submitted/rejected/approved.`, | ||
labelNames: ['status'], | ||
}); | ||
|
||
export const passwordResetRequestsMetric = new PromMetricCounter({ | ||
name: `password_reset_requests_total`, | ||
help: `Total number of password reset emails sent out.`, | ||
}); | ||
|
||
export const passwordResetCompletedMetric = new PromMetricCounter({ | ||
name: `password_resets_completed_total`, | ||
help: `Total number of password resets completed.`, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters