Open Kilda Java Documentation
MeterConfigMetricGenBolt.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.wfm.topology.stats.metrics;
17 
20 
29 
30 import com.google.common.collect.ImmutableMap;
31 import org.apache.storm.tuple.Tuple;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 
35 import java.util.Map;
36 
38  private static final Logger LOGGER = LoggerFactory.getLogger(MeterConfigMetricGenBolt.class);
39 
40  @Override
41  public void execute(Tuple input) {
42  StatsComponentType componentId = StatsComponentType.valueOf(input.getSourceComponent());
43  InfoMessage message = (InfoMessage) input.getValueByField(MESSAGE_FIELD);
44 
45  if (!Destination.WFM_STATS.equals(message.getDestination())) {
46  collector.ack(input);
47  return;
48  }
49 
50  LOGGER.debug("Meter config stats message: {}={}, component={}, stream={}",
51  CORRELATION_ID, message.getCorrelationId(), componentId,
52  StatsStreamType.valueOf(input.getSourceStreamId()));
54  long timestamp = message.getTimestamp();
55 
56  try {
57  SwitchId switchId = data.getSwitchId();
58  for (MeterConfigReply reply : data.getStats()) {
59  for (Long meterId : reply.getMeterIds()) {
60  emit(timestamp, meterId, switchId);
61  }
62  }
63  } finally {
64  collector.ack(input);
65  }
66  }
67 
68  private void emit(long timestamp, Long meterId, SwitchId switchId) {
69  try {
70  Map<String, String> tags = ImmutableMap.of(
71  "switchid", switchId.toOtsdFormat(),
72  "meterId", meterId.toString()
73  );
74  collector.emit(tuple("pen.switch.meters", timestamp, meterId, tags));
75  } catch (JsonEncodeException e) {
76  LOGGER.error("Error during serialization of datapoint", e);
77  }
78  }
79 }
static List< Object > tuple(String metric, long timestamp, Number value, Map< String, String > tag)
static final String CORRELATION_ID
Definition: Utils.java:43