@@ -5,7 +5,7 @@ use reqwest::{Client, StatusCode};
55use serde:: Serialize ;
66use serde_json:: Value ;
77use sqlx:: { query, PgPool } ;
8- use std:: fs:: read_to_string;
8+ use std:: { fmt :: Write , fs:: read_to_string} ;
99
1010const PROJECT_ID : & str = "p2rxzX0q" ;
1111
@@ -128,6 +128,30 @@ pub async fn get(
128128 Ok ( Json ( data) )
129129}
130130
131+ pub async fn metrics (
132+ State ( ApiState {
133+ database, online_users, ..
134+ } ) : State < ApiState > ,
135+ ) -> Result < String , ApiError > {
136+ let lifetime_players = get_total_players ( & database) . await ?;
137+ let online_players = online_users. len ( ) ;
138+
139+ let mut response = String :: new ( ) ;
140+
141+ #[ rustfmt:: skip]
142+ #[ expect( unused) ]
143+ {
144+ writeln ! ( response, "# This endpoint is intended for internal use with Prometheus. It is not part of the documented stable API and may be" ) ;
145+ writeln ! ( response, "# removed without notice. The `/v1/global_data` endpoint should be preferred, see the following:" ) ;
146+ writeln ! ( response, "# https://github.com/AxolotlClient/AxolotlClient-API/blob/main/docs/api_documentation.md#get-global_data" ) ;
147+ writeln ! ( response, "" ) ;
148+ writeln ! ( response, "lifetime_players {lifetime_players}" ) ;
149+ writeln ! ( response, "online_players {online_players}" ) ;
150+ } ;
151+
152+ Ok ( response)
153+ }
154+
131155async fn get_total_players ( database : & PgPool ) -> Result < u32 , ApiError > {
132156 Ok ( query ! ( "SELECT reltuples AS estimate FROM pg_class where relname = 'players'" )
133157 . fetch_one ( database)
0 commit comments