org.elasticsearch.monitor.jvm.JvmStats Java Examples

The following examples show how to use org.elasticsearch.monitor.jvm.JvmStats. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeHeapExpression.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private void addChildImplementations(final JvmStats stats) {
    childImplementations.put(FREE, new HeapExpression() {
        @Override
        public Long value() {
            return stats.getMem().getHeapMax().bytes() - stats.getMem().getHeapUsed().bytes();
        }
    });
    childImplementations.put(USED, new HeapExpression() {
        @Override
        public Long value() {
            return stats.getMem().getHeapUsed().bytes();
        }
    });
    childImplementations.put(MAX, new HeapExpression() {
        @Override
        public Long value() {
            return stats.getMem().getHeapMax().bytes();
        }
    });
    childImplementations.put(PROBE_TIMESTAMP, new SysNodeExpression<Long>() {
        @Override
        public Long value() {
            return stats.getTimestamp();
        }
    });
}
 
Example #2
Source File: NodeStats.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public NodeStats(DiscoveryNode node, long timestamp, @Nullable NodeIndicesStats indices,
                 @Nullable OsStats os, @Nullable ProcessStats process, @Nullable JvmStats jvm, @Nullable ThreadPoolStats threadPool,
                 @Nullable FsInfo fs, @Nullable TransportStats transport, @Nullable HttpStats http,
                 @Nullable AllCircuitBreakerStats breaker,
                 @Nullable ScriptStats scriptStats) {
    super(node);
    this.timestamp = timestamp;
    this.indices = indices;
    this.os = os;
    this.process = process;
    this.jvm = jvm;
    this.threadPool = threadPool;
    this.fs = fs;
    this.transport = transport;
    this.http = http;
    this.breaker = breaker;
    this.scriptStats = scriptStats;
}
 
Example #3
Source File: NodeStats.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    timestamp = in.readVLong();
    if (in.readBoolean()) {
        indices = NodeIndicesStats.readIndicesStats(in);
    }
    if (in.readBoolean()) {
        os = OsStats.readOsStats(in);
    }
    if (in.readBoolean()) {
        process = ProcessStats.readProcessStats(in);
    }
    if (in.readBoolean()) {
        jvm = JvmStats.readJvmStats(in);
    }
    if (in.readBoolean()) {
        threadPool = ThreadPoolStats.readThreadPoolStats(in);
    }
    if (in.readBoolean()) {
        fs = FsInfo.readFsInfo(in);
    }
    if (in.readBoolean()) {
        transport = TransportStats.readTransportStats(in);
    }
    if (in.readBoolean()) {
        http = HttpStats.readHttpStats(in);
    }
    breaker = AllCircuitBreakerStats.readOptionalAllCircuitBreakerStats(in);
    scriptStats = in.readOptionalStreamable(new ScriptStats());

}
 
Example #4
Source File: NodeStatsContext.java    From crate with Apache License 2.0 5 votes vote down vote up
public NodeStatsContext(StreamInput in, boolean complete) throws IOException {
    this.complete = complete;
    this.id = DataTypes.STRING.readValueFrom(in);
    this.name = DataTypes.STRING.readValueFrom(in);
    this.hostname = DataTypes.STRING.readValueFrom(in);
    this.timestamp = in.readLong();
    this.version = in.readBoolean() ? Version.readVersion(in) : null;
    this.build = in.readBoolean() ? Build.readBuild(in) : null;
    this.restUrl = DataTypes.STRING.readValueFrom(in);
    this.pgPort = in.readOptionalVInt();
    this.httpPort = in.readOptionalVInt();
    this.transportPort = in.readOptionalVInt();
    this.jvmStats = in.readOptionalWriteable(JvmStats::new);
    this.osInfo = in.readOptionalWriteable(OsInfo::new);
    this.processStats = in.readOptionalWriteable(ProcessStats::new);
    this.osStats = in.readOptionalWriteable(OsStats::new);
    this.fsInfo = in.readOptionalWriteable(FsInfo::new);
    this.extendedOsStats = in.readOptionalWriteable(ExtendedOsStats::new);
    this.threadPools = in.readOptionalWriteable(ThreadPoolStats::new);
    this.httpStats = in.readOptionalWriteable(HttpStats::new);
    this.psqlStats = in.readOptionalWriteable(ConnectionStats::new);
    this.openTransportConnections = in.readLong();
    this.clusterStateVersion = in.readLong();

    this.osName = DataTypes.STRING.readValueFrom(in);
    this.osArch = DataTypes.STRING.readValueFrom(in);
    this.osVersion = DataTypes.STRING.readValueFrom(in);
    this.javaVersion = DataTypes.STRING.readValueFrom(in);
    this.jvmName = DataTypes.STRING.readValueFrom(in);
    this.jvmVendor = DataTypes.STRING.readValueFrom(in);
    this.jvmVersion = DataTypes.STRING.readValueFrom(in);
}
 
Example #5
Source File: NodeHeapExpression.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public NodeHeapExpression(JvmStats stats) {
    addChildImplementations(stats);
}
 
Example #6
Source File: NodeStats.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * JVM level statistics.
 */
@Nullable
public JvmStats getJvm() {
    return jvm;
}
 
Example #7
Source File: JvmStatsMonitor.java    From Raigad with Apache License 2.0 4 votes vote down vote up
@Override
public void execute() throws Exception {
    // Only start monitoring if Elasticsearch is started
    if (!ElasticsearchProcessMonitor.isElasticsearchRunning()) {
        String exceptionMsg = "Elasticsearch is not yet started, check back again later";
        logger.info(exceptionMsg);
        return;
    }

    JvmStatsBean jvmStatsBean = new JvmStatsBean();

    try {
        NodesStatsResponse nodesStatsResponse = ElasticsearchTransportClient.getNodesStatsResponse(config);
        NodeStats nodeStats = null;

        List<NodeStats> nodeStatsList = nodesStatsResponse.getNodes();

        if (nodeStatsList.size() > 0) {
            nodeStats = nodeStatsList.get(0);
        }

        if (nodeStats == null) {
            logger.info("JVM stats is not available (node stats is not available)");
            return;
        }

        JvmStats jvmStats = nodeStats.getJvm();
        if (jvmStats == null) {
            logger.info("JVM stats is not available");
            return;
        }

        //Heap
        jvmStatsBean.heapCommittedInBytes = jvmStats.getMem().getHeapCommitted().getMb();
        jvmStatsBean.heapMaxInBytes = jvmStats.getMem().getHeapMax().getMb();
        jvmStatsBean.heapUsedInBytes = jvmStats.getMem().getHeapUsed().getMb();
        jvmStatsBean.heapUsedPercent = jvmStats.getMem().getHeapUsedPercent();
        jvmStatsBean.nonHeapCommittedInBytes = jvmStats.getMem().getNonHeapCommitted().getMb();
        jvmStatsBean.nonHeapUsedInBytes = jvmStats.getMem().getNonHeapUsed().getMb();

        Iterator<JvmStats.MemoryPool> memoryPoolIterator = jvmStats.getMem().iterator();

        while (memoryPoolIterator.hasNext()) {
            JvmStats.MemoryPool memoryPoolStats = memoryPoolIterator.next();
            if (memoryPoolStats.getName().equalsIgnoreCase(GC_YOUNG_TAG)) {
                jvmStatsBean.youngMaxInBytes = memoryPoolStats.getMax().getBytes();
                jvmStatsBean.youngUsedInBytes = memoryPoolStats.getUsed().getBytes();
                jvmStatsBean.youngPeakUsedInBytes = memoryPoolStats.getPeakUsed().getBytes();
                jvmStatsBean.youngPeakMaxInBytes = memoryPoolStats.getPeakMax().getBytes();
            } else if (memoryPoolStats.getName().equalsIgnoreCase(GC_SURVIVOR_TAG)) {
                jvmStatsBean.survivorMaxInBytes = memoryPoolStats.getMax().getBytes();
                jvmStatsBean.survivorUsedInBytes = memoryPoolStats.getUsed().getBytes();
                jvmStatsBean.survivorPeakUsedInBytes = memoryPoolStats.getPeakUsed().getBytes();
                jvmStatsBean.survivorPeakMaxInBytes = memoryPoolStats.getPeakMax().getBytes();
            } else if (memoryPoolStats.getName().equalsIgnoreCase(GC_OLD_TAG)) {
                jvmStatsBean.oldMaxInBytes = memoryPoolStats.getMax().getBytes();
                jvmStatsBean.oldUsedInBytes = memoryPoolStats.getUsed().getBytes();
                jvmStatsBean.oldPeakUsedInBytes = memoryPoolStats.getPeakUsed().getBytes();
                jvmStatsBean.oldPeakMaxInBytes = memoryPoolStats.getPeakMax().getBytes();
            }
        }

        //Threads
        jvmStatsBean.threadCount = jvmStats.getThreads().getCount();
        jvmStatsBean.threadPeakCount = jvmStats.getThreads().getPeakCount();
        jvmStatsBean.uptimeHours = jvmStats.getUptime().getHours();

        //GC
        for (JvmStats.GarbageCollector garbageCollector : jvmStats.getGc().getCollectors()) {
            if (garbageCollector.getName().equalsIgnoreCase(GC_YOUNG_TAG)) {
                jvmStatsBean.youngCollectionCount = garbageCollector.getCollectionCount();
                jvmStatsBean.youngCollectionTimeInMillis = garbageCollector.getCollectionTime().getMillis();
            } else if (garbageCollector.getName().equalsIgnoreCase(GC_OLD_TAG)) {
                jvmStatsBean.oldCollectionCount = garbageCollector.getCollectionCount();
                jvmStatsBean.oldCollectionTimeInMillis = garbageCollector.getCollectionTime().getMillis();
            }
        }
    } catch (Exception e) {
        logger.warn("Failed to load JVM stats data", e);
    }

    jvmStatsReporter.jvmStatsBean.set(jvmStatsBean);
}
 
Example #8
Source File: GraphiteReporter.java    From elasticsearch-graphite-plugin with Do What The F*ck You Want To Public License 4 votes vote down vote up
private void sendNodeJvmStats(JvmStats jvmStats) {
    String type = buildMetricName("node.jvm");
    sendInt(type, "uptime", jvmStats.uptime().seconds());

    // mem
    sendInt(type + ".mem", "heapCommitted", jvmStats.mem().heapCommitted().bytes());
    sendInt(type + ".mem", "heapUsed", jvmStats.mem().heapUsed().bytes());
    sendInt(type + ".mem", "nonHeapCommitted", jvmStats.mem().nonHeapCommitted().bytes());
    sendInt(type + ".mem", "nonHeapUsed", jvmStats.mem().nonHeapUsed().bytes());

    Iterator<JvmStats.MemoryPool> memoryPoolIterator = jvmStats.mem().iterator();
    while (memoryPoolIterator.hasNext()) {
        JvmStats.MemoryPool memoryPool = memoryPoolIterator.next();
        String memoryPoolType = type + ".mem.pool." + memoryPool.name();

        sendInt(memoryPoolType, "max", memoryPool.max().bytes());
        sendInt(memoryPoolType, "used", memoryPool.used().bytes());
        sendInt(memoryPoolType, "peakUsed", memoryPool.peakUsed().bytes());
        sendInt(memoryPoolType, "peakMax", memoryPool.peakMax().bytes());
    }

    // threads
    sendInt(type + ".threads", "count", jvmStats.threads().count());
    sendInt(type + ".threads", "peakCount", jvmStats.threads().peakCount());

    // garbage collectors
    for (JvmStats.GarbageCollector collector : jvmStats.gc().collectors()) {
        String id = type + ".gc." + collector.name();
        sendInt(id, "collectionCount", collector.collectionCount());
        sendInt(id, "collectionTimeSeconds", collector.collectionTime().seconds());

        JvmStats.GarbageCollector.LastGc lastGc = collector.lastGc();
        String lastGcType = type + ".lastGc";
        if (lastGc != null) {
            sendInt(lastGcType, "startTime", lastGc.startTime());
            sendInt(lastGcType, "endTime", lastGc.endTime());
            sendInt(lastGcType, "max", lastGc.max().bytes());
            sendInt(lastGcType, "beforeUsed", lastGc.beforeUsed().bytes());
            sendInt(lastGcType, "afterUsed", lastGc.afterUsed().bytes());
            sendInt(lastGcType, "durationSeconds", lastGc.duration().seconds());
        }
    }

    // TODO: bufferPools - where to get them?
}
 
Example #9
Source File: NodeStatsContext.java    From crate with Apache License 2.0 4 votes vote down vote up
public JvmStats jvmStats() {
    return jvmStats;
}
 
Example #10
Source File: NodeStatsContextTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testStreamContext() throws Exception {
    NodeStatsContext ctx1 = new NodeStatsContext(true);
    ctx1.id("93c7ff92-52fa-11e6-aad8-3c15c2d3ad18");
    ctx1.name("crate1");
    ctx1.hostname("crate1.example.com");
    ctx1.timestamp(100L);
    ctx1.version(Version.CURRENT);
    ctx1.build(Build.CURRENT);
    ctx1.httpPort(4200);
    ctx1.transportPort(4300);
    ctx1.restUrl("10.0.0.1:4200");
    ctx1.jvmStats(JvmStats.jvmStats());
    ctx1.osInfo(DummyOsInfo.INSTANCE);
    ProcessProbe processProbe = ProcessProbe.getInstance();
    ctx1.processStats(processProbe.processStats());
    OsProbe osProbe = OsProbe.getInstance();
    ctx1.osStats(osProbe.osStats());
    ctx1.extendedOsStats(extendedNodeInfo.osStats());
    ctx1.threadPools(threadPool.stats());
    ctx1.clusterStateVersion(10L);

    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    StreamOutput out = new OutputStreamStreamOutput(outBuffer);
    ctx1.writeTo(out);

    ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    InputStreamStreamInput in = new InputStreamStreamInput(inBuffer);
    NodeStatsContext ctx2 = new NodeStatsContext(in, true);

    assertThat(ctx1.id(), is(ctx2.id()));
    assertThat(ctx1.name(), is(ctx2.name()));
    assertThat(ctx1.hostname(), is(ctx2.hostname()));
    assertThat(ctx1.timestamp(), is(100L));
    assertThat(ctx1.version(), is(ctx2.version()));
    assertThat(ctx1.build().hash(), is(ctx2.build().hash()));
    assertThat(ctx1.restUrl(), is(ctx2.restUrl()));
    assertThat(ctx1.httpPort(), is(ctx2.httpPort()));
    assertThat(ctx1.transportPort(), is(ctx2.transportPort()));
    assertThat(ctx1.pgPort(), is(ctx2.pgPort()));
    assertThat(ctx1.jvmStats().getTimestamp(), is(ctx2.jvmStats().getTimestamp()));
    assertThat(ctx1.osInfo().getArch(), is(ctx2.osInfo().getArch()));
    assertThat(ctx1.processStats().getTimestamp(), is(ctx2.processStats().getTimestamp()));
    assertThat(ctx1.osStats().getTimestamp(), is(ctx2.osStats().getTimestamp()));
    assertThat(ctx1.extendedOsStats().uptime(), is(ctx2.extendedOsStats().uptime()));
    assertThat(ctx1.threadPools().iterator().next().getActive(), is(ctx2.threadPools().iterator().next().getActive()));
    assertThat(ctx1.clusterStateVersion(), is(ctx2.clusterStateVersion()));
}