use of org.opennms.nrtg.api.model.MeasurementSet in project opennms by OpenNMS.
the class CollectionJobListener method onMessage.
@Override
public void onMessage(Message message) {
try {
// FIXME abstraction between technology and job handling is missing
CollectionJob collectionJob = (CollectionJob) simpleMessageConverter.fromMessage(message);
collectionJob = protocolCollectorRegistry.getProtocolCollector(collectionJob.getService()).collect(collectionJob);
Date finishedTimestamp = new Date();
collectionJob.setFinishedTimestamp(finishedTimestamp);
Map<String, MeasurementSet> measurementSets = collectionJob.getMeasurementSetsByDestination();
int val = counter.incrementAndGet();
if (val % 1000 == 0) {
logger.debug("processed job #{}, {} measurement set(s)", val, measurementSets.size());
} else {
logger.trace("processed job #{}, {} measurement set(s)", val, measurementSets.size());
}
for (String destinationString : measurementSets.keySet()) {
jmsTemplate.convertAndSend(destinationString, measurementSets.get(destinationString));
logger.info("** sending msg '{}' to '{}'", measurementSets.get(destinationString), destinationString);
}
LightweightMeasurementSet errorMeasurementSet = new LightweightMeasurementSet(collectionJob.getNodeId(), collectionJob.getService(), collectionJob.getNetInterface(), collectionJob.getFinishedTimestamp());
for (String metricId : collectionJob.getAllMetrics()) {
if (collectionJob.getMetricValue(metricId) == null) {
errorMeasurementSet.addMeasurement(metricId, collectionJob.getMetricType(metricId), null, collectionJob.getOnmsLogicMetricId(metricId));
}
logger.trace("collected metric of job #{}='{}'", counter + ": " + metricId, collectionJob.getMetricValue(metricId));
}
if (errorMeasurementSet.getMeasurements().size() > 0) {
logger.warn("result set of job #{} contains {} null values", counter, errorMeasurementSet.getMeasurements().size());
jmsTemplate.convertAndSend("error", errorMeasurementSet);
logger.trace("** sending to 'error'");
}
} catch (JMSException ex) {
logger.error(ex.getMessage());
// FIXME react, don't continue
} catch (MessageConversionException ex) {
logger.error(ex.getMessage());
// FIXME react, don't continue
}
}
use of org.opennms.nrtg.api.model.MeasurementSet in project opennms by OpenNMS.
the class NrtController method getMeasurementSetsForDestination.
/**
* Will be called by the JS-Graphing-Frontend as http/GET Get Measurements from NrtBroker, transform them into Json and return
* them to the JS-Graphing-Frontend
*
* @param nrtCollectionTaskId
* @return Json Representation of MeasurementeSets for the given nrtCollectionTaskId
*/
public String getMeasurementSetsForDestination(String nrtCollectionTaskId) {
List<MeasurementSet> measurementSets = m_nrtBroker.receiveMeasurementSets(nrtCollectionTaskId);
StringBuffer buffer = new StringBuffer();
for (MeasurementSet measurementSet : measurementSets) {
if (buffer.length() > 0) {
buffer.append(", ");
}
buffer.append(measurementSet.toString());
}
return "{\"measurement_sets\":[" + buffer.toString() + "]}";
}
use of org.opennms.nrtg.api.model.MeasurementSet in project opennms by OpenNMS.
the class NrtBrokerJms method receiveMeasurementSets.
@Override
public List<MeasurementSet> receiveMeasurementSets(String nrtCollectionTaskId) {
List<MeasurementSet> result = new ArrayList<MeasurementSet>();
m_jmsTemplate.setReceiveTimeout(125);
Message message = m_jmsTemplate.receive(nrtCollectionTaskId);
while (message != null) {
MeasurementSet measurementSet;
try {
measurementSet = (MeasurementSet) simpleMessageConverter.fromMessage(message);
result.add(measurementSet);
} catch (JMSException ex) {
logger.error("Error receiving messages", ex);
return result;
} catch (MessageConversionException ex) {
logger.error("Error converting messages", ex);
return result;
}
message = m_jmsTemplate.receive(nrtCollectionTaskId);
}
return result;
}
Aggregations