Search in sources :

Example 1 with QueryResult

use of io.fabric8.insight.metrics.model.QueryResult 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)

Example 2 with QueryResult

use of io.fabric8.insight.metrics.model.QueryResult in project fabric8 by jboss-fuse.

the class MetricsTest method testDefault.

@Test
public void testDefault() throws Exception {
    Query query = new Query("test", new HashSet<Request>(Arrays.asList(new MBeanAttrs("memory", "java.lang:type=Memory", Arrays.asList("HeapMemoryUsage", "NonHeapMemoryUsage")), new MBeanOpers("deadlocks", "java.lang:type=Threading", "dumpAllThreads", Arrays.<Object>asList(true, true), Arrays.<String>asList(boolean.class.getName(), boolean.class.getName())))), null, null, null, 0, 0);
    System.gc();
    QueryResult qrs = JmxUtils.execute(new Server("local"), query, ManagementFactory.getPlatformMBeanServer());
    String output = new Renderer().render(qrs);
    Map map = new ObjectMapper().readValue(output, Map.class);
    assertEquals("local", map.get("host"));
    assertNotNull(map.get("@timestamp"));
}
Also used : QueryResult(io.fabric8.insight.metrics.model.QueryResult) Query(io.fabric8.insight.metrics.model.Query) Server(io.fabric8.insight.metrics.model.Server) Request(io.fabric8.insight.metrics.model.Request) Renderer(io.fabric8.insight.metrics.mvel.Renderer) MBeanOpers(io.fabric8.insight.metrics.model.MBeanOpers) MBeanAttrs(io.fabric8.insight.metrics.model.MBeanAttrs) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with QueryResult

use of io.fabric8.insight.metrics.model.QueryResult in project fabric8 by jboss-fuse.

the class InfluxDBMetricsStorage method store.

@Override
public void store(String type, long timestamp, QueryResult queryResult) {
    assertValid();
    if (influxDB == null) {
        throw new IllegalStateException("No influxDB available!");
    }
    List<Serie> series = new LinkedList<>();
    Map<String, Result<?>> results = queryResult.getResults();
    if (results != null) {
        Map<String, Object> data = new HashMap<>();
        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.put(id, doubleValue);
                        }
                    }
                }
            } 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.put(id, doubleValue);
                                }
                            }
                        }
                    }
                }
            }
            if (!data.isEmpty()) {
                data.put("time", timestamp);
                series.add(new Serie.Builder("insight").columns(data.keySet().toArray(new String[data.size()])).values(data.values().toArray(new Object[data.size()])).build());
            }
        }
        if (!series.isEmpty()) {
            influxDB.get().write("fabric", TimeUnit.MILLISECONDS, series.toArray(new Serie[series.size()]));
            if (LOG.isDebugEnabled()) {
                LOG.debug("added " + series.size() + " metrics");
            }
        }
    }
}
Also used : MBeanOpersResult(io.fabric8.insight.metrics.model.MBeanOpersResult) Set(java.util.Set) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) 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) LinkedList(java.util.LinkedList) List(java.util.List) Serie(org.influxdb.dto.Serie) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

QueryResult (io.fabric8.insight.metrics.model.QueryResult)3 Map (java.util.Map)3 MBeanAttrResult (io.fabric8.insight.metrics.model.MBeanAttrResult)2 MBeanAttrsResult (io.fabric8.insight.metrics.model.MBeanAttrsResult)2 MBeanOperResult (io.fabric8.insight.metrics.model.MBeanOperResult)2 MBeanOpersResult (io.fabric8.insight.metrics.model.MBeanOpersResult)2 Result (io.fabric8.insight.metrics.model.Result)2 List (java.util.List)2 Set (java.util.Set)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MBeanAttrs (io.fabric8.insight.metrics.model.MBeanAttrs)1 MBeanOpers (io.fabric8.insight.metrics.model.MBeanOpers)1 Query (io.fabric8.insight.metrics.model.Query)1 Request (io.fabric8.insight.metrics.model.Request)1 Server (io.fabric8.insight.metrics.model.Server)1 Renderer (io.fabric8.insight.metrics.mvel.Renderer)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Serie (org.influxdb.dto.Serie)1