Search in sources :

Example 1 with BufferPool

use of org.opensearch.monitor.jvm.JvmStats.BufferPool in project fess by codelibs.

the class SystemMonitorTarget method appendJvmStats.

private void appendJvmStats(final StringBuilder buf) {
    buf.append("\"jvm\":{");
    final JvmStats jvmStats = JvmStats.jvmStats();
    final Mem mem = jvmStats.getMem();
    buf.append("\"memory\":{");
    buf.append("\"heap\":{");
    append(buf, "used", () -> mem.getHeapUsed().getBytes()).append(',');
    append(buf, "committed", () -> mem.getHeapCommitted().getBytes()).append(',');
    append(buf, "max", () -> mem.getHeapMax().getBytes()).append(',');
    append(buf, "percent", () -> mem.getHeapUsedPercent());
    buf.append("},");
    buf.append("\"non_heap\":{");
    append(buf, "used", () -> mem.getNonHeapUsed().getBytes()).append(',');
    append(buf, "committed", () -> mem.getNonHeapCommitted().getBytes());
    buf.append('}');
    buf.append("},");
    final List<BufferPool> bufferPools = jvmStats.getBufferPools();
    buf.append("\"pools\":{");
    buf.append(bufferPools.stream().map(p -> {
        final StringBuilder b = new StringBuilder();
        b.append('"').append(StringEscapeUtils.escapeJson(p.getName())).append("\":{");
        append(b, "count", () -> p.getCount()).append(',');
        append(b, "used", () -> p.getUsed().getBytes()).append(',');
        append(b, "capacity", () -> p.getTotalCapacity().getBytes()).append('}');
        return b.toString();
    }).collect(Collectors.joining(",")));
    buf.append("},");
    final GarbageCollectors gc = jvmStats.getGc();
    buf.append("\"gc\":{");
    buf.append(Arrays.stream(gc.getCollectors()).map(c -> {
        final StringBuilder b = new StringBuilder();
        b.append('"').append(StringEscapeUtils.escapeJson(c.getName())).append("\":{");
        append(b, "count", () -> c.getCollectionCount()).append(',');
        append(b, "time", () -> c.getCollectionTime().getMillis()).append('}');
        return b.toString();
    }).collect(Collectors.joining(",")));
    buf.append("},");
    final Threads threads = jvmStats.getThreads();
    buf.append("\"threads\":{");
    append(buf, "count", () -> threads.getCount()).append(',');
    append(buf, "peak", () -> threads.getPeakCount());
    buf.append("},");
    final Classes classes = jvmStats.getClasses();
    buf.append("\"classes\":{");
    append(buf, "loaded", () -> classes.getLoadedClassCount()).append(',');
    append(buf, "total_loaded", () -> classes.getTotalLoadedClassCount()).append(',');
    append(buf, "unloaded", () -> classes.getUnloadedClassCount());
    buf.append("},");
    append(buf, "uptime", () -> jvmStats.getUptime().getMillis());
    buf.append("},");
}
Also used : JvmStats(org.opensearch.monitor.jvm.JvmStats) Threads(org.opensearch.monitor.jvm.JvmStats.Threads) BufferPool(org.opensearch.monitor.jvm.JvmStats.BufferPool) Mem(org.opensearch.monitor.jvm.JvmStats.Mem) GarbageCollectors(org.opensearch.monitor.jvm.JvmStats.GarbageCollectors) Classes(org.opensearch.monitor.jvm.JvmStats.Classes)

Aggregations

JvmStats (org.opensearch.monitor.jvm.JvmStats)1 BufferPool (org.opensearch.monitor.jvm.JvmStats.BufferPool)1 Classes (org.opensearch.monitor.jvm.JvmStats.Classes)1 GarbageCollectors (org.opensearch.monitor.jvm.JvmStats.GarbageCollectors)1 Mem (org.opensearch.monitor.jvm.JvmStats.Mem)1 Threads (org.opensearch.monitor.jvm.JvmStats.Threads)1