-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmetrics.rs
More file actions
129 lines (129 loc) · 4.64 KB
/
metrics.rs
File metadata and controls
129 lines (129 loc) · 4.64 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
use metrics::Counter;
use metrics_derive::Metrics;
fn main() {
let metrics = MeteredReceiverMetrics::new("txpool.total-txs");
metrics.messages_received_total.increment(1);
{
::std::io::_print(format_args!("{0:?}\n", metrics.messages_received_total));
};
}
#[metrics(dynamic = true)]
struct MeteredReceiverMetrics {
/// Number of messages received
messages_received_total: Counter,
}
#[automatically_derived]
impl ::core::clone::Clone for MeteredReceiverMetrics {
#[inline]
fn clone(&self) -> MeteredReceiverMetrics {
MeteredReceiverMetrics {
messages_received_total: ::core::clone::Clone::clone(
&self.messages_received_total,
),
}
}
}
impl MeteredReceiverMetrics {
/// Create new instance of metrics with provided scope.
fn new(scope: &str) -> Self {
MeteredReceiverMetrics::describe(scope);
Self {
messages_received_total: {
let metric_key = ::metrics::Key::from_name(
::alloc::__export::must_use({
let res = ::alloc::fmt::format(
format_args!(
"{0}{1}{2}",
scope,
".",
"messages_received_total",
),
);
res
}),
);
let metadata = {
static METADATA: ::metrics::Metadata<'static> = ::metrics::Metadata::new(
"metrics",
::metrics::Level::INFO,
::core::option::Option::Some("metrics"),
);
&METADATA
};
::metrics::with_recorder(|recorder| {
recorder.register_counter(&metric_key, metadata)
})
},
}
}
/// Create new instance of metrics with provided labels.
fn new_with_labels(scope: &str, labels: impl metrics::IntoLabels + Clone) -> Self {
Self {
messages_received_total: {
let metric_key = ::metrics::Key::from_parts(
::alloc::__export::must_use({
let res = ::alloc::fmt::format(
format_args!(
"{0}{1}{2}",
scope,
".",
"messages_received_total",
),
);
res
}),
labels.clone(),
);
let metadata = {
static METADATA: ::metrics::Metadata<'static> = ::metrics::Metadata::new(
"metrics",
::metrics::Level::INFO,
::core::option::Option::Some("metrics"),
);
&METADATA
};
::metrics::with_recorder(|recorder| {
recorder.register_counter(&metric_key, metadata)
})
},
}
}
/// Describe all exposed metrics. Internally calls `describe_*` macros from
/// the metrics crate according to the metric type.
///
/// See <https://docs.rs/metrics/0.20.1/metrics/index.html#macros>
fn describe(scope: &str) {
{
::metrics::with_recorder(|recorder| {
recorder
.describe_counter(
::core::convert::Into::into(
::alloc::__export::must_use({
let res = ::alloc::fmt::format(
format_args!(
"{0}{1}{2}",
scope,
".",
"messages_received_total",
),
);
res
}),
),
::core::option::Option::None,
::core::convert::Into::into("Number of messages received"),
);
});
};
}
}
impl std::fmt::Debug for MeteredReceiverMetrics {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("MeteredReceiverMetrics").finish()
}
}