2020-09-13 16:26:50 +00:00
|
|
|
|
use prometheus::{
|
2021-03-26 11:41:22 +00:00
|
|
|
|
Gauge, GaugeVec, Histogram, HistogramOpts, HistogramVec, IntCounter, IntCounterVec, IntGauge,
|
|
|
|
|
IntGaugeVec, Opts, Registry,
|
2020-09-13 16:26:50 +00:00
|
|
|
|
};
|
2019-09-10 13:22:34 +00:00
|
|
|
|
use std::{
|
|
|
|
|
convert::TryInto,
|
2020-02-01 20:39:39 +00:00
|
|
|
|
error::Error,
|
2019-09-20 04:41:44 +00:00
|
|
|
|
time::{Duration, SystemTime, UNIX_EPOCH},
|
2019-09-10 13:22:34 +00:00
|
|
|
|
};
|
2019-09-06 14:21:09 +00:00
|
|
|
|
|
2020-10-20 16:31:19 +00:00
|
|
|
|
pub struct PhysicsMetrics {
|
|
|
|
|
pub entity_entity_collision_checks_count: IntCounter,
|
|
|
|
|
pub entity_entity_collisions_count: IntCounter,
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 08:36:53 +00:00
|
|
|
|
pub struct EcsSystemMetrics {
|
|
|
|
|
// Gauges give us detailed information for random ticks
|
|
|
|
|
pub system_start_time: IntGaugeVec,
|
|
|
|
|
pub system_length_time: IntGaugeVec,
|
|
|
|
|
pub system_thread_avg: GaugeVec,
|
|
|
|
|
// Counter will only give us granularity on pool speed (2s?) for actual spike detection we
|
2020-09-14 12:56:05 +00:00
|
|
|
|
// need the Historgram
|
2021-03-08 08:36:53 +00:00
|
|
|
|
pub system_length_hist: HistogramVec,
|
|
|
|
|
pub system_length_count: IntCounterVec,
|
2020-09-14 12:56:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-13 16:26:50 +00:00
|
|
|
|
pub struct PlayerMetrics {
|
2020-09-16 22:19:48 +00:00
|
|
|
|
pub clients_connected: IntCounter,
|
2020-09-13 16:26:50 +00:00
|
|
|
|
pub players_connected: IntCounter,
|
2020-09-16 22:19:48 +00:00
|
|
|
|
pub clients_disconnected: IntCounterVec, // timeout, network_error, gracefully
|
2020-09-13 16:26:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct NetworkRequestMetrics {
|
|
|
|
|
pub chunks_request_dropped: IntCounter,
|
2020-09-14 12:56:05 +00:00
|
|
|
|
pub chunks_served_from_memory: IntCounter,
|
2020-09-13 16:26:50 +00:00
|
|
|
|
pub chunks_generation_triggered: IntCounter,
|
2021-04-28 15:36:07 +00:00
|
|
|
|
pub chunks_served_lo_bandwidth: IntCounter,
|
|
|
|
|
pub chunks_served_hi_bandwidth: IntCounter,
|
2020-09-13 16:26:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct ChunkGenMetrics {
|
|
|
|
|
pub chunks_requested: IntCounter,
|
|
|
|
|
pub chunks_served: IntCounter,
|
|
|
|
|
pub chunks_canceled: IntCounter,
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-19 17:08:57 +00:00
|
|
|
|
pub struct TickMetrics {
|
2019-09-09 08:46:58 +00:00
|
|
|
|
pub chonks_count: IntGauge,
|
|
|
|
|
pub chunks_count: IntGauge,
|
2020-09-28 11:35:49 +00:00
|
|
|
|
pub chunk_groups_count: IntGauge,
|
2019-09-07 13:10:57 +00:00
|
|
|
|
pub entity_count: IntGauge,
|
|
|
|
|
pub tick_time: IntGaugeVec,
|
2021-03-26 11:41:22 +00:00
|
|
|
|
pub tick_time_hist: Histogram,
|
2019-09-07 13:10:57 +00:00
|
|
|
|
pub build_info: IntGauge,
|
2019-09-10 13:22:34 +00:00
|
|
|
|
pub start_time: IntGauge,
|
|
|
|
|
pub time_of_day: Gauge,
|
2019-09-07 13:10:57 +00:00
|
|
|
|
pub light_count: IntGauge,
|
2020-02-19 17:08:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-20 16:31:19 +00:00
|
|
|
|
impl PhysicsMetrics {
|
2021-03-08 08:49:16 +00:00
|
|
|
|
pub fn new(registry: &Registry) -> Result<Self, prometheus::Error> {
|
2020-10-20 16:31:19 +00:00
|
|
|
|
let entity_entity_collision_checks_count = IntCounter::with_opts(Opts::new(
|
|
|
|
|
"entity_entity_collision_checks_count",
|
|
|
|
|
"shows the number of collision checks",
|
|
|
|
|
))?;
|
|
|
|
|
let entity_entity_collisions_count = IntCounter::with_opts(Opts::new(
|
|
|
|
|
"entity_entity_collisions_count",
|
|
|
|
|
"shows the number of actual collisions detected",
|
|
|
|
|
))?;
|
|
|
|
|
|
2021-03-08 08:49:16 +00:00
|
|
|
|
registry.register(Box::new(entity_entity_collision_checks_count.clone()))?;
|
|
|
|
|
registry.register(Box::new(entity_entity_collisions_count.clone()))?;
|
2020-10-20 16:31:19 +00:00
|
|
|
|
|
2021-03-08 08:49:16 +00:00
|
|
|
|
Ok(Self {
|
|
|
|
|
entity_entity_collision_checks_count,
|
|
|
|
|
entity_entity_collisions_count,
|
|
|
|
|
})
|
2020-10-20 16:31:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 08:36:53 +00:00
|
|
|
|
impl EcsSystemMetrics {
|
2021-03-08 08:49:16 +00:00
|
|
|
|
pub fn new(registry: &Registry) -> Result<Self, prometheus::Error> {
|
2020-09-14 12:56:05 +00:00
|
|
|
|
let bucket = vec![
|
|
|
|
|
Duration::from_micros(1).as_secs_f64(),
|
|
|
|
|
Duration::from_micros(10).as_secs_f64(),
|
|
|
|
|
Duration::from_micros(100).as_secs_f64(),
|
|
|
|
|
Duration::from_micros(200).as_secs_f64(),
|
|
|
|
|
Duration::from_micros(400).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(2).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(5).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(10).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(20).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(30).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(50).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(100).as_secs_f64(),
|
|
|
|
|
];
|
2021-03-08 08:36:53 +00:00
|
|
|
|
let system_length_hist = HistogramVec::new(
|
2020-09-14 12:56:05 +00:00
|
|
|
|
HistogramOpts::new(
|
2021-03-08 08:55:35 +00:00
|
|
|
|
"system_length_hist",
|
|
|
|
|
"shows the detailed time in ns inside each ECS system as histogram",
|
2020-09-14 12:56:05 +00:00
|
|
|
|
)
|
|
|
|
|
.buckets(bucket),
|
|
|
|
|
&["system"],
|
|
|
|
|
)?;
|
2021-03-08 08:36:53 +00:00
|
|
|
|
let system_length_count = IntCounterVec::new(
|
2020-09-14 12:56:05 +00:00
|
|
|
|
Opts::new(
|
2021-03-08 08:55:35 +00:00
|
|
|
|
"system_length_count",
|
|
|
|
|
"shows the detailed time in ns inside each ECS system",
|
2020-09-14 12:56:05 +00:00
|
|
|
|
),
|
|
|
|
|
&["system"],
|
|
|
|
|
)?;
|
2021-03-08 08:36:53 +00:00
|
|
|
|
let system_start_time = IntGaugeVec::new(
|
|
|
|
|
Opts::new(
|
|
|
|
|
"system_start_time",
|
|
|
|
|
"start relative to tick start in ns required per ECS system",
|
|
|
|
|
),
|
|
|
|
|
&["system"],
|
|
|
|
|
)?;
|
|
|
|
|
let system_length_time = IntGaugeVec::new(
|
|
|
|
|
Opts::new("system_length_time", "time in ns required per ECS system"),
|
|
|
|
|
&["system"],
|
|
|
|
|
)?;
|
|
|
|
|
let system_thread_avg = GaugeVec::new(
|
|
|
|
|
Opts::new(
|
|
|
|
|
"system_thread_avg",
|
|
|
|
|
"average threads used by the ECS system",
|
|
|
|
|
),
|
|
|
|
|
&["system"],
|
|
|
|
|
)?;
|
2020-09-14 12:56:05 +00:00
|
|
|
|
|
2021-03-08 08:49:16 +00:00
|
|
|
|
registry.register(Box::new(system_start_time.clone()))?;
|
|
|
|
|
registry.register(Box::new(system_length_time.clone()))?;
|
|
|
|
|
registry.register(Box::new(system_thread_avg.clone()))?;
|
2021-03-12 11:10:42 +00:00
|
|
|
|
registry.register(Box::new(system_length_hist.clone()))?;
|
|
|
|
|
registry.register(Box::new(system_length_count.clone()))?;
|
2021-03-08 08:49:16 +00:00
|
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
|
system_start_time,
|
|
|
|
|
system_length_time,
|
|
|
|
|
system_thread_avg,
|
2021-03-12 11:10:42 +00:00
|
|
|
|
system_length_hist,
|
|
|
|
|
system_length_count,
|
2021-03-08 08:49:16 +00:00
|
|
|
|
})
|
2020-09-14 12:56:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-13 16:26:50 +00:00
|
|
|
|
impl PlayerMetrics {
|
2021-03-08 08:49:16 +00:00
|
|
|
|
pub fn new(registry: &Registry) -> Result<Self, prometheus::Error> {
|
2020-09-16 22:19:48 +00:00
|
|
|
|
let clients_connected = IntCounter::with_opts(Opts::new(
|
|
|
|
|
"clients_connected",
|
|
|
|
|
"shows the number of clients joined to the server",
|
|
|
|
|
))?;
|
2020-09-13 16:26:50 +00:00
|
|
|
|
let players_connected = IntCounter::with_opts(Opts::new(
|
|
|
|
|
"players_connected",
|
2020-09-16 22:19:48 +00:00
|
|
|
|
"shows the number of players joined to the server. A player is a client, that \
|
|
|
|
|
registers itself. Bots are not players (but clients)",
|
2020-09-13 16:26:50 +00:00
|
|
|
|
))?;
|
2020-09-16 22:19:48 +00:00
|
|
|
|
let clients_disconnected = IntCounterVec::new(
|
2020-09-13 16:26:50 +00:00
|
|
|
|
Opts::new(
|
2020-09-16 22:19:48 +00:00
|
|
|
|
"clients_disconnected",
|
2020-09-13 16:26:50 +00:00
|
|
|
|
"shows the number of clients disconnected from the server and the reason",
|
|
|
|
|
),
|
|
|
|
|
&["reason"],
|
|
|
|
|
)?;
|
|
|
|
|
|
2021-03-08 08:49:16 +00:00
|
|
|
|
registry.register(Box::new(clients_connected.clone()))?;
|
|
|
|
|
registry.register(Box::new(players_connected.clone()))?;
|
|
|
|
|
registry.register(Box::new(clients_disconnected.clone()))?;
|
2020-09-13 16:26:50 +00:00
|
|
|
|
|
2021-03-08 08:49:16 +00:00
|
|
|
|
Ok(Self {
|
|
|
|
|
clients_connected,
|
|
|
|
|
players_connected,
|
|
|
|
|
clients_disconnected,
|
|
|
|
|
})
|
2020-09-13 16:26:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NetworkRequestMetrics {
|
2021-03-08 08:49:16 +00:00
|
|
|
|
pub fn new(registry: &Registry) -> Result<Self, prometheus::Error> {
|
2020-09-13 16:26:50 +00:00
|
|
|
|
let chunks_request_dropped = IntCounter::with_opts(Opts::new(
|
|
|
|
|
"chunks_request_dropped",
|
|
|
|
|
"number of all chunk request dropped, e.g because the player was to far away",
|
|
|
|
|
))?;
|
2020-09-14 12:56:05 +00:00
|
|
|
|
let chunks_served_from_memory = IntCounter::with_opts(Opts::new(
|
|
|
|
|
"chunks_served_from_memory",
|
2020-09-13 16:26:50 +00:00
|
|
|
|
"number of all requested chunks already generated and could be served out of cache",
|
|
|
|
|
))?;
|
|
|
|
|
let chunks_generation_triggered = IntCounter::with_opts(Opts::new(
|
|
|
|
|
"chunks_generation_triggered",
|
|
|
|
|
"number of all chunks that were requested and needs to be generated",
|
|
|
|
|
))?;
|
2021-04-28 15:36:07 +00:00
|
|
|
|
let chunks_served_lo_bandwidth = IntCounter::with_opts(Opts::new(
|
|
|
|
|
"chunks_served_lo_bandwidth",
|
|
|
|
|
"number of chunks that were sent with compression setting by the low bandwidth \
|
|
|
|
|
heuristic",
|
|
|
|
|
))?;
|
|
|
|
|
let chunks_served_hi_bandwidth = IntCounter::with_opts(Opts::new(
|
|
|
|
|
"chunks_served_hi_bandwidth",
|
|
|
|
|
"number of chunks that were sent with compression setting by the high bandwidth \
|
|
|
|
|
heuristic",
|
|
|
|
|
))?;
|
2020-09-13 16:26:50 +00:00
|
|
|
|
|
2021-03-08 08:49:16 +00:00
|
|
|
|
registry.register(Box::new(chunks_request_dropped.clone()))?;
|
|
|
|
|
registry.register(Box::new(chunks_served_from_memory.clone()))?;
|
|
|
|
|
registry.register(Box::new(chunks_generation_triggered.clone()))?;
|
2021-04-28 15:36:07 +00:00
|
|
|
|
registry.register(Box::new(chunks_served_lo_bandwidth.clone()))?;
|
|
|
|
|
registry.register(Box::new(chunks_served_hi_bandwidth.clone()))?;
|
2020-09-13 16:26:50 +00:00
|
|
|
|
|
2021-03-08 08:49:16 +00:00
|
|
|
|
Ok(Self {
|
|
|
|
|
chunks_request_dropped,
|
|
|
|
|
chunks_served_from_memory,
|
|
|
|
|
chunks_generation_triggered,
|
2021-04-28 15:36:07 +00:00
|
|
|
|
chunks_served_lo_bandwidth,
|
|
|
|
|
chunks_served_hi_bandwidth,
|
2021-03-08 08:49:16 +00:00
|
|
|
|
})
|
2020-09-13 16:26:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ChunkGenMetrics {
|
2021-03-08 08:49:16 +00:00
|
|
|
|
pub fn new(registry: &Registry) -> Result<Self, prometheus::Error> {
|
2020-09-13 16:26:50 +00:00
|
|
|
|
let chunks_requested = IntCounter::with_opts(Opts::new(
|
|
|
|
|
"chunks_requested",
|
|
|
|
|
"number of all chunks requested on the server",
|
|
|
|
|
))?;
|
|
|
|
|
let chunks_served = IntCounter::with_opts(Opts::new(
|
|
|
|
|
"chunks_served",
|
|
|
|
|
"number of all requested chunks already served on the server",
|
|
|
|
|
))?;
|
|
|
|
|
let chunks_canceled = IntCounter::with_opts(Opts::new(
|
|
|
|
|
"chunks_canceled",
|
|
|
|
|
"number of all canceled chunks on the server",
|
|
|
|
|
))?;
|
|
|
|
|
|
2021-03-08 08:49:16 +00:00
|
|
|
|
registry.register(Box::new(chunks_requested.clone()))?;
|
|
|
|
|
registry.register(Box::new(chunks_served.clone()))?;
|
|
|
|
|
registry.register(Box::new(chunks_canceled.clone()))?;
|
2020-09-13 16:26:50 +00:00
|
|
|
|
|
2021-03-08 08:49:16 +00:00
|
|
|
|
Ok(Self {
|
|
|
|
|
chunks_requested,
|
|
|
|
|
chunks_served,
|
|
|
|
|
chunks_canceled,
|
|
|
|
|
})
|
2020-09-13 16:26:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-19 17:08:57 +00:00
|
|
|
|
impl TickMetrics {
|
2021-03-08 08:49:16 +00:00
|
|
|
|
pub fn new(registry: &Registry) -> Result<Self, Box<dyn Error>> {
|
2020-09-13 16:26:50 +00:00
|
|
|
|
let chonks_count = IntGauge::with_opts(Opts::new(
|
|
|
|
|
"chonks_count",
|
|
|
|
|
"number of all chonks currently active on the server",
|
|
|
|
|
))?;
|
|
|
|
|
let chunks_count = IntGauge::with_opts(Opts::new(
|
|
|
|
|
"chunks_count",
|
|
|
|
|
"number of all chunks currently active on the server",
|
2020-02-19 17:08:57 +00:00
|
|
|
|
))?;
|
2020-09-28 11:35:49 +00:00
|
|
|
|
let chunk_groups_count = IntGauge::with_opts(Opts::new(
|
|
|
|
|
"chunk_groups_count",
|
|
|
|
|
"number of 4×4×4 groups currently allocated by chunks on the server",
|
|
|
|
|
))?;
|
2020-02-19 17:08:57 +00:00
|
|
|
|
let entity_count = IntGauge::with_opts(Opts::new(
|
2019-09-07 13:10:57 +00:00
|
|
|
|
"entity_count",
|
|
|
|
|
"number of all entities currently active on the server",
|
2020-02-19 17:08:57 +00:00
|
|
|
|
))?;
|
2019-09-06 14:21:09 +00:00
|
|
|
|
let opts = Opts::new("veloren_build_info", "Build information")
|
2020-11-06 13:14:54 +00:00
|
|
|
|
.const_label("hash", *common::util::GIT_HASH)
|
2019-09-06 14:21:09 +00:00
|
|
|
|
.const_label("version", "");
|
2019-10-23 16:38:09 +00:00
|
|
|
|
let build_info = IntGauge::with_opts(opts)?;
|
2020-02-19 17:08:57 +00:00
|
|
|
|
let start_time = IntGauge::with_opts(Opts::new(
|
2019-09-10 13:22:34 +00:00
|
|
|
|
"veloren_start_time",
|
|
|
|
|
"start time of the server in seconds since EPOCH",
|
2020-02-19 17:08:57 +00:00
|
|
|
|
))?;
|
|
|
|
|
let time_of_day =
|
|
|
|
|
Gauge::with_opts(Opts::new("time_of_day", "ingame time in ingame-seconds"))?;
|
|
|
|
|
let light_count = IntGauge::with_opts(Opts::new(
|
2019-09-07 13:10:57 +00:00
|
|
|
|
"light_count",
|
|
|
|
|
"number of all lights currently active on the server",
|
2020-02-19 17:08:57 +00:00
|
|
|
|
))?;
|
2020-07-13 19:57:13 +00:00
|
|
|
|
let tick_time = IntGaugeVec::new(
|
2020-08-25 12:21:25 +00:00
|
|
|
|
Opts::new("tick_time", "time in ns required for a tick of the server"),
|
2019-09-07 13:10:57 +00:00
|
|
|
|
&["period"],
|
2020-07-13 19:57:13 +00:00
|
|
|
|
)?;
|
2021-03-26 11:41:22 +00:00
|
|
|
|
// 33.33ms is the ideal tick time. So we have hight detail around it.
|
|
|
|
|
// 300/700 are to detect high I/O blocks
|
|
|
|
|
let bucket = vec![
|
|
|
|
|
Duration::from_millis(8).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(16).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(24).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(30).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(33).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(37).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(45).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(60).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(100).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(300).as_secs_f64(),
|
|
|
|
|
Duration::from_millis(700).as_secs_f64(),
|
|
|
|
|
];
|
|
|
|
|
let tick_time_hist = Histogram::with_opts(
|
|
|
|
|
HistogramOpts::new(
|
|
|
|
|
"tick_time_hist",
|
|
|
|
|
"shows the detailed time in ns spend for the whole tick as histogram",
|
|
|
|
|
)
|
|
|
|
|
.buckets(bucket),
|
|
|
|
|
)?;
|
2019-09-06 14:21:09 +00:00
|
|
|
|
|
2019-09-10 13:22:34 +00:00
|
|
|
|
let since_the_epoch = SystemTime::now()
|
|
|
|
|
.duration_since(UNIX_EPOCH)
|
|
|
|
|
.expect("Time went backwards");
|
2019-10-23 16:38:09 +00:00
|
|
|
|
start_time.set(since_the_epoch.as_secs().try_into()?);
|
2019-09-10 13:22:34 +00:00
|
|
|
|
|
2021-03-08 08:49:16 +00:00
|
|
|
|
registry.register(Box::new(chonks_count.clone()))?;
|
|
|
|
|
registry.register(Box::new(chunks_count.clone()))?;
|
|
|
|
|
registry.register(Box::new(chunk_groups_count.clone()))?;
|
|
|
|
|
registry.register(Box::new(entity_count.clone()))?;
|
|
|
|
|
registry.register(Box::new(build_info.clone()))?;
|
|
|
|
|
registry.register(Box::new(start_time.clone()))?;
|
|
|
|
|
registry.register(Box::new(time_of_day.clone()))?;
|
|
|
|
|
registry.register(Box::new(light_count.clone()))?;
|
|
|
|
|
registry.register(Box::new(tick_time.clone()))?;
|
2021-03-26 11:41:22 +00:00
|
|
|
|
registry.register(Box::new(tick_time_hist.clone()))?;
|
2021-03-08 08:49:16 +00:00
|
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
|
chonks_count,
|
|
|
|
|
chunks_count,
|
|
|
|
|
chunk_groups_count,
|
|
|
|
|
entity_count,
|
|
|
|
|
tick_time,
|
2021-03-26 11:41:22 +00:00
|
|
|
|
tick_time_hist,
|
2021-03-08 08:49:16 +00:00
|
|
|
|
build_info,
|
|
|
|
|
start_time,
|
|
|
|
|
time_of_day,
|
|
|
|
|
light_count,
|
|
|
|
|
})
|
2020-08-18 17:03:43 +00:00
|
|
|
|
}
|
2019-09-07 13:10:57 +00:00
|
|
|
|
}
|