use of io.prometheus.client.Collector.MetricFamilySamples in project instrumentation-java by census-instrumentation.
the class PrometheusExportUtilsTest method createDescribableMetricFamilySamples_WithNamespace.
@Test
public void createDescribableMetricFamilySamples_WithNamespace() {
String namespace1 = "myorg";
assertThat(PrometheusExportUtils.createDescribableMetricFamilySamples(CUMULATIVE_METRIC_DESCRIPTOR, namespace1)).isEqualTo(new MetricFamilySamples(namespace1 + '_' + METRIC_NAME, Type.COUNTER, METRIC_DESCRIPTION, Collections.<Sample>emptyList()));
String namespace2 = "opencensus/";
assertThat(PrometheusExportUtils.createDescribableMetricFamilySamples(CUMULATIVE_METRIC_DESCRIPTOR, namespace2)).isEqualTo(new MetricFamilySamples("opencensus_" + METRIC_NAME, Type.COUNTER, METRIC_DESCRIPTION, Collections.<Sample>emptyList()));
}
use of io.prometheus.client.Collector.MetricFamilySamples 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));
}
use of io.prometheus.client.Collector.MetricFamilySamples in project promregator by promregator.
the class MFSUtils method convertToEMFSToHashMap.
public static HashMap<String, MetricFamilySamples> convertToEMFSToHashMap(Enumeration<MetricFamilySamples> emfs) {
HashMap<String, MetricFamilySamples> map = new HashMap<>();
while (emfs.hasMoreElements()) {
MetricFamilySamples mfs = emfs.nextElement();
map.put(mfs.name, mfs);
}
return map;
}
use of io.prometheus.client.Collector.MetricFamilySamples in project promregator by promregator.
the class MergableMetricFamilySamples method merge.
public void merge(HashMap<String, MetricFamilySamples> others) {
for (Entry<String, MetricFamilySamples> entry : others.entrySet()) {
String metricName = entry.getKey();
MetricFamilySamples otherMFS = entry.getValue();
MetricFamilySamples mfs = this.map.get(metricName);
if (mfs == null) {
this.map.put(metricName, otherMFS);
continue;
}
if (otherMFS.type != mfs.type) {
log.warn(String.format("Attempt to merge metric %s, but types are deviating: %s vs. %s", metricName, otherMFS.toString(), mfs.toString()));
continue;
}
mfs.samples.addAll(otherMFS.samples);
}
}
use of io.prometheus.client.Collector.MetricFamilySamples in project promregator by promregator.
the class MergableMetricFamilySamples method toType004String.
public String toType004String() {
Enumeration<MetricFamilySamples> resultEMFS = this.getEnumerationMetricFamilySamples();
Writer writer = new StringWriter();
try {
TextFormat.write004(writer, resultEMFS);
} catch (IOException e) {
log.error("IO Exception on StringWriter; uuuhhh...", e);
}
return writer.toString();
}
Aggregations