Search in sources :

Example 1 with DatapointEntries

use of org.openkilda.messaging.info.DatapointEntries in project open-kilda by telstra.

the class DatapointParseBolt method execute.

@Override
public void execute(Tuple tuple) {
    if (ZooKeeperSpout.SPOUT_ID.equals(tuple.getSourceComponent())) {
        LifecycleEvent event = (LifecycleEvent) tuple.getValueByField(FIELD_ID_LIFECYCLE_EVENT);
        if (event != null && shouldHandleLifeCycleEvent(event.getSignal())) {
            handleLifeCycleEvent(tuple, event);
        }
        collector.ack(tuple);
    } else if (active) {
        InfoData data = (InfoData) tuple.getValueByField(MessageKafkaTranslator.FIELD_ID_PAYLOAD);
        LOGGER.debug("Processing datapoint: {}", data);
        try {
            List<Datapoint> datapoints;
            Object payload = tuple.getValueByField(MessageKafkaTranslator.FIELD_ID_PAYLOAD);
            if (payload instanceof Datapoint) {
                LOGGER.debug("Processing datapoint: {}", payload);
                datapoints = Collections.singletonList((Datapoint) payload);
            } else if (payload instanceof DatapointEntries) {
                LOGGER.debug("Processing datapoints: {}", payload);
                datapoints = ((DatapointEntries) payload).getDatapointEntries();
            } else {
                LOGGER.error("Unhandled input tuple from {} with data {}", getClass().getName(), payload);
                return;
            }
            for (Datapoint datapoint : datapoints) {
                collector.emit(asList(datapoint.simpleHashCode(), datapoint));
            }
        } catch (Exception e) {
            LOGGER.error("Failed process data: {}", data, e);
        } finally {
            collector.ack(tuple);
        }
    } else {
        LOGGER.debug("DatapointParseBolt is inactive");
        collector.ack(tuple);
    }
}
Also used : Datapoint(org.openkilda.messaging.info.Datapoint) InfoData(org.openkilda.messaging.info.InfoData) LifecycleEvent(org.openkilda.bluegreen.LifecycleEvent) DatapointEntries(org.openkilda.messaging.info.DatapointEntries) Arrays.asList(java.util.Arrays.asList) List(java.util.List)

Example 2 with DatapointEntries

use of org.openkilda.messaging.info.DatapointEntries in project open-kilda by telstra.

the class PushToStreamMeterRegistry method pushMeters.

/**
 * Push the current values of registered meters to the specified stream.
 */
public void pushMeters(OutputCollector collector, String streamId) {
    try {
        List<Datapoint> datapoints = new ArrayList<>();
        for (Meter meter : getMeters()) {
            datapoints.addAll(meter.match(this::writeGauge, this::writeCounter, this::writeTimer, this::writeSummary, this::writeLongTaskTimer, this::writeTimeGauge, this::writeFunctionCounter, this::writeFunctionTimer, this::writeCustomMeter));
        }
        String payload = Utils.MAPPER.writeValueAsString(new DatapointEntries(datapoints));
        log.debug("Pushing datapoint(s) {}", payload);
        collector.emit(streamId, Collections.singletonList(payload));
    } catch (Exception ex) {
        log.warn("Failed to send metrics", ex);
    }
}
Also used : Datapoint(org.openkilda.messaging.info.Datapoint) Meter(io.micrometer.core.instrument.Meter) DefaultMeter(io.micrometer.core.instrument.internal.DefaultMeter) ArrayList(java.util.ArrayList) DatapointEntries(org.openkilda.messaging.info.DatapointEntries)

Aggregations

Datapoint (org.openkilda.messaging.info.Datapoint)2 DatapointEntries (org.openkilda.messaging.info.DatapointEntries)2 Meter (io.micrometer.core.instrument.Meter)1 DefaultMeter (io.micrometer.core.instrument.internal.DefaultMeter)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 LifecycleEvent (org.openkilda.bluegreen.LifecycleEvent)1 InfoData (org.openkilda.messaging.info.InfoData)1