Search in sources :

Example 1 with Meter

use of org.opendaylight.infrautils.metrics.Meter in project infrautils by opendaylight.

the class MetricProviderTest method testMeter.

@Test
public void testMeter() {
    Meter meter1 = metrics.newMeter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_meter1").build());
    meter1.mark();
    meter1.mark(2);
    assertThat(meter1.get()).isEqualTo(3);
}
Also used : Meter(org.opendaylight.infrautils.metrics.Meter) Test(org.junit.Test)

Example 2 with Meter

use of org.opendaylight.infrautils.metrics.Meter 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 3 with Meter

use of org.opendaylight.infrautils.metrics.Meter in project infrautils by opendaylight.

the class MetricProviderTest method testMeterWith2Labels.

@Test
public void testMeterWith2Labels() {
    Labeled<Labeled<Meter>> meterWithTwoLabels = metrics.newMeter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_meter1").build(), "port", "mac");
    Meter meterA = meterWithTwoLabels.label(/* port */
    "456").label(/* MAC */
    "1A:0B:F2:25:1C:68");
    meterA.mark(3);
    assertThat(meterA.get()).isEqualTo(3);
    Meter meterB = meterWithTwoLabels.label(/* port */
    "789").label(/* MAC */
    "1A:0B:F2:25:1C:68");
    meterB.mark(1);
    assertThat(meterB.get()).isEqualTo(1);
    assertThat(meterA.get()).isEqualTo(3);
    Meter againMeterA = meterWithTwoLabels.label(/* port */
    "456").label(/* MAC */
    "1A:0B:F2:25:1C:68");
    assertThat(againMeterA.get()).isEqualTo(3);
}
Also used : Meter(org.opendaylight.infrautils.metrics.Meter) Labeled(org.opendaylight.infrautils.metrics.Labeled) Test(org.junit.Test)

Example 4 with Meter

use of org.opendaylight.infrautils.metrics.Meter in project infrautils by opendaylight.

the class MetricProviderTest method testUseClosedMeter.

@Test
public void testUseClosedMeter() {
    Meter meter1 = metrics.newMeter(this, "test.meter1");
    meter1.close();
    assertThrows(IllegalStateException.class, meter1::mark);
    // Closing an already closed metric throws an IllegalStateException
    assertThrows(IllegalStateException.class, meter1::close);
}
Also used : Meter(org.opendaylight.infrautils.metrics.Meter) Test(org.junit.Test)

Example 5 with Meter

use of org.opendaylight.infrautils.metrics.Meter in project infrautils by opendaylight.

the class MetricProviderTest method testCloseMeterAndCreateNewOneWithSameID.

@Test
public void testCloseMeterAndCreateNewOneWithSameID() {
    Meter meter = metrics.newMeter(this, "test.meter");
    meter.close();
    Meter meterAgain = metrics.newMeter(this, "test.meter");
    meterAgain.mark();
}
Also used : Meter(org.opendaylight.infrautils.metrics.Meter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 Meter (org.opendaylight.infrautils.metrics.Meter)8 MetricProvider (org.opendaylight.infrautils.metrics.MetricProvider)4 CollectorRegistrySingleton (org.opendaylight.infrautils.metrics.prometheus.impl.CollectorRegistrySingleton)4 PrometheusMetricProviderImpl (org.opendaylight.infrautils.metrics.prometheus.impl.PrometheusMetricProviderImpl)4 Labeled (org.opendaylight.infrautils.metrics.Labeled)1