metrics/metrics.v

38 lines
800 B
V

module metrics
import io
[params]
pub struct Metric {
pub:
name string [required]
labels [][2]string
}
pub fn (m &Metric) str() string {
return '$m.name $m.labels'
}
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(prefix string, collector MetricsCollector)
export_to_writer(writer io.Writer) !
export_to_string() !string
serialize_metric(metric Metric) string
}