mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add metrics for counting server events
This commit is contained in:
parent
2404f111f1
commit
950723dd0d
@ -36,6 +36,9 @@ pub enum LocalEvent {
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)] // TODO: Pending review in #587
|
||||
#[derive(strum::EnumDiscriminants)]
|
||||
#[strum_discriminants(repr(usize))]
|
||||
#[strum_discriminants(derive(strum::EnumVariantNames))]
|
||||
pub enum ServerEvent {
|
||||
Explosion {
|
||||
pos: Vec3<f32>,
|
||||
|
@ -2,7 +2,7 @@ use crate::{
|
||||
events::interaction::handle_tame_pet, persistence::PersistedComponents, state_ext::StateExt,
|
||||
Server,
|
||||
};
|
||||
use common::event::{EventBus, ServerEvent};
|
||||
use common::event::{EventBus, ServerEvent, ServerEventDiscriminants};
|
||||
use common_base::span;
|
||||
use entity_creation::{
|
||||
handle_beam, handle_create_npc, handle_create_ship, handle_create_waypoint,
|
||||
@ -65,7 +65,13 @@ impl Server {
|
||||
.read_resource::<EventBus<ServerEvent>>()
|
||||
.recv_all();
|
||||
|
||||
use strum::VariantNames;
|
||||
let mut event_counts = vec![0u32; ServerEventDiscriminants::VARIANTS.len()];
|
||||
|
||||
for event in events {
|
||||
// Count events by variant for metrics
|
||||
event_counts[ServerEventDiscriminants::from(&event) as usize] += 1;
|
||||
|
||||
match event {
|
||||
ServerEvent::Explosion {
|
||||
pos,
|
||||
@ -270,6 +276,22 @@ impl Server {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let server_event_metrics = self
|
||||
.state
|
||||
.ecs()
|
||||
.read_resource::<crate::metrics::ServerEventMetrics>();
|
||||
event_counts
|
||||
.into_iter()
|
||||
.zip(ServerEventDiscriminants::VARIANTS)
|
||||
.for_each(|(count, event_name)| {
|
||||
server_event_metrics
|
||||
.event_count
|
||||
.with_label_values(&[event_name])
|
||||
.set(i64::from(count));
|
||||
})
|
||||
}
|
||||
|
||||
for (entity, name, args) in commands {
|
||||
self.process_command(entity, name, args);
|
||||
}
|
||||
|
@ -237,6 +237,8 @@ impl Server {
|
||||
let ecs_system_metrics = EcsSystemMetrics::new(®istry).unwrap();
|
||||
let tick_metrics = TickMetrics::new(®istry).unwrap();
|
||||
let physics_metrics = PhysicsMetrics::new(®istry).unwrap();
|
||||
let server_event_metrics = metrics::ServerEventMetrics::new(®istry).unwrap();
|
||||
|
||||
let battlemode_buffer = BattleModeBuffer::default();
|
||||
|
||||
let mut state = State::server();
|
||||
@ -268,6 +270,7 @@ impl Server {
|
||||
state.ecs_mut().insert(ecs_system_metrics);
|
||||
state.ecs_mut().insert(tick_metrics);
|
||||
state.ecs_mut().insert(physics_metrics);
|
||||
state.ecs_mut().insert(server_event_metrics);
|
||||
if settings.experimental_terrain_persistence {
|
||||
#[cfg(feature = "persistent_world")]
|
||||
{
|
||||
|
@ -64,6 +64,10 @@ pub struct TickMetrics {
|
||||
pub light_count: IntGauge,
|
||||
}
|
||||
|
||||
pub struct ServerEventMetrics {
|
||||
pub event_count: IntGaugeVec,
|
||||
}
|
||||
|
||||
impl PhysicsMetrics {
|
||||
pub fn new(registry: &Registry) -> Result<Self, prometheus::Error> {
|
||||
let entity_entity_collision_checks_count = IntCounter::with_opts(Opts::new(
|
||||
@ -398,3 +402,15 @@ impl TickMetrics {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ServerEventMetrics {
|
||||
pub fn new(registry: &Registry) -> Result<Self, Box<dyn Error>> {
|
||||
let event_count = IntGaugeVec::new(
|
||||
Opts::new("event_count", "number of ServerEvents handled this tick"),
|
||||
&["event"],
|
||||
)?;
|
||||
registry.register(Box::new(event_count.clone()))?;
|
||||
|
||||
Ok(Self { event_count })
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user