-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(metrics): add additional spell metrics
- Loading branch information
Showing
9 changed files
with
115 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use crate::register; | ||
use prometheus_client::metrics::counter::Counter; | ||
use prometheus_client::metrics::gauge::Gauge; | ||
use prometheus_client::metrics::histogram::Histogram; | ||
use prometheus_client::registry::Registry; | ||
|
||
#[derive(Clone)] | ||
pub struct SpellMetrics { | ||
// How much spell _particles_ were created by the node | ||
spell_particles_created: Counter, | ||
// How much spells are scheduled to run _now_ | ||
spell_scheduled_now: Gauge, | ||
// Distribution of spell's scheduled periods | ||
spell_periods: Histogram, | ||
} | ||
|
||
impl SpellMetrics { | ||
pub fn new(registry: &mut Registry) -> Self { | ||
let sub_registry = registry.sub_registry_with_prefix("spell"); | ||
|
||
let spell_particles_created = register( | ||
sub_registry, | ||
Counter::default(), | ||
"particles_created", | ||
"Number of spell particles created", | ||
); | ||
|
||
let spell_scheduled_now = register( | ||
sub_registry, | ||
Gauge::default(), | ||
"scheduled_now", | ||
"Number of spell particles scheduled to run now", | ||
); | ||
|
||
let spell_periods = register( | ||
sub_registry, | ||
Histogram::new(Self::periods_buckets()), | ||
"periods", | ||
"Spell particle periods", | ||
); | ||
|
||
Self { | ||
spell_particles_created, | ||
spell_scheduled_now, | ||
spell_periods, | ||
} | ||
} | ||
|
||
fn periods_buckets() -> std::vec::IntoIter<f64> { | ||
// 0.0 sec, 1 sec, 30 sec, 1 min, 5 min, 10 min, 1 hour, 12 hours, 1 day, 1 week, 1 month | ||
// 0 means that the spell is oneshot or reacts only on events | ||
vec![ | ||
0.0, | ||
1.0, | ||
30.0, | ||
60.0, | ||
60.0 * 5.0, | ||
60.0 * 10.0, | ||
60.0 * 60.0, | ||
60.0 * 60.0 * 12.0, | ||
60.0 * 60.0 * 24.0, | ||
60.0 * 60.0 * 24.0 * 7.0, | ||
60.0 * 60.0 * 24.0 * 30.0, | ||
] | ||
.into_iter() | ||
} | ||
|
||
pub fn observe_started_spell(&self, period: u32) { | ||
self.spell_scheduled_now.inc(); | ||
self.spell_periods.observe(period as f64) | ||
} | ||
|
||
pub fn observe_finished_spell(&self) { | ||
self.spell_scheduled_now.dec(); | ||
} | ||
|
||
pub fn observe_spell_cast(&self) { | ||
self.spell_particles_created.inc(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters