mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
fix client stats, difference client/player
This commit is contained in:
parent
95fcea086b
commit
cb6fa52eae
@ -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.");
|
||||
|
@ -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 players_connected = IntCounter::with_opts(Opts::new(
|
||||
"players_connected",
|
||||
let clients_connected = IntCounter::with_opts(Opts::new(
|
||||
"clients_connected",
|
||||
"shows the number of clients joined to the server",
|
||||
))?;
|
||||
let players_disconnected = IntCounterVec::new(
|
||||
let players_connected = IntCounter::with_opts(Opts::new(
|
||||
"players_connected",
|
||||
"shows the number of players joined to the server. A player is a client, that \
|
||||
registers itself. Bots are not players (but clients)",
|
||||
))?;
|
||||
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),
|
||||
))
|
||||
|
@ -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…
Reference in New Issue
Block a user