Search in sources :

Example 6 with Labeled

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

the class MetricProviderTest method testTimeRunnableOKWithLabels.

@Test
public void testTimeRunnableOKWithLabels() {
    Labeled<Labeled<Timer>> timerWithTwoLabels = metrics.newTimer(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_timer_with_labels").build(), "l1", "l2");
    Timer timerA = timerWithTwoLabels.label("l1value").label("l2value");
    timerA.time(() -> {
        for (@SuppressWarnings("unused") int sum = 0, i = 1; i < 101; i++) {
            sum += i;
        }
    });
}
Also used : Timer(org.opendaylight.infrautils.metrics.Timer) Labeled(org.opendaylight.infrautils.metrics.Labeled) Test(org.junit.Test)

Example 7 with Labeled

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

the class MetricProviderTest method testCounterWith2Labels.

@Test
public void testCounterWith2Labels() {
    Labeled<Labeled<Counter>> counterWithTwoLabels = metrics.newCounter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_counter1").build(), "port", "mac");
    Counter counterA = counterWithTwoLabels.label(/* port */
    "456").label(/* MAC */
    "1A:0B:F2:25:1C:68");
    counterA.increment(3);
    assertThat(counterA.get()).isEqualTo(3);
    Counter counterB = counterWithTwoLabels.label(/* port */
    "789").label(/* MAC */
    "1A:0B:F2:25:1C:68");
    counterB.increment(1);
    assertThat(counterB.get()).isEqualTo(1);
    assertThat(counterA.get()).isEqualTo(3);
    Counter againCounterA = counterWithTwoLabels.label(/* port */
    "456").label(/* MAC */
    "1A:0B:F2:25:1C:68");
    assertThat(againCounterA.get()).isEqualTo(3);
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) Labeled(org.opendaylight.infrautils.metrics.Labeled) Test(org.junit.Test)

Example 8 with Labeled

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

the class MetricProviderTest method testSameCounterUpdateOperationsWithLabels.

@Test
public void testSameCounterUpdateOperationsWithLabels() {
    Labeled<Labeled<Counter>> counterWithTwoLabels = metrics.newCounter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_counter_upd_opers").build(), "l1", "l2");
    Counter counterA = counterWithTwoLabels.label("l1value").label("l2value");
    counterA.increment(51);
    assertThat(counterA.get()).isEqualTo(51);
    counterA.decrement();
    assertThat(counterA.get()).isEqualTo(50);
    Labeled<Labeled<Counter>> sameCounterWithTwoLabels = metrics.newCounter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_counter_upd_opers").build(), "l1", "l2");
    Counter sameCounterA = sameCounterWithTwoLabels.label("l1value").label("l2value");
    assertThat(sameCounterA).isEqualTo(counterA);
    assertThat(sameCounterA.get()).isEqualTo(50);
    sameCounterA.increment(5);
    assertThat(sameCounterA.get()).isEqualTo(55);
    sameCounterA.decrement(10);
    assertThat(sameCounterA.get()).isEqualTo(45);
    sameCounterA.close();
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) Labeled(org.opendaylight.infrautils.metrics.Labeled) Test(org.junit.Test)

Example 9 with Labeled

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

the class MetricProviderTest method testCounterOperationsWithLabels.

@Test
public void testCounterOperationsWithLabels() {
    Labeled<Labeled<Counter>> counterWithTwoLabels = metrics.newCounter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_counter_opers").build(), "l1", "l2");
    Counter counterA = counterWithTwoLabels.label("l1value").label("l2value");
    counterA.increment();
    counterA.increment();
    assertThat(counterA.get()).isEqualTo(2);
    counterA.decrement();
    assertThat(counterA.get()).isEqualTo(1);
    counterA.increment(5);
    assertThat(counterA.get()).isEqualTo(6);
    counterA.decrement(2);
    assertThat(counterA.get()).isEqualTo(4);
    counterA.close();
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) Labeled(org.opendaylight.infrautils.metrics.Labeled) Test(org.junit.Test)

Aggregations

Labeled (org.opendaylight.infrautils.metrics.Labeled)9 Test (org.junit.Test)7 Counter (org.opendaylight.infrautils.metrics.Counter)6 Timer (org.opendaylight.infrautils.metrics.Timer)2 Optional (com.google.common.base.Optional)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 JdkFutureAdapters (com.google.common.util.concurrent.JdkFutureAdapters)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Var (com.google.errorprone.annotations.Var)1 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1