Search in sources :

Example 6 with Sample

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

the class TextFormat004ParserTest method testGaugeWithSingleLabel.

@Test
public void testGaugeWithSingleLabel() {
    String textToParse = "# TYPE metric_with_label gauge\n" + "metric_with_label{name=\"value\"} 12.47\n";
    TextFormat004Parser subject = new TextFormat004Parser(textToParse);
    HashMap<String, Collector.MetricFamilySamples> resultMap = subject.parse();
    Enumeration<Collector.MetricFamilySamples> result = Collections.enumeration(resultMap.values());
    // creating expected result
    LinkedList<Collector.MetricFamilySamples> expectedList = new LinkedList<>();
    List<Sample> samples = new LinkedList<>();
    List<String> labelNames = new LinkedList<>();
    labelNames.add("name");
    List<String> labelValues = new LinkedList<>();
    labelValues.add("value");
    Sample sample = new Sample("metric_with_label", labelNames, labelValues, 12.47);
    samples.add(sample);
    Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_with_label", Type.GAUGE, null, samples);
    expectedList.add(expectedMFS);
    Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList);
    // compare
    compareEMFS(expected, result);
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) Collector(io.prometheus.client.Collector) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) LinkedList(java.util.LinkedList) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Example 7 with Sample

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

the class TextFormat004ParserTest method testSimple.

@Test
public void testSimple() {
    String textToParse = "# Minimalistic line:\n" + "metric_without_timestamp_and_labels 12.47\n";
    TextFormat004Parser subject = new TextFormat004Parser(textToParse);
    HashMap<String, Collector.MetricFamilySamples> resultMap = subject.parse();
    Enumeration<Collector.MetricFamilySamples> result = Collections.enumeration(resultMap.values());
    // creating expected result
    LinkedList<Collector.MetricFamilySamples> expectedList = new LinkedList<>();
    List<Sample> samples = new LinkedList<>();
    Sample sample = new Sample("metric_without_timestamp_and_labels", new LinkedList<String>(), new LinkedList<String>(), 12.47);
    samples.add(sample);
    Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_without_timestamp_and_labels", Type.UNTYPED, null, samples);
    expectedList.add(expectedMFS);
    Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList);
    // compare
    compareEMFS(expected, result);
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) Collector(io.prometheus.client.Collector) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) LinkedList(java.util.LinkedList) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Example 8 with Sample

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

the class TextFormat004ParserTest method testStandardExampleWithEscapingInLabels.

@Test
public void testStandardExampleWithEscapingInLabels() {
    String textToParse = "# Escaping in label values:\n" + "msdos_file_access_time_seconds{path=\"C:\\\\DIR\\\\FILE.TXT\",error=\"Cannot find file:\\n\\\"FILE.TXT\\\"\"} 1.458255915e9";
    TextFormat004Parser subject = new TextFormat004Parser(textToParse);
    HashMap<String, Collector.MetricFamilySamples> resultMap = subject.parse();
    Enumeration<Collector.MetricFamilySamples> result = Collections.enumeration(resultMap.values());
    // creating expected result
    LinkedList<Collector.MetricFamilySamples> expectedList = new LinkedList<>();
    List<Sample> samples = new LinkedList<>();
    List<String> labelNames = new LinkedList<>();
    labelNames.add("path");
    labelNames.add("error");
    List<String> labelValues = new LinkedList<>();
    labelValues.add("C:\\DIR\\FILE.TXT");
    labelValues.add("Cannot find file:\n\"FILE.TXT\"");
    Sample sample = new Sample("msdos_file_access_time_seconds", labelNames, labelValues, 1.458255915e9);
    samples.add(sample);
    Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("msdos_file_access_time_seconds", Type.UNTYPED, null, samples);
    expectedList.add(expectedMFS);
    Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList);
    // compare
    compareEMFS(expected, result);
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) Collector(io.prometheus.client.Collector) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) LinkedList(java.util.LinkedList) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Example 9 with Sample

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

the class TextFormat004ParserTest method createSampleForSummary.

private static Sample createSampleForSummary(String bucketMetricName, String quantileValue, double value) {
    List<String> labelNames = new LinkedList<>();
    labelNames.add("quantile");
    List<String> labelValues = new LinkedList<>();
    labelValues.add(quantileValue);
    Sample sample = new Sample(bucketMetricName, labelNames, labelValues, value);
    return sample;
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) LinkedList(java.util.LinkedList)

Example 10 with Sample

use of io.prometheus.client.Collector.MetricFamilySamples.Sample 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)

Aggregations

Sample (io.prometheus.client.Collector.MetricFamilySamples.Sample)44 MetricFamilySamples (io.prometheus.client.Collector.MetricFamilySamples)34 Test (org.junit.Test)32 LinkedList (java.util.LinkedList)27 Collector (io.prometheus.client.Collector)18 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Type (io.prometheus.client.Collector.Type)2 Collector.doubleToGoString (io.prometheus.client.Collector.doubleToGoString)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Meter (com.netflix.spectator.api.Meter)1 Registry (com.netflix.spectator.api.Registry)1 Tag (com.netflix.spectator.api.Tag)1 LabelValue (io.opencensus.metrics.LabelValue)1 Distribution (io.opencensus.metrics.export.Distribution)1 BucketOptions (io.opencensus.metrics.export.Distribution.BucketOptions)1 ExplicitOptions (io.opencensus.metrics.export.Distribution.BucketOptions.ExplicitOptions)1 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)1 Summary (io.opencensus.metrics.export.Summary)1 ValueAtPercentile (io.opencensus.metrics.export.Summary.Snapshot.ValueAtPercentile)1