Java Code Examples for io.prometheus.client.Collector.Type#COUNTER

The following examples show how to use io.prometheus.client.Collector.Type#COUNTER . 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 vote down vote up
@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";
	
	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.COUNTER, "", 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 vote down vote up
@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";
	
	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.COUNTER, "this is my help text", 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 vote down vote up
@Test
public void testHelpEscaping() {
	String textToParse = "# Simple metric without labels:\n" + 
			"# TYPE metric_without_labels counter\n" + 
			"# HELP metric_without_labels this is my help text with \\\\ backslashes escaped \\\\ and escaped newline \\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.COUNTER, "this is my help text with \\ backslashes escaped \\ and escaped newline \n", 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 vote down vote up
@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 vote down vote up
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: MergableMetricFamilySamplesTest.java    From promregator with Apache License 2.0 3 votes vote down vote up
@Test
public void testStraightFowardEnumeration() {
	MergableMetricFamilySamples subject = new MergableMetricFamilySamples();
	
	List<Sample> samples = new LinkedList<>();
	MetricFamilySamples mfs = new MetricFamilySamples("dummy", Type.COUNTER, "somehelp", samples);
	
	List<MetricFamilySamples> list = new LinkedList<>();
	list.add(mfs);
	
	Enumeration<MetricFamilySamples> emfs = new Vector<MetricFamilySamples>(list).elements();
	
	subject.merge(emfs);
	
	Enumeration<MetricFamilySamples> returnedEMFS = subject.getEnumerationMetricFamilySamples();
	
	Assert.assertTrue(returnedEMFS.hasMoreElements());
	MetricFamilySamples element = returnedEMFS.nextElement();
	Assert.assertFalse(returnedEMFS.hasMoreElements());
	
	Assert.assertEquals(mfs, element);
	
	HashMap<String, MetricFamilySamples> returnedHMMFS = subject.getEnumerationMetricFamilySamplesInHashMap();
	Assert.assertEquals(1, returnedHMMFS.size());
	Assert.assertEquals(mfs, returnedHMMFS.get("dummy"));
	
}
 
Example 7
Source File: MergableMetricFamilySamplesTest.java    From promregator with Apache License 2.0 3 votes vote down vote up
@Test
public void testStraightFowardHashMap() {
	MergableMetricFamilySamples subject = new MergableMetricFamilySamples();
	
	List<Sample> samples = new LinkedList<>();
	MetricFamilySamples mfs = new MetricFamilySamples("dummy", Type.COUNTER, "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.assertTrue(returnedEMFS.hasMoreElements());
	MetricFamilySamples element = returnedEMFS.nextElement();
	Assert.assertFalse(returnedEMFS.hasMoreElements());
	
	Assert.assertEquals(mfs, element);
	
	HashMap<String, MetricFamilySamples> returnedHMMFS = subject.getEnumerationMetricFamilySamplesInHashMap();
	Assert.assertEquals(1, returnedHMMFS.size());
	Assert.assertEquals(mfs, returnedHMMFS.get("dummy"));

}