31 lines
613 B
V
31 lines
613 B
V
module metrics
|
|
|
|
[params]
|
|
pub struct Metric {
|
|
name string [required]
|
|
labels [][2]string
|
|
}
|
|
|
|
[inline]
|
|
fn join_two_array(arr [2]string) string {
|
|
return arr[0] + '=' + arr[1]
|
|
}
|
|
|
|
pub fn (m &Metric) str() string {
|
|
if m.labels.len == 0 {
|
|
return m.name
|
|
}
|
|
|
|
return '$m.name{${m.labels.map(join_two_array(it)).join(',')}}'
|
|
}
|
|
|
|
interface MetricsCollector {
|
|
counter_register(value u64, metric Metric)
|
|
counter_increment(metric Metric)
|
|
counter_decrement(metric Metric)
|
|
counter_get(metric Metric) ?u64
|
|
histogram_register(metric Metric)
|
|
histogram_add(value f64, metric Metric)
|
|
histogram_get(metric Metric) ?
|
|
}
|