45 lines
907 B
V
45 lines
907 B
V
module metrics
|
|
|
|
import io
|
|
|
|
[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(',')}}'
|
|
}
|
|
|
|
pub interface MetricsCollector {
|
|
counter_get(metric Metric) ?u64
|
|
counters() []Metric
|
|
histogram_get(metric Metric) ?[]f64
|
|
histograms() []Metric
|
|
gauge_get(metric Metric) ?f64
|
|
gauges() []Metric
|
|
mut:
|
|
counter_set(val u64, metric Metric)
|
|
counter_increment(metric Metric)
|
|
histogram_record(value f64, metric Metric)
|
|
gauge_set(value f64, metric Metric)
|
|
gauge_add(value f64, metric Metric)
|
|
gauge_sub(value f64, metric Metric)
|
|
}
|
|
|
|
pub interface MetricsExporter {
|
|
load(collector MetricsCollector)
|
|
export_to_writer(writer io.Writer) !
|
|
export_to_string() !string
|
|
}
|