use of org.rhq.metrics.core.RawNumericMetric in project fabric8 by jboss-fuse.
the class RhqMetricsStorage method store.
@Override
public void store(String type, long timestamp, QueryResult queryResult) {
assertValid();
if (metricsService == null) {
throw new IllegalStateException("No metricsService available!");
}
Map<String, Result<?>> results = queryResult.getResults();
if (results != null) {
Set<RawNumericMetric> data = new HashSet<>();
Set<Map.Entry<String, Result<?>>> entries = results.entrySet();
for (Map.Entry<String, Result<?>> entry : entries) {
String key = entry.getKey();
Result<?> result = entry.getValue();
if (result instanceof MBeanOpersResult) {
MBeanOpersResult opersResult = (MBeanOpersResult) result;
List<MBeanOperResult> operResults = opersResult.getResults();
if (operResults != null) {
for (MBeanOperResult operResult : operResults) {
Object value = operResult.getValue();
Double doubleValue = toDouble(value);
if (doubleValue != null) {
String id = Metrics.metricId(type, opersResult.getRequest());
data.add(new RawNumericMetric(id, doubleValue, timestamp));
}
}
}
} else if (result instanceof MBeanAttrsResult) {
MBeanAttrsResult attrsResult = (MBeanAttrsResult) result;
List<MBeanAttrResult> attrResults = attrsResult.getResults();
if (attrResults != null) {
for (MBeanAttrResult attrResult : attrResults) {
Map<String, Object> attrs = attrResult.getAttrs();
if (attrs != null) {
Set<Map.Entry<String, Object>> attrEntries = attrs.entrySet();
for (Map.Entry<String, Object> attrEntry : attrEntries) {
String attributeName = attrEntry.getKey();
Object value = attrEntry.getValue();
Double doubleValue = toDouble(value);
if (doubleValue != null) {
String id = Metrics.metricId(type, attrsResult.getRequest(), attributeName);
data.add(new RawNumericMetric(id, doubleValue, timestamp));
}
}
}
}
}
}
}
if (!data.isEmpty()) {
metricsService.addData(data);
if (LOG.isDebugEnabled()) {
LOG.debug("added " + data.size() + " metrics");
}
}
}
}
Aggregations