Search in sources :

Example 1 with Renderer

use of io.fabric8.insight.metrics.mvel.Renderer in project fabric8 by jboss-fuse.

the class Log4jLogQuery method toLogEvent.

protected LogEvent toLogEvent(LoggingEvent element) {
    LogEvent answer = new LogEvent();
    answer.setClassName(element.getFQNOfLoggerClass());
    // TODO
    // answer.setContainerName(element.get);
    ThrowableInformation throwableInformation = element.getThrowableInformation();
    if (throwableInformation != null) {
        ThrowableFormatter renderer = new ThrowableFormatter();
        String[] stack = renderer.doRender(throwableInformation.getThrowable());
        if (stack == null) {
            stack = element.getThrowableStrRep();
        }
        answer.setException(stack);
    }
    LocationInfo locationInformation = element.getLocationInformation();
    if (locationInformation != null) {
        answer.setFileName(locationInformation.getFileName());
        answer.setClassName(locationInformation.getClassName());
        answer.setMethodName(locationInformation.getMethodName());
        answer.setLineNumber(locationInformation.getLineNumber());
    }
    Level level = element.getLevel();
    if (level != null) {
        answer.setLevel(level.toString());
    }
    // TODO
    answer.setLogger(element.getLoggerName());
    Category logger = element.getLogger();
    Object message = element.getMessage();
    if (message != null) {
        // TODO marshal differently?
        answer.setMessage(message.toString());
    }
    answer.setProperties(element.getProperties());
    // TODO
    answer.setSeq(element.getTimeStamp());
    answer.setTimestamp(new Date(element.getTimeStamp()));
    answer.setThread(element.getThreadName());
    answer.setHost(getHostName());
    return answer;
}
Also used : Category(org.apache.log4j.Category) LogEvent(io.fabric8.insight.log.LogEvent) ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) Level(org.apache.log4j.Level) Date(java.util.Date) LocationInfo(org.apache.log4j.spi.LocationInfo)

Example 2 with Renderer

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

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 LogEvent (io.fabric8.insight.log.LogEvent)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 QueryResult (io.fabric8.insight.metrics.model.QueryResult)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 Date (java.util.Date)1 Map (java.util.Map)1 Category (org.apache.log4j.Category)1 Level (org.apache.log4j.Level)1 LocationInfo (org.apache.log4j.spi.LocationInfo)1 ThrowableInformation (org.apache.log4j.spi.ThrowableInformation)1 Test (org.junit.Test)1