add prometheus custom exporter implementation

This commit is contained in:
Martin Ptáček
2023-04-16 22:33:29 +02:00
parent b19c62c676
commit 31225bd32b
2 changed files with 27 additions and 0 deletions

View File

@@ -47,6 +47,8 @@ android {
}
dependencies {
// custom dependencies
implementation 'io.prometheus:simpleclient:0.16.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'

View File

@@ -0,0 +1,25 @@
package com.birdthedeveloper.prometheus.android.prometheus.android.exporter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import io.prometheus.client.Collector;
import io.prometheus.client.GaugeMetricFamily;
public class AndroidCustomExporter extends Collector {
public List<MetricFamilySamples> collect() {
List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>();
// With no labels.
mfs.add(new GaugeMetricFamily("my_gauge", "help", 42));
// With labels
GaugeMetricFamily labeledGauge = new GaugeMetricFamily("my_other_gauge", "help", Arrays.asList("labelname"));
labeledGauge.addMetric(Arrays.asList("foo"), 4);
labeledGauge.addMetric(Arrays.asList("bar"), 5);
mfs.add(labeledGauge);
return mfs;
}
}
// Registration
//static final YourCustomCollector requests = new YourCustomCollector().register()