Search in sources :

Example 16 with MetricFamilySamples

use of io.prometheus.client.Collector.MetricFamilySamples in project instrumentation-java by census-instrumentation.

the class PrometheusExportUtilsTest method createDescribableMetricFamilySamples_WithNamespace.

@Test
public void createDescribableMetricFamilySamples_WithNamespace() {
    String namespace1 = "myorg";
    assertThat(PrometheusExportUtils.createDescribableMetricFamilySamples(CUMULATIVE_METRIC_DESCRIPTOR, namespace1)).isEqualTo(new MetricFamilySamples(namespace1 + '_' + METRIC_NAME, Type.COUNTER, METRIC_DESCRIPTION, Collections.<Sample>emptyList()));
    String namespace2 = "opencensus/";
    assertThat(PrometheusExportUtils.createDescribableMetricFamilySamples(CUMULATIVE_METRIC_DESCRIPTOR, namespace2)).isEqualTo(new MetricFamilySamples("opencensus_" + METRIC_NAME, Type.COUNTER, METRIC_DESCRIPTION, Collections.<Sample>emptyList()));
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Example 17 with MetricFamilySamples

use of io.prometheus.client.Collector.MetricFamilySamples in project promregator by promregator.

the class TextFormat004ParserTest method testSimpleNan.

@Test
public void testSimpleNan() {
    String textToParse = "# Minimalistic line:\n" + "\n" + "metric_without_labels Nan 123456789012345600\n";
    TextFormat004Parser subject = new TextFormat004Parser(textToParse);
    HashMap<String, Collector.MetricFamilySamples> resultMap = subject.parse();
    Enumeration<Collector.MetricFamilySamples> result = Collections.enumeration(resultMap.values());
    // compareEMFS does not properly work with NaN values
    // Thus, we have to check this explicitly here
    MetricFamilySamples mfs = result.nextElement();
    Assert.assertFalse(result.hasMoreElements());
    Assert.assertEquals("metric_without_labels", mfs.name);
    Assert.assertEquals(1, mfs.samples.size());
    Sample actualSample = mfs.samples.get(0);
    Assert.assertEquals("metric_without_labels", actualSample.name);
    Assert.assertTrue(Double.isNaN(actualSample.value));
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Example 18 with MetricFamilySamples

use of io.prometheus.client.Collector.MetricFamilySamples in project promregator by promregator.

the class MFSUtils method convertToEMFSToHashMap.

public static HashMap<String, MetricFamilySamples> convertToEMFSToHashMap(Enumeration<MetricFamilySamples> emfs) {
    HashMap<String, MetricFamilySamples> map = new HashMap<>();
    while (emfs.hasMoreElements()) {
        MetricFamilySamples mfs = emfs.nextElement();
        map.put(mfs.name, mfs);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples)

Example 19 with MetricFamilySamples

use of io.prometheus.client.Collector.MetricFamilySamples in project promregator by promregator.

the class MergableMetricFamilySamples method merge.

public void merge(HashMap<String, MetricFamilySamples> others) {
    for (Entry<String, MetricFamilySamples> entry : others.entrySet()) {
        String metricName = entry.getKey();
        MetricFamilySamples otherMFS = entry.getValue();
        MetricFamilySamples mfs = this.map.get(metricName);
        if (mfs == null) {
            this.map.put(metricName, otherMFS);
            continue;
        }
        if (otherMFS.type != mfs.type) {
            log.warn(String.format("Attempt to merge metric %s, but types are deviating: %s vs. %s", metricName, otherMFS.toString(), mfs.toString()));
            continue;
        }
        mfs.samples.addAll(otherMFS.samples);
    }
}
Also used : MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples)

Example 20 with MetricFamilySamples

use of io.prometheus.client.Collector.MetricFamilySamples in project promregator by promregator.

the class MergableMetricFamilySamples method toType004String.

public String toType004String() {
    Enumeration<MetricFamilySamples> resultEMFS = this.getEnumerationMetricFamilySamples();
    Writer writer = new StringWriter();
    try {
        TextFormat.write004(writer, resultEMFS);
    } catch (IOException e) {
        log.error("IO Exception on StringWriter; uuuhhh...", e);
    }
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) IOException(java.io.IOException) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

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