Compare commits
No commits in common. "main" and "mem-usage" have entirely different histories.
|
@ -10,7 +10,7 @@ pub:
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (m &Metric) str() string {
|
pub fn (m &Metric) str() string {
|
||||||
return '${m.name} ${m.labels}'
|
return '$m.name $m.labels'
|
||||||
}
|
}
|
||||||
|
|
||||||
pub interface MetricsCollector {
|
pub interface MetricsCollector {
|
||||||
|
@ -23,7 +23,6 @@ pub interface MetricsCollector {
|
||||||
mut:
|
mut:
|
||||||
counter_set(val u64, metric Metric)
|
counter_set(val u64, metric Metric)
|
||||||
counter_increment(metric Metric)
|
counter_increment(metric Metric)
|
||||||
histogram_buckets_set(name string, buckets []f64)
|
|
||||||
histogram_record(value f64, metric Metric)
|
histogram_record(value f64, metric Metric)
|
||||||
gauge_set(value f64, metric Metric)
|
gauge_set(value f64, metric Metric)
|
||||||
gauge_add(value f64, metric Metric)
|
gauge_add(value f64, metric Metric)
|
||||||
|
|
2
null.v
2
null.v
|
@ -19,8 +19,6 @@ pub fn (c &NullCollector) counters() []Metric {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (c &NullCollector) histogram_buckets_set(name string, buckets []f64) {}
|
|
||||||
|
|
||||||
pub fn (c &NullCollector) histogram_record(value f64, metric Metric) {}
|
pub fn (c &NullCollector) histogram_record(value f64, metric Metric) {}
|
||||||
|
|
||||||
pub fn (c &NullCollector) histogram_get(metric Metric) ?Histogram {
|
pub fn (c &NullCollector) histogram_get(metric Metric) ?Histogram {
|
||||||
|
|
14
prometheus.v
14
prometheus.v
|
@ -27,10 +27,10 @@ fn join_two_array(arr [2]string) string {
|
||||||
|
|
||||||
pub fn (e &PrometheusExporter) serialize_metric(metric Metric) string {
|
pub fn (e &PrometheusExporter) serialize_metric(metric Metric) string {
|
||||||
if metric.labels.len == 0 {
|
if metric.labels.len == 0 {
|
||||||
return '${e.prefix}${metric.name}'
|
return '$e.prefix$metric.name'
|
||||||
}
|
}
|
||||||
|
|
||||||
return '${e.prefix}${metric.name}{${metric.labels.map(join_two_array(it)).join(',')}}'
|
return '$e.prefix$metric.name{${metric.labels.map(join_two_array(it)).join(',')}}'
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut e PrometheusExporter) export_to_string() !string {
|
pub fn (mut e PrometheusExporter) export_to_string() !string {
|
||||||
|
@ -44,14 +44,14 @@ pub fn (mut e PrometheusExporter) export_to_string() !string {
|
||||||
pub fn (mut e PrometheusExporter) export_to_writer(mut writer io.Writer) ! {
|
pub fn (mut e PrometheusExporter) export_to_writer(mut writer io.Writer) ! {
|
||||||
for counter in e.collector.counters() {
|
for counter in e.collector.counters() {
|
||||||
val := e.collector.counter_get(counter) or { return error("This can't happen.") }
|
val := e.collector.counter_get(counter) or { return error("This can't happen.") }
|
||||||
line := '${e.serialize_metric(counter)} ${val}\n'
|
line := '${e.serialize_metric(counter)} $val\n'
|
||||||
|
|
||||||
writer.write(line.bytes())!
|
writer.write(line.bytes())!
|
||||||
}
|
}
|
||||||
|
|
||||||
for gauge in e.collector.gauges() {
|
for gauge in e.collector.gauges() {
|
||||||
val := e.collector.gauge_get(gauge) or { return error("This can't happen.") }
|
val := e.collector.gauge_get(gauge) or { return error("This can't happen.") }
|
||||||
line := '${e.serialize_metric(gauge)} ${val}\n'
|
line := '${e.serialize_metric(gauge)} $val\n'
|
||||||
|
|
||||||
writer.write(line.bytes())!
|
writer.write(line.bytes())!
|
||||||
}
|
}
|
||||||
|
@ -63,13 +63,13 @@ pub fn (mut e PrometheusExporter) export_to_writer(mut writer io.Writer) ! {
|
||||||
...hist
|
...hist
|
||||||
name: '${hist.name}_count'
|
name: '${hist.name}_count'
|
||||||
}
|
}
|
||||||
writer.write('${e.serialize_metric(m)} ${hist_data.total_count}\n'.bytes())!
|
writer.write('${e.serialize_metric(m)} $hist_data.total_count\n'.bytes())!
|
||||||
|
|
||||||
m = Metric{
|
m = Metric{
|
||||||
...hist
|
...hist
|
||||||
name: '${hist.name}_sum'
|
name: '${hist.name}_sum'
|
||||||
}
|
}
|
||||||
writer.write('${e.serialize_metric(m)} ${hist_data.sum}\n'.bytes())!
|
writer.write('${e.serialize_metric(m)} $hist_data.sum\n'.bytes())!
|
||||||
|
|
||||||
mut le_labels := [][2]string{}
|
mut le_labels := [][2]string{}
|
||||||
le_labels.prepend(hist.labels)
|
le_labels.prepend(hist.labels)
|
||||||
|
@ -95,7 +95,7 @@ pub fn (mut e PrometheusExporter) export_to_writer(mut writer io.Writer) ! {
|
||||||
labels: le_labels
|
labels: le_labels
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.write('${e.serialize_metric(m)} ${hist_data.total_count}\n'.bytes())!
|
writer.write('${e.serialize_metric(m)} $hist_data.total_count\n'.bytes())!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue