Search in sources :

Example 1 with RawNumericMetric

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");
            }
        }
    }
}
Also used : MBeanOpersResult(io.fabric8.insight.metrics.model.MBeanOpersResult) HashSet(java.util.HashSet) Set(java.util.Set) RawNumericMetric(org.rhq.metrics.core.RawNumericMetric) MBeanAttrsResult(io.fabric8.insight.metrics.model.MBeanAttrsResult) MBeanAttrsResult(io.fabric8.insight.metrics.model.MBeanAttrsResult) Result(io.fabric8.insight.metrics.model.Result) MBeanAttrResult(io.fabric8.insight.metrics.model.MBeanAttrResult) MBeanOperResult(io.fabric8.insight.metrics.model.MBeanOperResult) QueryResult(io.fabric8.insight.metrics.model.QueryResult) MBeanOpersResult(io.fabric8.insight.metrics.model.MBeanOpersResult) MBeanOperResult(io.fabric8.insight.metrics.model.MBeanOperResult) MBeanAttrResult(io.fabric8.insight.metrics.model.MBeanAttrResult) List(java.util.List) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

MBeanAttrResult (io.fabric8.insight.metrics.model.MBeanAttrResult)1 MBeanAttrsResult (io.fabric8.insight.metrics.model.MBeanAttrsResult)1 MBeanOperResult (io.fabric8.insight.metrics.model.MBeanOperResult)1 MBeanOpersResult (io.fabric8.insight.metrics.model.MBeanOpersResult)1 QueryResult (io.fabric8.insight.metrics.model.QueryResult)1 Result (io.fabric8.insight.metrics.model.Result)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 RawNumericMetric (org.rhq.metrics.core.RawNumericMetric)1