Browse Source

Merge branch 'fix_metrics' into 'master'

fix client stats, difference client/player

See merge request veloren/veloren!1387
merge-requests/1393/head
Marcel 1 month ago
parent
commit
74caa01185
3 changed files with 25 additions and 11 deletions
  1. +5
    -0
      server/src/lib.rs
  2. +16
    -7
      server/src/metrics.rs
  3. +4
    -4
      server/src/sys/message.rs

+ 5
- 0
server/src/lib.rs View File

@@ -801,6 +801,11 @@ impl Server {
.create_entity_synced()
.with(client)
.build();
self.state
.ecs()
.read_resource::<metrics::PlayerMetrics>()
.clients_connected
.inc();
// Send client all the tracked components currently attached to its entity as
// well as synced resources (currently only `TimeOfDay`)
debug!("Starting initial sync with client.");


+ 16
- 7
server/src/metrics.rs View File

@@ -25,8 +25,9 @@ pub struct StateTickMetrics {
}

pub struct PlayerMetrics {
pub clients_connected: IntCounter,
pub players_connected: IntCounter,
pub players_disconnected: IntCounterVec, // timeout, network_error, gracefully
pub clients_disconnected: IntCounterVec, // timeout, network_error, gracefully
}

pub struct NetworkRequestMetrics {
@@ -113,31 +114,39 @@ impl StateTickMetrics {

impl PlayerMetrics {
pub fn new() -> Result<(Self, RegistryFn), prometheus::Error> {
let clients_connected = IntCounter::with_opts(Opts::new(
"clients_connected",
"shows the number of clients joined to the server",
))?;
let players_connected = IntCounter::with_opts(Opts::new(
"players_connected",
"shows the number of clients joined to the server",
"shows the number of players joined to the server. A player is a client, that \
registers itself. Bots are not players (but clients)",
))?;
let players_disconnected = IntCounterVec::new(
let clients_disconnected = IntCounterVec::new(
Opts::new(
"players_disconnected",
"clients_disconnected",
"shows the number of clients disconnected from the server and the reason",
),
&["reason"],
)?;

let clients_connected_clone = clients_connected.clone();
let players_connected_clone = players_connected.clone();
let players_disconnected_clone = players_disconnected.clone();
let clients_disconnected_clone = clients_disconnected.clone();

let f = |registry: &Registry| {
registry.register(Box::new(clients_connected_clone))?;
registry.register(Box::new(players_connected_clone))?;
registry.register(Box::new(players_disconnected_clone))?;
registry.register(Box::new(clients_disconnected_clone))?;
Ok(())
};

Ok((
Self {
clients_connected,
players_connected,
players_disconnected,
clients_disconnected,
},
Box::new(f),
))


+ 4
- 4
server/src/sys/message.rs View File

@@ -122,6 +122,7 @@ impl Sys {
ClientState::Connected => {
// Add Player component to this client
let _ = players.insert(entity, player);
player_metrics.players_connected.inc();

// Give the Admin component to the player if their name exists in
// admin list
@@ -139,7 +140,6 @@ impl Sys {

// Add to list to notify all clients of the new player
new_players.push(entity);
player_metrics.players_connected.inc();
},
// Use RequestState instead (No need to send `player` again).
_ => client.error_state(RequestStateError::Impossible),
@@ -364,7 +364,7 @@ impl Sys {
ClientMsg::Terminate => {
debug!(?entity, "Client send message to termitate session");
player_metrics
.players_disconnected
.clients_disconnected
.with_label_values(&["gracefully"])
.inc();
server_emitter.emit(ServerEvent::ClientDisconnect(entity));
@@ -556,7 +556,7 @@ impl<'a> System<'a> for Sys {
{
info!(?entity, "timeout error with client, disconnecting");
player_metrics
.players_disconnected
.clients_disconnected
.with_label_values(&["timeout"])
.inc();
server_emitter.emit(ServerEvent::ClientDisconnect(entity));
@@ -565,7 +565,7 @@ impl<'a> System<'a> for Sys {
{
debug!(?entity, "postbox error with client, disconnecting");
player_metrics
.players_disconnected
.clients_disconnected
.with_label_values(&["network_error"])
.inc();
server_emitter.emit(ServerEvent::ClientDisconnect(entity));


Loading…
Cancel
Save