Search in sources :

Example 11 with Counter

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

the class FlowNodeConnectorInventoryTranslatorImpl method nodeRemovedNotification.

public void nodeRemovedNotification(String node) {
    Counter counter;
    String[] switchId = node.split(":");
    counter = packetInCounter.label("OFSwitch").label(String.valueOf(switchId[1])).label("portsperswitch");
    counter.close();
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter)

Example 12 with Counter

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

the class NodeConnectorStatsImpl method processFlowStatistics.

/**
 * This method processes FlowStatistics RPC result.
 * It performs:
 * - fetches all flows of node
 * - stores flows count per table in local map
 * - creates/updates Flow table counters using Infrautils metrics API
 * - set counter with values fetched from FlowStatistics
 */
private void processFlowStatistics(GetFlowStatisticsOutput flowStatsOutput, BigInteger dpid) {
    Map<Short, AtomicInteger> flowTableMap = new HashMap<>();
    // Get all flows for node from RPC result
    List<FlowAndStatisticsMapList> flowTableAndStatisticsMapList = flowStatsOutput.getFlowAndStatisticsMapList();
    for (FlowAndStatisticsMapList flowAndStatisticsMap : flowTableAndStatisticsMapList) {
        short tableId = flowAndStatisticsMap.getTableId();
        // populate map to maintain flow count per table
        flowTableMap.computeIfAbsent(tableId, key -> new AtomicInteger(0)).incrementAndGet();
    }
    LOG.trace("FlowTableStatistics (tableId:counter): {} for node: {}", flowTableMap.entrySet(), dpid.toString());
    for (Map.Entry<Short, AtomicInteger> flowTable : flowTableMap.entrySet()) {
        Short tableId = flowTable.getKey();
        AtomicInteger flowCount = flowTable.getValue();
        Counter counter = getCounter(CounterConstants.IFM_FLOW_TBL_COUNTER_FLOWS_PER_TBL, dpid, null, null, tableId.toString());
        // update counter value
        updateCounter(counter, flowCount.longValue());
    }
}
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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NodeConnectorStatisticsAndPortNumberMap(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap) HashMap(java.util.HashMap)

Example 13 with Counter

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

the class NodeConnectorStatsImpl method processNodeConnectorStatistics.

/**
 * This method processes NodeConnectorStatistics RPC result.
 * It performs:
 * - fetches various OF Port counters values
 * - creates/updates new OF Port counters using Infrautils metrics API
 * - set counter with values fetched from NodeConnectorStatistics
 */
private void processNodeConnectorStatistics(GetNodeConnectorStatisticsOutput nodeConnectorStatisticsOutput, BigInteger dpid) {
    String port = "";
    String portUuid = "";
    List<NodeConnectorStatisticsAndPortNumberMap> ncStatsAndPortMapList = nodeConnectorStatisticsOutput.getNodeConnectorStatisticsAndPortNumberMap();
    // Parse NodeConnectorStatistics and create/update counters for them
    for (NodeConnectorStatisticsAndPortNumberMap ncStatsAndPortMap : ncStatsAndPortMapList) {
        NodeConnectorId nodeConnector = ncStatsAndPortMap.getNodeConnectorId();
        LOG.trace("Create/update metric counter for NodeConnector: {} of node: {}", nodeConnector, dpid.toString());
        port = nodeConnector.getValue();
        // update port name as per port name maintained in portNameCache
        String portNameInCache = "openflow" + ":" + dpid.toString() + ":" + port;
        java.util.Optional<String> portName = portNameCache.get(portNameInCache);
        if (portName.isPresent()) {
            Optional<List<InterfaceChildEntry>> interfaceChildEntries = interfaceChildCache.getInterfaceChildEntries(portName.get());
            if (interfaceChildEntries.isPresent()) {
                if (!interfaceChildEntries.get().isEmpty()) {
                    portUuid = interfaceChildEntries.get().get(0).getChildInterface();
                    LOG.trace("Retrieved portUuid {} for portname {}", portUuid, portName.get());
                } else {
                    LOG.trace("PortUuid is not found for portname {}. Skipping IFM counters publish for this port.", portName.get());
                    continue;
                }
            } else {
                LOG.trace("PortUuid is not found for portname {}. Skipping IFM counters publish for this port.", portName.get());
                continue;
            }
        }
        Counter counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_DURATION, dpid, port, portUuid, null);
        long ofPortDuration = ncStatsAndPortMap.getDuration().getSecond().getValue();
        updateCounter(counter, ofPortDuration);
        counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_PKT_RECVDROP, dpid, port, portUuid, null);
        long packetsPerOFPortReceiveDrop = ncStatsAndPortMap.getReceiveDrops().longValue();
        updateCounter(counter, packetsPerOFPortReceiveDrop);
        counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_PKT_RECVERROR, dpid, port, portUuid, null);
        long packetsPerOFPortReceiveError = ncStatsAndPortMap.getReceiveErrors().longValue();
        updateCounter(counter, packetsPerOFPortReceiveError);
        counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_PKT_SENT, dpid, port, portUuid, null);
        long packetsPerOFPortSent = ncStatsAndPortMap.getPackets().getTransmitted().longValue();
        updateCounter(counter, packetsPerOFPortSent);
        counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_PKT_RECV, dpid, port, portUuid, null);
        long packetsPerOFPortReceive = ncStatsAndPortMap.getPackets().getReceived().longValue();
        updateCounter(counter, packetsPerOFPortReceive);
        counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_BYTE_SENT, dpid, port, portUuid, null);
        long bytesPerOFPortSent = ncStatsAndPortMap.getBytes().getTransmitted().longValue();
        updateCounter(counter, bytesPerOFPortSent);
        counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_BYTE_RECV, dpid, port, portUuid, null);
        long bytesPerOFPortReceive = ncStatsAndPortMap.getBytes().getReceived().longValue();
        updateCounter(counter, bytesPerOFPortReceive);
    }
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId) List(java.util.List) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) NodeConnectorStatisticsAndPortNumberMap(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap)

Example 14 with Counter

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

the class NodeConnectorStatsImpl method remove.

@Override
protected void remove(InstanceIdentifier<Node> identifier, Node node) {
    NodeId nodeId = node.getId();
    String nodeVal = nodeId.getValue().split(":")[1];
    BigInteger dpId = new BigInteger(nodeVal);
    if (nodes.contains(dpId)) {
        nodes.remove(dpId);
        // remove counters set from node
        Set<Counter> nodeMetricCounterSet = metricsCountersPerNodeMap.remove(dpId);
        if (nodeMetricCounterSet != null) {
            // remove counters
            nodeMetricCounterSet.forEach(UncheckedCloseable::close);
        }
    }
    if (nodes.size() > 0) {
        delayStatsQuery = ifmConfig.getIfmStatsDefPollInterval() / nodes.size();
    } else {
        stopPortStatRequestTask();
        delayStatsQuery = 0;
    }
}
Also used : UncheckedCloseable(org.opendaylight.infrautils.utils.UncheckedCloseable) Counter(org.opendaylight.infrautils.metrics.Counter) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) BigInteger(java.math.BigInteger)

Example 15 with Counter

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

Aggregations

Counter (org.opendaylight.infrautils.metrics.Counter)19 Labeled (org.opendaylight.infrautils.metrics.Labeled)7 Test (org.junit.Test)5 BigInteger (java.math.BigInteger)3 List (java.util.List)3 UncheckedCloseable (org.opendaylight.infrautils.utils.UncheckedCloseable)3 FlowAndStatisticsMapList (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList)3 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)3 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)3 NodeConnectorStatisticsAndPortNumberMap (org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap)3 Optional (com.google.common.base.Optional)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 Futures (com.google.common.util.concurrent.Futures)2 JdkFutureAdapters (com.google.common.util.concurrent.JdkFutureAdapters)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2