2022-12-26 21:49:07 +01:00
|
|
|
module metrics
|
|
|
|
|
|
|
|
fn test_only_counters() {
|
|
|
|
mut m := new_default_collector()
|
|
|
|
m.counter_increment(name: 'test')
|
|
|
|
|
2023-01-28 17:21:59 +01:00
|
|
|
mut e := new_prometheus_exporter()
|
2023-01-04 09:07:45 +01:00
|
|
|
e.load('hi_', m)
|
2022-12-26 21:49:07 +01:00
|
|
|
|
2023-01-04 09:07:45 +01:00
|
|
|
assert e.export_to_string()! == 'hi_test 1\n'
|
2022-12-26 21:49:07 +01:00
|
|
|
|
|
|
|
metric := Metric{
|
|
|
|
name: 'test2'
|
|
|
|
labels: [['hi', 'label']!, ['hi2', 'label2']!]
|
|
|
|
}
|
|
|
|
m.counter_increment(metric)
|
|
|
|
m.counter_increment(metric)
|
|
|
|
|
2023-01-04 09:07:45 +01:00
|
|
|
assert e.export_to_string()! == 'hi_test 1\nhi_test2{hi="label",hi2="label2"} 2\n'
|
2022-12-26 21:49:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_only_gauges() {
|
|
|
|
mut m := new_default_collector()
|
|
|
|
m.gauge_set(3.25, name: 'test')
|
|
|
|
|
2023-01-28 17:21:59 +01:00
|
|
|
mut e := new_prometheus_exporter()
|
2023-01-04 09:07:45 +01:00
|
|
|
e.load('hi_', m)
|
2022-12-26 21:49:07 +01:00
|
|
|
|
2023-01-04 09:07:45 +01:00
|
|
|
assert e.export_to_string()! == 'hi_test 3.25\n'
|
2022-12-26 21:49:07 +01:00
|
|
|
|
|
|
|
metric := Metric{
|
|
|
|
name: 'test2'
|
|
|
|
labels: [['hi', 'label']!, ['hi2', 'label2']!]
|
|
|
|
}
|
|
|
|
m.gauge_add(2.5, metric)
|
|
|
|
|
2023-01-04 09:07:45 +01:00
|
|
|
assert e.export_to_string()! == 'hi_test 3.25\nhi_test2{hi="label",hi2="label2"} 2.5\n'
|
2022-12-26 21:49:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_single_histogram() {
|
|
|
|
mut m := new_default_collector()
|
|
|
|
|
2023-01-28 17:32:57 +01:00
|
|
|
m.histogram_buckets_set('test', [0.5, 5.0])
|
2022-12-26 21:49:07 +01:00
|
|
|
m.histogram_record(5.0, name: 'test')
|
2023-01-04 10:31:48 +01:00
|
|
|
m.histogram_record(7.0, name: 'test')
|
2022-12-26 21:49:07 +01:00
|
|
|
|
2023-01-28 17:21:59 +01:00
|
|
|
mut e := new_prometheus_exporter()
|
2023-01-04 09:07:45 +01:00
|
|
|
e.load('hi_', m)
|
2022-12-26 21:49:07 +01:00
|
|
|
|
2023-01-04 10:31:48 +01:00
|
|
|
assert e.export_to_string()! == 'hi_test_count 2\nhi_test_sum 12.0\nhi_test_bucket{le="0.5"} 0\nhi_test_bucket{le="5.0"} 1\nhi_test_bucket{le="+Inf"} 2\n'
|
2022-12-26 21:49:07 +01:00
|
|
|
}
|