Search in sources :

Example 1 with Labeled

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

the class MetricProviderTest method testCounterWith5Labels.

@Test
public void testCounterWith5Labels() {
    Labeled<Labeled<Labeled<Labeled<Labeled<Counter>>>>> counterWithFiveLabels = metrics.newCounter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_counter2").build(), "label1", "label2", "label3", "label4", "label5");
    Counter counterA = counterWithFiveLabels.label("l1").label("l2").label("l3").label("l4").label("l5");
    counterA.increment(5);
    assertThat(counterA.get()).isEqualTo(5);
    Counter againCounterA = counterWithFiveLabels.label("l1").label("l2").label("l3").label("l4").label("l5");
    assertThat(againCounterA.get()).isEqualTo(5);
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) Labeled(org.opendaylight.infrautils.metrics.Labeled) Test(org.junit.Test)

Example 2 with Labeled

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

the class MetricProviderTest method testTimeCallableWithLabels.

@Test
public void testTimeCallableWithLabels() {
    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");
    assertThat(timerA.time(() -> {
        @Var int sum = 0;
        for (int i = 1; i < 101; i++) {
            sum += i;
        }
        return sum;
    })).isEqualTo(5050);
}
Also used : Timer(org.opendaylight.infrautils.metrics.Timer) Var(com.google.errorprone.annotations.Var) Labeled(org.opendaylight.infrautils.metrics.Labeled) Test(org.junit.Test)

Example 3 with Labeled

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

the class BgpCounters method getCounter.

/**
 * Returns the counter.
 * This method returns counter and also creates counter if does not exist.
 *
 * @param counterName name of the counter.
 * @param asValue as value.
 * @param rxValue rx value.
 * @param txValue tx value.
 * @param neighborIp neighbor Ipaddress.
 * @param rdValue rd value.
 * @return counter object.
 */
private Counter getCounter(String counterName, String asValue, String rxValue, String txValue, String neighborIp, String rdValue) {
    String counterTypeEntityCounter = "entitycounter";
    String labelKeyEntityType = "entitytype";
    String labelValEntityTypeBgpPeer = "bgp-peer";
    String labelKeyAsId = "asid";
    String labelKeyNeighborIp = "neighborip";
    String labelValEntityTypeBgpRd = "bgp-rd";
    String labelKeyRd = "rd";
    String counterTypeAggregateCounter = "aggregatecounter";
    String labelKeyCounterName = "name";
    Counter counter = null;
    if (rxValue != null) {
        /*
             * Following is the key pattern for Counter BgpNeighborPacketsReceived
             * netvirt.bgpmanager.entitycounter{entitytype=bgp-peer, asid=value, neighborip=value, name=countername}
             * */
        Labeled<Labeled<Labeled<Labeled<Counter>>>> labeledCounter = metricProvider.newCounter(MetricDescriptor.builder().anchor(this).project("netvirt").module("bgpmanager").id(counterTypeEntityCounter).build(), labelKeyEntityType, labelKeyAsId, labelKeyNeighborIp, labelKeyCounterName);
        counter = labeledCounter.label(labelValEntityTypeBgpPeer).label(asValue).label(neighborIp).label(counterName);
    } else if (txValue != null) {
        /*
             * Following is the key pattern for Counter BgpNeighborPacketsSent
             * netvirt.bgpmanager.entitycounter{entitytype=bgp-peer, asid=value, neighborip=value, name=countername}
             * */
        Labeled<Labeled<Labeled<Labeled<Counter>>>> labeledCounter = metricProvider.newCounter(MetricDescriptor.builder().anchor(this).project("netvirt").module("bgpmanager").id(counterTypeEntityCounter).build(), labelKeyEntityType, labelKeyAsId, labelKeyNeighborIp, labelKeyCounterName);
        counter = labeledCounter.label(labelValEntityTypeBgpPeer).label(asValue).label(neighborIp).label(counterName);
    } else if (rdValue != null) {
        /*
             * Following is the key pattern for Counter BgpRdRouteCount
             * netvirt.bgpmanager.entitycounter{entitytype=bgp-rd, rd=value, name=countername}
             * */
        Labeled<Labeled<Labeled<Counter>>> labeledCounter = metricProvider.newCounter(MetricDescriptor.builder().anchor(this).project("netvirt").module("bgpmanager").id(counterTypeEntityCounter).build(), labelKeyEntityType, labelKeyRd, labelKeyCounterName);
        counter = labeledCounter.label(labelValEntityTypeBgpRd).label(rdValue).label(counterName);
    } else {
        /*
             * Following is the key pattern for Counter BgpTotalPrefixes:Bgp_Total_Prefixes
             * netvirt.bgpmanager.aggregatecounter{name=countername}
             * */
        Labeled<Counter> labeledCounter = metricProvider.newCounter(MetricDescriptor.builder().anchor(this).project("netvirt").module("bgpmanager").id(counterTypeAggregateCounter).build(), labelKeyCounterName);
        counter = labeledCounter.label(counterName);
    }
    return counter;
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) Labeled(org.opendaylight.infrautils.metrics.Labeled)

Example 4 with Labeled

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

the class NodeConnectorStatsImpl method getCounter.

/*
     * This method returns counter and also creates counter if does not exist.
     *
     * @param counterName name of the counter
     * @param switchId datapath-id value
     * @param port port-id value
     * @param aliasId alias-id value
     * @param tableId table-id value of switch
     * @return counter object
     */
private Counter getCounter(String counterName, BigInteger switchId, String port, String aliasId, String tableId) {
    /*
         * Pattern to be followed for key generation:
         *
         * genius.interfacemanager.entitycounter{entitytype=port,switchid=value,portid=value,aliasid=value,
         * name=counterName}
         * genius.interfacemanager.entitycounter{entitytype=flowtable,switchid=value,flowtableid=value,name=counterName}
         */
    Counter counter = null;
    if (port != null) {
        Labeled<Labeled<Labeled<Labeled<Labeled<Counter>>>>> labeledCounter = metricProvider.newCounter(MetricDescriptor.builder().anchor(this).project("genius").module("interfacemanager").id(CounterConstants.CNT_TYPE_ENTITY_CNT_ID).build(), CounterConstants.LBL_KEY_ENTITY_TYPE, CounterConstants.LBL_KEY_SWITCHID, CounterConstants.LBL_KEY_PORTID, CounterConstants.LBL_KEY_ALIASID, CounterConstants.LBL_KEY_COUNTER_NAME);
        counter = labeledCounter.label(CounterConstants.LBL_VAL_ENTITY_TYPE_PORT).label(switchId.toString()).label(port).label(aliasId).label(counterName);
    }
    if (tableId != null) {
        Labeled<Labeled<Labeled<Labeled<Counter>>>> labeledCounter = metricProvider.newCounter(MetricDescriptor.builder().anchor(this).project("genius").module("interfacemanager").id(CounterConstants.CNT_TYPE_ENTITY_CNT_ID).build(), CounterConstants.LBL_KEY_ENTITY_TYPE, CounterConstants.LBL_KEY_SWITCHID, CounterConstants.LBL_KEY_FLOWTBLID, CounterConstants.LBL_KEY_COUNTER_NAME);
        counter = labeledCounter.label(CounterConstants.LBL_VAL_ENTITY_TYPE_FLOWTBL).label(switchId.toString()).label(tableId).label(counterName);
    }
    // create counters set for node if absent.
    // and then populate counter set with counter object
    // which will be needed to close counters when node is removed.
    metricsCountersPerNodeMap.computeIfAbsent(switchId, counterSet -> ConcurrentHashMap.newKeySet()).add(counter);
    return counter;
}
Also used : InterfaceChildEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info._interface.parent.entry.InterfaceChildEntry) ScheduledFuture(java.util.concurrent.ScheduledFuture) MetricDescriptor(org.opendaylight.infrautils.metrics.MetricDescriptor) UncheckedCloseable(org.opendaylight.infrautils.utils.UncheckedCloseable) LoggerFactory(org.slf4j.LoggerFactory) AsyncClusteredDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase) GetFlowStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput) PreDestroy(javax.annotation.PreDestroy) Future(java.util.concurrent.Future) InterfaceChildCache(org.opendaylight.genius.interfacemanager.listeners.InterfaceChildCache) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Optional(com.google.common.base.Optional) NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId) Map(java.util.Map) BigInteger(java.math.BigInteger) ThreadFactory(java.util.concurrent.ThreadFactory) GetFlowStatisticsInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInputBuilder) GetFlowStatisticsInput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInput) GetNodeConnectorStatisticsInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsInputBuilder) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) EntityOwnershipUtils(org.opendaylight.genius.utils.clustering.EntityOwnershipUtils) IfmConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.config.rev160406.IfmConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) Set(java.util.Set) Executors(java.util.concurrent.Executors) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) OpendaylightDirectStatisticsService(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.OpendaylightDirectStatisticsService) NodeConnectorStatisticsAndPortNumberMap(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap) List(java.util.List) GetNodeConnectorStatisticsInput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsInput) Labeled(org.opendaylight.infrautils.metrics.Labeled) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) IfmConstants(org.opendaylight.genius.interfacemanager.IfmConstants) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) MetricProvider(org.opendaylight.infrautils.metrics.MetricProvider) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) JdkFutureAdapters(com.google.common.util.concurrent.JdkFutureAdapters) Inject(javax.inject.Inject) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Nonnull(javax.annotation.Nonnull) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) Logger(org.slf4j.Logger) FutureCallback(com.google.common.util.concurrent.FutureCallback) TimeUnit(java.util.concurrent.TimeUnit) Futures(com.google.common.util.concurrent.Futures) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) PortNameCache(org.opendaylight.genius.interfacemanager.listeners.PortNameCache) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Counter(org.opendaylight.infrautils.metrics.Counter) GetNodeConnectorStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsOutput) Counter(org.opendaylight.infrautils.metrics.Counter) Labeled(org.opendaylight.infrautils.metrics.Labeled)

Example 5 with Labeled

use of org.opendaylight.infrautils.metrics.Labeled 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)

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