Search in sources :

Example 11 with MetricFamilySamples

use of io.prometheus.client.Collector.MetricFamilySamples in project instrumentation-java by census-instrumentation.

the class PrometheusStatsCollectorTest method testDescribe_WithNamespace.

@Test
public void testDescribe_WithNamespace() {
    String namespace = "myorg";
    PrometheusStatsCollector collector = new PrometheusStatsCollector(mockMetricProducerManager, namespace);
    assertThat(collector.describe()).containsExactly(new MetricFamilySamples(namespace + '_' + METRIC_NAME, Type.HISTOGRAM, METRIC_DESCRIPTION, Collections.<Sample>emptyList()));
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Example 12 with MetricFamilySamples

use of io.prometheus.client.Collector.MetricFamilySamples in project instrumentation-java by census-instrumentation.

the class PrometheusStatsCollectorTest method testDescribe.

@Test
public void testDescribe() {
    PrometheusStatsCollector collector = new PrometheusStatsCollector(mockMetricProducerManager, "");
    assertThat(collector.describe()).containsExactly(new MetricFamilySamples(METRIC_NAME, Type.HISTOGRAM, METRIC_DESCRIPTION, Collections.<Sample>emptyList()));
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Example 13 with MetricFamilySamples

use of io.prometheus.client.Collector.MetricFamilySamples in project instrumentation-java by census-instrumentation.

the class PrometheusExportUtilsTest method createDescribableMetricFamilySamples.

@Test
public void createDescribableMetricFamilySamples() {
    assertThat(PrometheusExportUtils.createDescribableMetricFamilySamples(CUMULATIVE_METRIC_DESCRIPTOR, "")).isEqualTo(new MetricFamilySamples(METRIC_NAME, Type.COUNTER, METRIC_DESCRIPTION, Collections.<Sample>emptyList()));
    assertThat(PrometheusExportUtils.createDescribableMetricFamilySamples(SUMMARY_METRIC_DESCRIPTOR, "")).isEqualTo(new MetricFamilySamples(METRIC_NAME2, Type.SUMMARY, METRIC_DESCRIPTION, Collections.<Sample>emptyList()));
    assertThat(PrometheusExportUtils.createDescribableMetricFamilySamples(HISTOGRAM_METRIC_DESCRIPTOR, "")).isEqualTo(new MetricFamilySamples(METRIC_NAME3, Type.HISTOGRAM, METRIC_DESCRIPTION, Collections.<Sample>emptyList()));
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Example 14 with MetricFamilySamples

use of io.prometheus.client.Collector.MetricFamilySamples in project instrumentation-java by census-instrumentation.

the class PrometheusExportUtilsTest method createMetricFamilySamples_WithNamespace.

@Test
public void createMetricFamilySamples_WithNamespace() {
    String namespace = "opencensus_";
    assertThat(PrometheusExportUtils.createMetricFamilySamples(LONG_METRIC, namespace)).isEqualTo(new MetricFamilySamples(namespace + METRIC_NAME, Type.COUNTER, METRIC_DESCRIPTION, Collections.singletonList(new Sample(namespace + METRIC_NAME, Arrays.asList("k1", "k2"), Arrays.asList("v1", "v2"), 123456789))));
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Example 15 with MetricFamilySamples

use of io.prometheus.client.Collector.MetricFamilySamples in project instrumentation-java by census-instrumentation.

the class PrometheusExportUtilsTest method createMetricFamilySamples.

@Test
public void createMetricFamilySamples() {
    assertThat(PrometheusExportUtils.createMetricFamilySamples(LONG_METRIC, "")).isEqualTo(new MetricFamilySamples(METRIC_NAME, Type.COUNTER, METRIC_DESCRIPTION, Collections.singletonList(new Sample(METRIC_NAME, Arrays.asList("k1", "k2"), Arrays.asList("v1", "v2"), 123456789))));
    assertThat(PrometheusExportUtils.createMetricFamilySamples(SUMMARY_METRIC, "")).isEqualTo(new MetricFamilySamples(METRIC_NAME2, Type.SUMMARY, METRIC_DESCRIPTION, Arrays.asList(new Sample(METRIC_NAME2 + "_count", Collections.singletonList("k_3"), Collections.singletonList("v1"), 22), new Sample(METRIC_NAME2 + "_sum", Collections.singletonList("k_3"), Collections.singletonList("v1"), 74.8), new Sample(METRIC_NAME2, Arrays.asList("k_3", LABEL_NAME_QUANTILE), Arrays.asList("v1", "0.99"), 10.2))));
    assertThat(PrometheusExportUtils.createMetricFamilySamples(DISTRIBUTION_METRIC, "")).isEqualTo(new MetricFamilySamples(METRIC_NAME3, Type.HISTOGRAM, METRIC_DESCRIPTION, Arrays.asList(new Sample(METRIC_NAME3 + "_bucket", Arrays.asList("k1", "le"), Arrays.asList("v-3", "1.0"), 0), new Sample(METRIC_NAME3 + "_bucket", Arrays.asList("k1", "le"), Arrays.asList("v-3", "2.0"), 2), new Sample(METRIC_NAME3 + "_bucket", Arrays.asList("k1", "le"), Arrays.asList("v-3", "5.0"), 4), new Sample(METRIC_NAME3 + "_bucket", Arrays.asList("k1", "le"), Arrays.asList("v-3", "+Inf"), 5), new Sample(METRIC_NAME3 + "_count", Collections.singletonList("k1"), Collections.singletonList("v-3"), 5), new Sample(METRIC_NAME3 + "_sum", Collections.singletonList("k1"), Collections.singletonList("v-3"), 22.0))));
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Aggregations

MetricFamilySamples (io.prometheus.client.Collector.MetricFamilySamples)31 Sample (io.prometheus.client.Collector.MetricFamilySamples.Sample)17 Test (org.junit.Test)15 HashMap (java.util.HashMap)9 LinkedList (java.util.LinkedList)8 MergableMetricFamilySamples (org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples)4 IOException (java.io.IOException)3 Collector (io.prometheus.client.Collector)2 Type (io.prometheus.client.Collector.Type)2 Collector.doubleToGoString (io.prometheus.client.Collector.doubleToGoString)2 StringWriter (java.io.StringWriter)2 Writer (java.io.Writer)2 Future (java.util.concurrent.Future)2 CFMetricsFetcher (org.cloudfoundry.promregator.fetcher.CFMetricsFetcher)2 MetricsFetcher (org.cloudfoundry.promregator.fetcher.MetricsFetcher)2 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)1 Timer (io.prometheus.client.Histogram.Timer)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ExecutionException (java.util.concurrent.ExecutionException)1