mirror of
https://github.com/mii443/prometheus-android-exporter.git
synced 2025-12-03 11:08:21 +00:00
add prometheus custom exporter implementation
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user