mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'imbris/event-metrics' into 'master'
Add metrics for counting server events See merge request veloren/veloren!3435
This commit is contained in:
commit
11e71529d5
@ -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])
|
||||
.inc_by(count.into());
|
||||
})
|
||||
}
|
||||
|
||||
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")]
|
||||
{
|
||||
@ -1020,6 +1023,7 @@ impl Server {
|
||||
.duration_since(before_state_tick)
|
||||
.as_secs_f64(),
|
||||
);
|
||||
tick_metrics.tick_count.inc();
|
||||
}
|
||||
|
||||
// 9) Finish the tick, pass control back to the frontend.
|
||||
|
@ -62,6 +62,11 @@ pub struct TickMetrics {
|
||||
pub start_time: IntGauge,
|
||||
pub time_of_day: Gauge,
|
||||
pub light_count: IntGauge,
|
||||
pub tick_count: IntCounter,
|
||||
}
|
||||
|
||||
pub struct ServerEventMetrics {
|
||||
pub event_count: IntCounterVec,
|
||||
}
|
||||
|
||||
impl PhysicsMetrics {
|
||||
@ -367,6 +372,10 @@ impl TickMetrics {
|
||||
)
|
||||
.buckets(bucket),
|
||||
)?;
|
||||
let tick_count = IntCounter::with_opts(Opts::new(
|
||||
"tick_count",
|
||||
"counts the number of ticks that have been processed",
|
||||
))?;
|
||||
|
||||
let since_the_epoch = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
@ -383,6 +392,7 @@ impl TickMetrics {
|
||||
registry.register(Box::new(light_count.clone()))?;
|
||||
registry.register(Box::new(tick_time.clone()))?;
|
||||
registry.register(Box::new(tick_time_hist.clone()))?;
|
||||
registry.register(Box::new(tick_count.clone()))?;
|
||||
|
||||
Ok(Self {
|
||||
chonks_count,
|
||||
@ -395,6 +405,19 @@ impl TickMetrics {
|
||||
start_time,
|
||||
time_of_day,
|
||||
light_count,
|
||||
tick_count,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ServerEventMetrics {
|
||||
pub fn new(registry: &Registry) -> Result<Self, Box<dyn Error>> {
|
||||
let event_count = IntCounterVec::new(
|
||||
Opts::new("event_count", "number of ServerEvents handled"),
|
||||
&["event"],
|
||||
)?;
|
||||
registry.register(Box::new(event_count.clone()))?;
|
||||
|
||||
Ok(Self { event_count })
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user