M src/environment.ts => src/environment.ts +1 -1
@@ 7,4 7,4 @@ export const HOST: string = env.HOST ?? '::';
export const PORT: number = parseInt(env.PORT ?? '3001');
export const PRODUCTION: boolean = env.NODE_ENV === 'production';
-export const USER: string = env.USER ?? 'USFN-Orion';>
\ No newline at end of file
+export const USERS: string[] = env.USERS?.split(',') || ['USFN-Orion'];<
\ No newline at end of file
M src/utils/neosApiClient.ts => src/utils/neosApiClient.ts +22 -15
@@ 1,13 1,13 @@
import axios, { AxiosInstance } from 'axios';
import { NeosUserData } from '../types/neosUser';
-import { USER } from '../environment';
+import { USERS } from '../environment';
const neosApiClient = axios.create({
baseURL: 'https://api.neos.com'
});
-const getSessionInfo = async (): Promise<NeosUserData|void> => {
- const res = await neosApiClient.get(`/api/users/U-${USER}/status`).catch((error) => {
+const getSessionInfo = async (user: string): Promise<NeosUserData|void> => {
+ const res = await neosApiClient.get(`/api/users/U-${user}/status`).catch((error) => {
console.error(error);
return;
});
@@ 21,21 21,28 @@ const getSessionInfo = async (): Promise<NeosUserData|void> => {
}
export const generatePrometheusString = async (): Promise<string> => {
- const userData = await getSessionInfo();
+ let totalPlayers: number = 0;
+ const fullPrometheusString = await Promise.all(USERS.map(async (user): Promise<string | undefined> => {
+ const userData = await getSessionInfo(user);
- console.log(userData);
+ if (!userData || userData.onlineStatus !== 'Online' || !userData.activeSessions) {
+ console.log("no sessions found");
+ return;
+ }
- if (!userData || userData.onlineStatus !== 'Online' || !userData.activeSessions) {
- console.log("no sessions found");
- return "";
- }
+ const prometheusString = userData.activeSessions.map((session) => {
+ totalPlayers += session.joinedUsers;
+ return `player_count{label="${session.name}"} ${session.joinedUsers}`;
+ });
- let totalPlayers: number = 0;
+ return prometheusString.join('\n');
+ }));
- const prometheusString = userData.activeSessions.map((session) => {
- totalPlayers += session.joinedUsers;
- return `player_count{label="${session.name}"} ${session.joinedUsers}`;
- });
+ console.log(fullPrometheusString);
+
+ if (!fullPrometheusString) {
+ return `player_count{label="total"} ${totalPlayers}`;
+ }
- return `${prometheusString.join('\n')}\nplayer_count{label="total"} ${totalPlayers}`;
+ return `${fullPrometheusString}\nplayer_count{label="total"} ${totalPlayers}`;
}