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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations