Search in sources :

Example 21 with MetricFamilySamples

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();
}
Also used : MergableMetricFamilySamples(org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples) MergableMetricFamilySamples(org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with MetricFamilySamples

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;
}
Also used : HashMap(java.util.HashMap) Collector(io.prometheus.client.Collector) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) LinkedList(java.util.LinkedList) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples)

Example 23 with MetricFamilySamples

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;
}
Also used : HashMap(java.util.HashMap) Future(java.util.concurrent.Future) MergableMetricFamilySamples(org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) LinkedList(java.util.LinkedList) MetricsFetcher(org.cloudfoundry.promregator.fetcher.MetricsFetcher) CFMetricsFetcher(org.cloudfoundry.promregator.fetcher.CFMetricsFetcher)

Example 24 with MetricFamilySamples

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);
}
Also used : HashMap(java.util.HashMap) Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 25 with MetricFamilySamples

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);
}
Also used : HashMap(java.util.HashMap) Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

MetricFamilySamples (io.prometheus.client.Collector.MetricFamilySamples)31 Sample (io.prometheus.client.Collector.MetricFamilySamples.Sample)17 Test (org.junit.Test)15 HashMap (java.util.HashMap)9 LinkedList (java.util.LinkedList)8 MergableMetricFamilySamples (org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples)4 IOException (java.io.IOException)3 Collector (io.prometheus.client.Collector)2 Type (io.prometheus.client.Collector.Type)2 Collector.doubleToGoString (io.prometheus.client.Collector.doubleToGoString)2 StringWriter (java.io.StringWriter)2 Writer (java.io.Writer)2 Future (java.util.concurrent.Future)2 CFMetricsFetcher (org.cloudfoundry.promregator.fetcher.CFMetricsFetcher)2 MetricsFetcher (org.cloudfoundry.promregator.fetcher.MetricsFetcher)2 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)1 Timer (io.prometheus.client.Histogram.Timer)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ExecutionException (java.util.concurrent.ExecutionException)1