50 lines
1.1 KiB
V
50 lines
1.1 KiB
V
module metrics
|
|
|
|
fn test_only_counters() {
|
|
mut m := new_default_collector()
|
|
m.counter_increment(name: 'test')
|
|
|
|
mut e := new_prometheus_exporter([])
|
|
e.load('hi_', m)
|
|
|
|
assert e.export_to_string()! == 'hi_test 1\n'
|
|
|
|
metric := Metric{
|
|
name: 'test2'
|
|
labels: [['hi', 'label']!, ['hi2', 'label2']!]
|
|
}
|
|
m.counter_increment(metric)
|
|
m.counter_increment(metric)
|
|
|
|
assert e.export_to_string()! == 'hi_test 1\nhi_test2{hi="label",hi2="label2"} 2\n'
|
|
}
|
|
|
|
fn test_only_gauges() {
|
|
mut m := new_default_collector()
|
|
m.gauge_set(3.25, name: 'test')
|
|
|
|
mut e := new_prometheus_exporter([])
|
|
e.load('hi_', m)
|
|
|
|
assert e.export_to_string()! == 'hi_test 3.25\n'
|
|
|
|
metric := Metric{
|
|
name: 'test2'
|
|
labels: [['hi', 'label']!, ['hi2', 'label2']!]
|
|
}
|
|
m.gauge_add(2.5, metric)
|
|
|
|
assert e.export_to_string()! == 'hi_test 3.25\nhi_test2{hi="label",hi2="label2"} 2.5\n'
|
|
}
|
|
|
|
fn test_single_histogram() {
|
|
mut m := new_default_collector()
|
|
|
|
m.histogram_record(5.0, name: 'test')
|
|
|
|
mut e := new_prometheus_exporter([0.5, 5.0])
|
|
e.load('hi_', m)
|
|
|
|
assert e.export_to_string()! == 'hi_test_count 1\nhi_test_sum 5.0\nhi_test_bucket{le="0.5"} 0\nhi_test_bucket{le="5.0"} 1\n'
|
|
}
|