Search in sources :

Example 11 with Timestamp

use of io.fabric8.maven.docker.util.Timestamp in project fabric8 by jboss-fuse.

the class FabricGitSummaryAction method printVersions.

private void printVersions(String title, List<GitVersion> versions) {
    System.out.println(title);
    TablePrinter table = new TablePrinter();
    table.columns("version", "SHA1", "timestamp", "message");
    for (GitVersion version : versions) {
        table.row(version.getVersion(), version.getSha1(), version.getTimestamp(), version.getMessage());
    }
    table.print();
}
Also used : GitVersion(io.fabric8.api.commands.GitVersion) TablePrinter(io.fabric8.utils.TablePrinter)

Example 12 with Timestamp

use of io.fabric8.maven.docker.util.Timestamp in project fabric8 by jboss-fuse.

the class FabricManagerTest method fromJson.

@Test
public void fromJson() throws IOException {
    JMXResult res = om().readValue("{\"correlationId\":\"id\",\"code\":0,\"message\":\"OK\",\"response\":{\"@class\":\"io.fabric8.api.commands.GitVersions\",\"versions\":[{\"version\":\"1.0\",\"sha1\":\"SHA1\",\"timestamp\":null,\"message\":null},{\"version\":\"1.0\",\"sha1\":\"SHA1\",\"timestamp\":null,\"message\":null},{\"version\":\"1.0\",\"sha1\":\"SHA1\",\"timestamp\":null,\"message\":null}]}}", JMXResult.class);
    assertNotNull(res);
    assertThat(res.getMessage(), equalTo("OK"));
    assertThat(((GitVersions) res.getResponse()).getVersions().get(2).getSha1(), equalTo("SHA1"));
    assertThat(((GitVersions) res.getResponse()).getVersions().size(), equalTo(3));
}
Also used : GitVersions(io.fabric8.api.commands.GitVersions) JMXResult(io.fabric8.api.commands.JMXResult) Test(org.junit.Test)

Example 13 with Timestamp

use of io.fabric8.maven.docker.util.Timestamp 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 14 with Timestamp

use of io.fabric8.maven.docker.util.Timestamp in project fabric8 by jboss-fuse.

the class LogQuery method getLogEventList.

public LogResults getLogEventList(int count, Predicate<PaxLoggingEvent> predicate) {
    LogResults answer = new LogResults();
    answer.setHost(getHostName());
    long from = Long.MAX_VALUE;
    long to = Long.MIN_VALUE;
    if (appender != null) {
        LruList events = appender.getEvents();
        if (events != null) {
            Iterable<PaxLoggingEvent> iterable = events.getElements();
            if (iterable != null) {
                int matched = 0;
                for (PaxLoggingEvent event : iterable) {
                    if (event != null) {
                        long timestamp = event.getTimeStamp();
                        if (timestamp > to) {
                            to = timestamp;
                        }
                        if (timestamp < from) {
                            from = timestamp;
                        }
                        if (predicate == null || predicate.matches(event)) {
                            answer.addEvent(Logs.newInstance(event));
                            matched += 1;
                            if (count > 0 && matched >= count) {
                                break;
                            }
                        }
                    }
                }
            }
        }
    } else {
        LOG.warn("No VmLogAppender available!");
    }
    answer.setFromTimestamp(from);
    answer.setToTimestamp(to);
    return answer;
}
Also used : PaxLoggingEvent(org.ops4j.pax.logging.spi.PaxLoggingEvent) LogResults(io.fabric8.insight.log.LogResults) LruList(org.apache.karaf.shell.log.LruList)

Example 15 with Timestamp

use of io.fabric8.maven.docker.util.Timestamp 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

Timestamp (io.fabric8.maven.docker.util.Timestamp)6 Test (org.junit.Test)6 Expectations (mockit.Expectations)4 QueryResult (io.fabric8.insight.metrics.model.QueryResult)3 Map (java.util.Map)3 LogResults (io.fabric8.insight.log.LogResults)2 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 GitVersion (io.fabric8.api.commands.GitVersion)1 GitVersions (io.fabric8.api.commands.GitVersions)1 JMXResult (io.fabric8.api.commands.JMXResult)1 LogEvent (io.fabric8.insight.log.LogEvent)1 MBeanAttrs (io.fabric8.insight.metrics.model.MBeanAttrs)1 MBeanOpers (io.fabric8.insight.metrics.model.MBeanOpers)1