use of io.prometheus.client.Collector.MetricFamilySamples.Sample in project promregator by promregator.
the class TextFormat004ParserTest method testHelp.
@Test
public void testHelp() {
String textToParse = "# Simple metric without labels:\n" + "# TYPE metric_without_labels counter\n" + "# HELP metric_without_labels this is my help text\n" + "metric_without_labels 12.47 123456789012345600\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_labels", new LinkedList<String>(), new LinkedList<String>(), 12.47);
samples.add(sample);
Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_without_labels", Type.COUNTER, "this is my help text", samples);
expectedList.add(expectedMFS);
Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList);
// compare
compareEMFS(expected, result);
}
use of io.prometheus.client.Collector.MetricFamilySamples.Sample in project promregator by promregator.
the class TextFormat004ParserTest method testGaugeWithTimestampAndEmptyLine.
@Test
public void testGaugeWithTimestampAndEmptyLine() {
String textToParse = "# Simple metric without labels:\n" + "# TYPE metric_without_labels gauge\n" + "\n" + "metric_without_labels 12.47 123456789012345600\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_labels", new LinkedList<String>(), new LinkedList<String>(), 12.47);
samples.add(sample);
Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_without_labels", Type.GAUGE, null, samples);
expectedList.add(expectedMFS);
Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList);
// compare
compareEMFS(expected, result);
}
use of io.prometheus.client.Collector.MetricFamilySamples.Sample in project promregator by promregator.
the class TextFormat004ParserTest method createSampleForHistogramWithDummyLabel.
private static Sample createSampleForHistogramWithDummyLabel(String bucketMetricName, String leValue, double value, boolean firstPosition) {
List<String> labelNames = new LinkedList<>();
if (firstPosition) {
labelNames.add("name");
}
labelNames.add("le");
if (!firstPosition) {
labelNames.add("name");
}
List<String> labelValues = new LinkedList<>();
if (firstPosition) {
labelValues.add("value");
}
labelValues.add(leValue);
if (!firstPosition) {
labelValues.add("value");
}
Sample sample = new Sample(bucketMetricName, labelNames, labelValues, value);
return sample;
}
use of io.prometheus.client.Collector.MetricFamilySamples.Sample in project promregator by promregator.
the class TextFormat004ParserTest method testHistogramSpecificationExample.
@Test
public void testHistogramSpecificationExample() {
String textToParse = "# A histogram, which has a pretty complex representation in the text format:\n" + "# HELP http_request_duration_seconds A histogram of the request duration.\n" + "# TYPE http_request_duration_seconds histogram\n" + "http_request_duration_seconds_bucket{le=\"0.05\"} 24054\n" + "http_request_duration_seconds_bucket{le=\"0.1\"} 33444\n" + "http_request_duration_seconds_bucket{le=\"0.2\"} 100392\n" + "http_request_duration_seconds_bucket{le=\"0.5\"} 129389\n" + "http_request_duration_seconds_bucket{le=\"1\"} 133988\n" + "http_request_duration_seconds_bucket{le=\"+Inf\"} 144320\n" + "http_request_duration_seconds_sum 53423\n" + "http_request_duration_seconds_count 144320";
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 = null;
sample = createSampleForHistogram("http_request_duration_seconds_bucket", "0.05", 24054);
samples.add(sample);
sample = createSampleForHistogram("http_request_duration_seconds_bucket", "0.1", 33444);
samples.add(sample);
sample = createSampleForHistogram("http_request_duration_seconds_bucket", "0.2", 100392);
samples.add(sample);
sample = createSampleForHistogram("http_request_duration_seconds_bucket", "0.5", 129389);
samples.add(sample);
sample = createSampleForHistogram("http_request_duration_seconds_bucket", "1", 133988);
samples.add(sample);
sample = createSampleForHistogram("http_request_duration_seconds_bucket", "+Inf", 144320);
samples.add(sample);
sample = new Sample("http_request_duration_seconds_sum", new LinkedList<>(), new LinkedList<>(), 53423);
samples.add(sample);
sample = new Sample("http_request_duration_seconds_count", new LinkedList<>(), new LinkedList<>(), 144320);
samples.add(sample);
Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("http_request_duration_seconds", Type.HISTOGRAM, "A histogram of the request duration.", samples);
expectedList.add(expectedMFS);
Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList);
// compare
compareEMFS(expected, result);
}
use of io.prometheus.client.Collector.MetricFamilySamples.Sample in project promregator by promregator.
the class TextFormat004ParserTest method testCounterWithTimestampAndEmptyLine.
@Test
public void testCounterWithTimestampAndEmptyLine() {
String textToParse = "# Simple metric without labels:\n" + "# TYPE metric_without_labels counter\n" + "\n" + "metric_without_labels 12.47 123456789012345600\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_labels", new LinkedList<String>(), new LinkedList<String>(), 12.47);
samples.add(sample);
Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_without_labels", Type.COUNTER, null, samples);
expectedList.add(expectedMFS);
Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList);
// compare
compareEMFS(expected, result);
}
Aggregations