Java Code Examples for io.prometheus.client.Collector.Type#GAUGE
The following examples show how to use
io.prometheus.client.Collector.Type#GAUGE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericMetricFamilySamplesPrefixRewriterTest.java From promregator with Apache License 2.0 | 6 votes |
@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); }
Example 2
Source File: GenericMetricFamilySamplesPrefixRewriterTest.java From promregator with Apache License 2.0 | 6 votes |
@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); }
Example 3
Source File: ParserTest.java From promregator with Apache License 2.0 | 6 votes |
@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"; Parser subject = new Parser(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, "", samples); expectedList.add(expectedMFS); Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList); // compare compareEMFS(expected, result); }
Example 4
Source File: PrometheusExportUtils.java From opencensus-java with Apache License 2.0 | 6 votes |
@VisibleForTesting static Type getType(MetricDescriptor.Type type) { if (type == MetricDescriptor.Type.CUMULATIVE_INT64 || type == MetricDescriptor.Type.CUMULATIVE_DOUBLE) { return Type.COUNTER; } else if (type == MetricDescriptor.Type.GAUGE_INT64 || type == MetricDescriptor.Type.GAUGE_DOUBLE) { return Type.GAUGE; } else if (type == MetricDescriptor.Type.CUMULATIVE_DISTRIBUTION || type == MetricDescriptor.Type.GAUGE_DISTRIBUTION) { return Type.HISTOGRAM; } else if (type == MetricDescriptor.Type.SUMMARY) { return Type.SUMMARY; } return Type.UNTYPED; }
Example 5
Source File: MetricAdapter.java From opentelemetry-java with Apache License 2.0 | 5 votes |
static Type toMetricFamilyType(MetricData.Descriptor.Type type) { switch (type) { case NON_MONOTONIC_LONG: case NON_MONOTONIC_DOUBLE: return Type.GAUGE; case MONOTONIC_LONG: case MONOTONIC_DOUBLE: return Type.COUNTER; case SUMMARY: return Type.SUMMARY; } return Type.UNTYPED; }
Example 6
Source File: ParserTest.java From promregator with Apache License 2.0 | 5 votes |
@Test public void testGaugeWithSingleLabel() { String textToParse = "# TYPE metric_with_label gauge\n" + "metric_with_label{name=\"value\"} 12.47\n"; Parser subject = new Parser(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, "", samples); expectedList.add(expectedMFS); Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList); // compare compareEMFS(expected, result); }
Example 7
Source File: ParserTest.java From promregator with Apache License 2.0 | 5 votes |
@Test public void testGaugeWithMultipleLabels() { String textToParse = "# TYPE metric_with_label gauge\n" + "metric_with_label{name=\"value\",second=\"somevalue\",third=\"next value\",} 12.47\n"; Parser subject = new Parser(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"); labelNames.add("second"); labelNames.add("third"); List<String> labelValues = new LinkedList<>(); labelValues.add("value"); labelValues.add("somevalue"); labelValues.add("next 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, "", samples); expectedList.add(expectedMFS); Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList); // compare compareEMFS(expected, result); }
Example 8
Source File: ParserTest.java From promregator with Apache License 2.0 | 5 votes |
@Test public void testGaugeWithSingleLabelEscaping() { String textToParse = "# TYPE metric_with_label gauge\n" + "metric_with_label{name=\"containing \\\" and \\\\ and \\n\"} 12.47\n"; Parser subject = new Parser(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("containing \" and \\ and \n"); 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, "", samples); expectedList.add(expectedMFS); Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList); // compare compareEMFS(expected, result); }
Example 9
Source File: ParserTest.java From promregator with Apache License 2.0 | 4 votes |
@Test // see also issue #175 public void testGaugeNonParsableJunk() { String textToParse = "# TYPE metric_with_label gauge\n" + "metric_with_label{name=\"xyz\"} 12.47\n" + "\n" + "some_garbage abc----\n" + "\n" + "# TYPE another_metric gauge\n" + "another_metric 123.1\n"; Parser subject = new Parser(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("xyz"); 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, "", samples); expectedList.add(expectedMFS); samples = new LinkedList<>(); samples.add(new Sample("another_metric", Collections.emptyList(), Collections.emptyList(), 123.1)); expectedMFS = new Collector.MetricFamilySamples("another_metric", Type.GAUGE, "", samples); expectedList.add(expectedMFS); Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList); // compare compareEMFS(expected, result); }
Example 10
Source File: MockedMetricsFetcher.java From promregator with Apache License 2.0 | 4 votes |
@Override public HashMap<String, MetricFamilySamples> call() throws Exception { HashMap<String, MetricFamilySamples> result = new HashMap<>(); String metricName = "metric_"+this.instance.getTarget().getApplicationName(); LinkedList<String> labelNames = new LinkedList<>(); labelNames.add("instanceId"); LinkedList<String> labelValues = new LinkedList<>(); labelValues.add(this.instance.getInstanceId()); Sample s = new Sample(metricName, labelNames, labelValues, 1.0); List<Sample> samples = new LinkedList<>(); samples.add(s); MetricFamilySamples mfs = new MetricFamilySamples(metricName, Type.GAUGE, "dummyhelp", samples); result.put(metricName, mfs); return result; }