use of io.prometheus.client.Collector.MetricFamilySamples in project promregator by promregator.
the class PromregatorMetricsEndpoint method getMetrics.
@RequestMapping(method = RequestMethod.GET, produces = TextFormat.CONTENT_TYPE_004)
public String getMetrics() {
HashMap<String, MetricFamilySamples> mfsMap = this.gmfspr.determineEnumerationOfMetricFamilySamples(this.collectorRegistry);
MergableMetricFamilySamples mmfs = new MergableMetricFamilySamples();
mmfs.merge(mfsMap);
return mmfs.toType004String();
}
use of io.prometheus.client.Collector.MetricFamilySamples in project promregator by promregator.
the class GenericMetricFamilySamplesPrefixRewriter method determineEnumerationOfMetricFamilySamples.
public HashMap<String, Collector.MetricFamilySamples> determineEnumerationOfMetricFamilySamples(HashMap<String, Collector.MetricFamilySamples> emfs) {
if (emfs == null) {
return null;
}
HashMap<String, Collector.MetricFamilySamples> newMap = new HashMap<String, Collector.MetricFamilySamples>();
for (Entry<String, MetricFamilySamples> entry : emfs.entrySet()) {
MetricFamilySamples mfs = entry.getValue();
List<Collector.MetricFamilySamples.Sample> newSamples = new LinkedList<Collector.MetricFamilySamples.Sample>();
for (Collector.MetricFamilySamples.Sample sample : mfs.samples) {
Collector.MetricFamilySamples.Sample newSample = new Collector.MetricFamilySamples.Sample(this.ensureWithPrefix(sample.name), sample.labelNames, sample.labelValues, sample.value);
newSamples.add(newSample);
}
Collector.MetricFamilySamples newEntry = new Collector.MetricFamilySamples(this.ensureWithPrefix(mfs.name), mfs.type, mfs.help, newSamples);
newMap.put(this.ensureWithPrefix(entry.getKey()), newEntry);
}
return newMap;
}
use of io.prometheus.client.Collector.MetricFamilySamples in project promregator by promregator.
the class AbstractMetricsEndpoint method startMetricsFetchers.
private LinkedList<Future<HashMap<String, MetricFamilySamples>>> startMetricsFetchers(List<MetricsFetcher> callablesPrep) {
LinkedList<Future<HashMap<String, MetricFamilySamples>>> futures = new LinkedList<>();
for (MetricsFetcher mf : callablesPrep) {
Future<HashMap<String, MetricFamilySamples>> future = this.metricsFetcherPool.submit(mf);
futures.add(future);
}
return futures;
}
use of io.prometheus.client.Collector.MetricFamilySamples in project promregator by promregator.
the class GenericMetricFamilySamplesPrefixRewriterTest method testDoesNotPrefixIfNotNeeded.
@Test
public void testDoesNotPrefixIfNotNeeded() {
GenericMetricFamilySamplesPrefixRewriter subject = new GenericMetricFamilySamplesPrefixRewriter("prefix");
List<Sample> samples = new LinkedList<>();
Sample s = new Sample("prefix_dummyname", Arrays.asList(new String[] { "labelName" }), Arrays.asList(new String[] { "labelValue" }), 1.0);
samples.add(s);
MetricFamilySamples mfs = new MetricFamilySamples("prefix_dummyname", Type.GAUGE, "dummyHelp", samples);
HashMap<String, MetricFamilySamples> map = new HashMap<>();
map.put("prefix_metricName", mfs);
HashMap<String, MetricFamilySamples> result = subject.determineEnumerationOfMetricFamilySamples(map);
MetricFamilySamples mfsResult = result.get("prefix_metricName");
Assert.assertNotNull(mfsResult);
Assert.assertEquals("prefix_dummyname", mfsResult.name);
Assert.assertEquals(1, mfsResult.samples.size());
Sample sampleResult = mfsResult.samples.get(0);
;
Assert.assertEquals("prefix_dummyname", sampleResult.name);
}
use of io.prometheus.client.Collector.MetricFamilySamples in project promregator by promregator.
the class GenericMetricFamilySamplesPrefixRewriterTest method testPrefixesProperly.
@Test
public void testPrefixesProperly() {
GenericMetricFamilySamplesPrefixRewriter subject = new GenericMetricFamilySamplesPrefixRewriter("prefix");
List<Sample> samples = new LinkedList<>();
Sample s = new Sample("dummyname", Arrays.asList(new String[] { "labelName" }), Arrays.asList(new String[] { "labelValue" }), 1.0);
samples.add(s);
MetricFamilySamples mfs = new MetricFamilySamples("dummyname", Type.GAUGE, "dummyHelp", samples);
HashMap<String, MetricFamilySamples> map = new HashMap<>();
map.put("metricName", mfs);
HashMap<String, MetricFamilySamples> result = subject.determineEnumerationOfMetricFamilySamples(map);
MetricFamilySamples mfsResult = result.get("prefix_metricName");
Assert.assertNotNull(mfsResult);
Assert.assertEquals("prefix_dummyname", mfsResult.name);
Assert.assertEquals(1, mfsResult.samples.size());
Sample sampleResult = mfsResult.samples.get(0);
;
Assert.assertEquals("prefix_dummyname", sampleResult.name);
}
Aggregations