Java Code Examples for io.prometheus.client.Collector.Type#UNTYPED
The following examples show how to use
io.prometheus.client.Collector.Type#UNTYPED .
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: ParserTest.java From promregator with Apache License 2.0 | 6 votes |
@Test public void testSimple() { String textToParse = "# Minimalistic line:\n" + "metric_without_timestamp_and_labels 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<>(); 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, "", samples); expectedList.add(expectedMFS); Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList); // compare compareEMFS(expected, result); }
Example 2
Source File: ParserTest.java From promregator with Apache License 2.0 | 6 votes |
@Test public void testSimpleWithTimestampAndEmptyLine() { String textToParse = "# Minimalistic line:\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.UNTYPED, "", samples); expectedList.add(expectedMFS); Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList); // compare compareEMFS(expected, result); }
Example 3
Source File: ParserTest.java From promregator with Apache License 2.0 | 6 votes |
@Test public void testSimpleWithEFormat() { String textToParse = "# Minimalistic line:\n" + "\n"+ "metric_without_labels 1.7560473e+07\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>(), 1.7560473e+07); samples.add(sample); Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_without_labels", Type.UNTYPED, "", samples); expectedList.add(expectedMFS); Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList); // compare compareEMFS(expected, result); }
Example 4
Source File: ParserTest.java From promregator with Apache License 2.0 | 6 votes |
@Test public void testSimplePlusInf() { String textToParse = "# Minimalistic line:\n" + "\n"+ "metric_without_labels +Inf 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>(), Double.POSITIVE_INFINITY); samples.add(sample); Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_without_labels", Type.UNTYPED, "", samples); expectedList.add(expectedMFS); Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList); // compare compareEMFS(expected, result); }
Example 5
Source File: ParserTest.java From promregator with Apache License 2.0 | 6 votes |
@Test public void testSimpleMinusInf() { String textToParse = "# Minimalistic line:\n" + "\n"+ "metric_without_labels -Inf 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>(), Double.NEGATIVE_INFINITY); samples.add(sample); Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_without_labels", Type.UNTYPED, "", samples); expectedList.add(expectedMFS); Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList); // compare compareEMFS(expected, result); }
Example 6
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 7
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 8
Source File: MergableMetricFamilySamples.java From promregator with Apache License 2.0 | 5 votes |
public Enumeration<MetricFamilySamples> getEnumerationMetricFamilySamples() { Collection<MetricFamilySamples> coll = this.map.values(); for (Iterator<MetricFamilySamples> iterator = coll.iterator(); iterator.hasNext();) { MetricFamilySamples mfs = iterator.next(); if (mfs.type == Type.UNTYPED) { log.warn(String.format("Dropping metric %s from set of metrics, as it is untyped and the simpleclient's serialization coding does not properly support this", mfs.name)); iterator.remove(); } } return Collections.enumeration(coll); }
Example 9
Source File: Parser.java From promregator with Apache License 2.0 | 5 votes |
private void parseMetric(String line) { final MetricLine ml = new MetricLine(line); Sample sample = null; try { sample = ml.parse(); } catch (MetricLine.ParseException e) { log.warn(String.format("Detected non-parsable metric line '%s'", line), e); return; } final String metricName = sample.name; Collector.Type type = determineType(metricName); if (type == Type.UNTYPED) { log.info(String.format("Definition of metric %s without type information (assuming untyped)", metricName)); } if (type.equals(Collector.Type.COUNTER) || type.equals(Collector.Type.GAUGE) || type.equals(Collector.Type.UNTYPED)) { this.storeSimpleType(sample, metricName, type); } else if (type.equals(Collector.Type.HISTOGRAM) || type.equals(Collector.Type.SUMMARY)) { this.storeComplexType(sample, metricName, type); } else { log.warn(String.format("Unknown type %s; unclear how to handle this; skipping", type.toString())); // return; can be skipped here } }
Example 10
Source File: ParserTest.java From promregator with Apache License 2.0 | 5 votes |
@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"; 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("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, "", samples); expectedList.add(expectedMFS); Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList); // compare compareEMFS(expected, result); }
Example 11
Source File: ParserTest.java From promregator with Apache License 2.0 | 5 votes |
@Test public void testSimpleWithLabelIncludingBraces() { String textToParse = "# Finally a summary, which has a complex representation, too:\n" + "rpc_duration_seconds{name=\"val/{ue}\",quantile=\"0.01\",} 3102\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("quantile"); List<String> labelValues = new LinkedList<>(); labelValues.add("val/{ue}"); labelValues.add("0.01"); Sample sample = new Sample("rpc_duration_seconds", labelNames, labelValues, 3102); samples.add(sample); Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("rpc_duration_seconds", Type.UNTYPED, "", samples); expectedList.add(expectedMFS); Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList); // compare compareEMFS(expected, result); }
Example 12
Source File: MergableMetricFamilySamplesTest.java From promregator with Apache License 2.0 | 4 votes |
@Test public void testUntypedMetricEnumeration() { MergableMetricFamilySamples subject = new MergableMetricFamilySamples(); List<Sample> samples = new LinkedList<>(); MetricFamilySamples mfs = new MetricFamilySamples("dummy", Type.UNTYPED, "somehelp", samples); List<MetricFamilySamples> list = new LinkedList<>(); list.add(mfs); HashMap<String, MetricFamilySamples> hmmfs = new HashMap<>(); hmmfs.put("dummy", mfs); subject.merge(hmmfs); Enumeration<MetricFamilySamples> returnedEMFS = subject.getEnumerationMetricFamilySamples(); Assert.assertFalse(returnedEMFS.hasMoreElements()); }