Search in sources :

Example 1 with PrometheusMetricProviderImpl

use of org.opendaylight.infrautils.metrics.prometheus.impl.PrometheusMetricProviderImpl in project infrautils by opendaylight.

the class PrometheusMetricProviderImplTest method testNewMeterWith1DynamicLabel.

@Test
public void testNewMeterWith1DynamicLabel() {
    MetricProvider metricProvider = new PrometheusMetricProviderImpl(new CollectorRegistrySingleton());
    Labeled<Meter> meterWithLabel = metricProvider.newMeter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_meter1").build(), "jobKey");
    Meter meterA = meterWithLabel.label("ABC");
    meterA.mark(3);
    assertThat(meterA.get()).isEqualTo(3);
    Meter meterB = meterWithLabel.label("DEF");
    meterB.mark(1);
    assertThat(meterB.get()).isEqualTo(1);
    assertThat(meterA.get()).isEqualTo(3);
    Meter againMeterA = meterWithLabel.label("ABC");
    assertThat(againMeterA.get()).isEqualTo(3);
}
Also used : MetricProvider(org.opendaylight.infrautils.metrics.MetricProvider) PrometheusMetricProviderImpl(org.opendaylight.infrautils.metrics.prometheus.impl.PrometheusMetricProviderImpl) Meter(org.opendaylight.infrautils.metrics.Meter) CollectorRegistrySingleton(org.opendaylight.infrautils.metrics.prometheus.impl.CollectorRegistrySingleton) Test(org.junit.Test)

Example 2 with PrometheusMetricProviderImpl

use of org.opendaylight.infrautils.metrics.prometheus.impl.PrometheusMetricProviderImpl in project infrautils by opendaylight.

the class MetricsPrometheusExampleMain method main.

public static void main(String[] args) throws IOException {
    // see also OsgiWebInitializer
    CollectorRegistry collectorRegistry = new CollectorRegistrySingleton();
    PrometheusMetricProviderImpl metricProvider = new PrometheusMetricProviderImpl(collectorRegistry);
    MetricsExample metricsExample = new MetricsExample(metricProvider);
    metricsExample.init();
    HTTPServer server = new HTTPServer(new InetSocketAddress("localhost", 1234), collectorRegistry);
    System.in.read();
    server.stop();
    metricsExample.close();
    metricProvider.close();
}
Also used : HTTPServer(io.prometheus.client.exporter.HTTPServer) PrometheusMetricProviderImpl(org.opendaylight.infrautils.metrics.prometheus.impl.PrometheusMetricProviderImpl) InetSocketAddress(java.net.InetSocketAddress) CollectorRegistry(io.prometheus.client.CollectorRegistry) CollectorRegistrySingleton(org.opendaylight.infrautils.metrics.prometheus.impl.CollectorRegistrySingleton)

Example 3 with PrometheusMetricProviderImpl

use of org.opendaylight.infrautils.metrics.prometheus.impl.PrometheusMetricProviderImpl in project infrautils by opendaylight.

the class PrometheusMetricProviderImplTest method testNewMeterWith1FixedLabel.

@Test
public void testNewMeterWith1FixedLabel() {
    MetricProvider metricProvider = new PrometheusMetricProviderImpl(new CollectorRegistrySingleton());
    Meter meter = metricProvider.newMeter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test").build(), "label1").label("value1");
    meter.mark(123);
    assertThat(meter.get()).isEqualTo(123L);
    meter.close();
}
Also used : MetricProvider(org.opendaylight.infrautils.metrics.MetricProvider) PrometheusMetricProviderImpl(org.opendaylight.infrautils.metrics.prometheus.impl.PrometheusMetricProviderImpl) Meter(org.opendaylight.infrautils.metrics.Meter) CollectorRegistrySingleton(org.opendaylight.infrautils.metrics.prometheus.impl.CollectorRegistrySingleton) Test(org.junit.Test)

Example 4 with PrometheusMetricProviderImpl

use of org.opendaylight.infrautils.metrics.prometheus.impl.PrometheusMetricProviderImpl in project infrautils by opendaylight.

the class PrometheusMetricProviderImplTest method testGetOverflownMeter.

@Test
public void testGetOverflownMeter() {
    MetricProvider metricProvider = new PrometheusMetricProviderImpl(new CollectorRegistrySingleton());
    Meter meter = metricProvider.newMeter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test").build());
    meter.mark(Double.doubleToRawLongBits(Double.MAX_VALUE));
    assertThat(meter.get()).isGreaterThan(1000000L);
}
Also used : MetricProvider(org.opendaylight.infrautils.metrics.MetricProvider) PrometheusMetricProviderImpl(org.opendaylight.infrautils.metrics.prometheus.impl.PrometheusMetricProviderImpl) Meter(org.opendaylight.infrautils.metrics.Meter) CollectorRegistrySingleton(org.opendaylight.infrautils.metrics.prometheus.impl.CollectorRegistrySingleton) Test(org.junit.Test)

Example 5 with PrometheusMetricProviderImpl

use of org.opendaylight.infrautils.metrics.prometheus.impl.PrometheusMetricProviderImpl in project infrautils by opendaylight.

the class PrometheusMetricProviderImplTest method testNewMeter.

@Test
public void testNewMeter() {
    MetricProvider metricProvider = new PrometheusMetricProviderImpl(new CollectorRegistrySingleton());
    Meter meter = metricProvider.newMeter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test").build());
    meter.mark(123);
    assertThat(meter.get()).isEqualTo(123L);
    meter.close();
}
Also used : MetricProvider(org.opendaylight.infrautils.metrics.MetricProvider) PrometheusMetricProviderImpl(org.opendaylight.infrautils.metrics.prometheus.impl.PrometheusMetricProviderImpl) Meter(org.opendaylight.infrautils.metrics.Meter) CollectorRegistrySingleton(org.opendaylight.infrautils.metrics.prometheus.impl.CollectorRegistrySingleton) Test(org.junit.Test)

Aggregations

CollectorRegistrySingleton (org.opendaylight.infrautils.metrics.prometheus.impl.CollectorRegistrySingleton)5 PrometheusMetricProviderImpl (org.opendaylight.infrautils.metrics.prometheus.impl.PrometheusMetricProviderImpl)5 Test (org.junit.Test)4 Meter (org.opendaylight.infrautils.metrics.Meter)4 MetricProvider (org.opendaylight.infrautils.metrics.MetricProvider)4 CollectorRegistry (io.prometheus.client.CollectorRegistry)1 HTTPServer (io.prometheus.client.exporter.HTTPServer)1 InetSocketAddress (java.net.InetSocketAddress)1