Search in sources :

Example 6 with Timestamp

use of io.fabric8.maven.docker.util.Timestamp in project docker-maven-plugin by fabric8io.

the class LogMatchCallbackTest method matchingLinesNonConformantToThePatternFails.

@Test
public void matchingLinesNonConformantToThePatternFails() throws Exception {
    final String patterString = "The start has started right now";
    final LogMatchCallback logMatchCallback = new LogMatchCallback(logger, callback, patterString);
    new Expectations() {

        {
            callback.matched();
            times = 0;
        }
    };
    logMatchCallback.log(1, new Timestamp(), "LOG:  database system is ready to accept connections");
}
Also used : Expectations(mockit.Expectations) Timestamp(io.fabric8.maven.docker.util.Timestamp) Test(org.junit.Test)

Example 7 with Timestamp

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

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

the class Log4jLogQuery method filterLogResults.

protected LogResults filterLogResults(Predicate<LogEvent> predicate, int maxCount) {
    int matched = 0;
    long from = Long.MAX_VALUE;
    long to = Long.MIN_VALUE;
    List<LogEvent> list = new ArrayList<LogEvent>();
    Iterable<LoggingEvent> elements = getEvents().getElements();
    for (LoggingEvent element : elements) {
        LogEvent logEvent = toLogEvent(element);
        long timestamp = element.getTimeStamp();
        if (timestamp > to) {
            to = timestamp;
        }
        if (timestamp < from) {
            from = timestamp;
        }
        if (logEvent != null) {
            if (predicate == null || predicate.matches(logEvent)) {
                list.add(logEvent);
                matched += 1;
                if (maxCount > 0 && matched >= maxCount) {
                    break;
                }
            }
        }
    }
    LogResults results = new LogResults();
    results.setEvents(list);
    if (from < Long.MAX_VALUE) {
        results.setFromTimestamp(from);
    }
    if (to > Long.MIN_VALUE) {
        results.setToTimestamp(to);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Requested " + maxCount + " logging items. returning " + results.getEvents().size() + " event(s) from a possible " + getEvents().size());
    }
    return results;
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) LogResults(io.fabric8.insight.log.LogResults) LogEvent(io.fabric8.insight.log.LogEvent) ArrayList(java.util.ArrayList)

Example 9 with Timestamp

use of io.fabric8.maven.docker.util.Timestamp in project docker-maven-plugin by fabric8io.

the class LogMatchCallbackTest method matchingSingleLineSucceeds.

@Test(expected = LogCallback.DoneException.class)
public void matchingSingleLineSucceeds() throws Exception {
    final String patternString = "The start has finished right now";
    final LogMatchCallback logMatchCallback = new LogMatchCallback(logger, callback, patternString);
    new Expectations() {

        {
            callback.matched();
            times = 1;
        }
    };
    logMatchCallback.log(1, new Timestamp(), patternString);
}
Also used : Expectations(mockit.Expectations) Timestamp(io.fabric8.maven.docker.util.Timestamp) Test(org.junit.Test)

Example 10 with Timestamp

use of io.fabric8.maven.docker.util.Timestamp in project docker-maven-plugin by fabric8io.

the class LogMatchCallbackTest method matchingMultipleLinesSucceeds.

@Test(expected = LogCallback.DoneException.class)
public void matchingMultipleLinesSucceeds() throws Exception {
    final String patterString = "(?s)ready to accept connections.*\\n.*ready to accept connections";
    final LogMatchCallback logMatchCallback = new LogMatchCallback(logger, callback, patterString);
    new Expectations() {

        {
            callback.matched();
            times = 1;
        }
    };
    logMatchCallback.log(1, new Timestamp(), "LOG:  database system is ready to accept connections");
    logMatchCallback.log(1, new Timestamp(), "LOG:  autovacuum launcher started");
    logMatchCallback.log(1, new Timestamp(), "LOG:  database system is shut down");
    logMatchCallback.log(1, new Timestamp(), "LOG:  database system is ready to accept connections");
}
Also used : Expectations(mockit.Expectations) Timestamp(io.fabric8.maven.docker.util.Timestamp) Test(org.junit.Test)

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