-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathmetrics.rs
More file actions
76 lines (70 loc) · 2.21 KB
/
metrics.rs
File metadata and controls
76 lines (70 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use serde::Serialize;
use torrust_clock::DurationSinceUnixEpoch;
use torrust_metrics::label::LabelSet;
use torrust_metrics::metric::MetricName;
use torrust_metrics::metric_collection::{Error, MetricCollection};
/// Metrics collected by the torrent repository.
#[derive(Debug, Clone, PartialEq, Default, Serialize)]
pub struct Metrics {
/// A collection of metrics.
pub metric_collection: MetricCollection,
}
impl Metrics {
/// # Errors
///
/// Returns an error if the metric does not exist and it cannot be created.
pub fn increment_counter(
&mut self,
metric_name: &MetricName,
labels: &LabelSet,
now: DurationSinceUnixEpoch,
) -> Result<(), Error> {
self.metric_collection.increment_counter(metric_name, labels, now)
}
/// # Errors
///
/// Returns an error if the metric does not exist and it cannot be created.
pub fn set_counter(
&mut self,
metric_name: &MetricName,
labels: &LabelSet,
value: u64,
now: DurationSinceUnixEpoch,
) -> Result<(), Error> {
self.metric_collection.set_counter(metric_name, labels, value, now)
}
/// # Errors
///
/// Returns an error if the metric does not exist and it cannot be created.
pub fn set_gauge(
&mut self,
metric_name: &MetricName,
labels: &LabelSet,
value: f64,
now: DurationSinceUnixEpoch,
) -> Result<(), Error> {
self.metric_collection.set_gauge(metric_name, labels, value, now)
}
/// # Errors
///
/// Returns an error if the metric does not exist and it cannot be created.
pub fn increment_gauge(
&mut self,
metric_name: &MetricName,
labels: &LabelSet,
now: DurationSinceUnixEpoch,
) -> Result<(), Error> {
self.metric_collection.increment_gauge(metric_name, labels, now)
}
/// # Errors
///
/// Returns an error if the metric does not exist and it cannot be created.
pub fn decrement_gauge(
&mut self,
metric_name: &MetricName,
labels: &LabelSet,
now: DurationSinceUnixEpoch,
) -> Result<(), Error> {
self.metric_collection.decrement_gauge(metric_name, labels, now)
}
}