Java Code Examples for org.elasticsearch.action.admin.cluster.node.stats.NodeStats#getProcess()

The following examples show how to use org.elasticsearch.action.admin.cluster.node.stats.NodeStats#getProcess() . 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: ClusterStatsNodes.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public void addNodeStats(NodeStats nodeStats) {
    if (nodeStats.getProcess() == null) {
        return;
    }
    count++;
    if (nodeStats.getProcess().getCpu() != null) {
        cpuPercent += nodeStats.getProcess().getCpu().getPercent();
    }
    long fd = nodeStats.getProcess().getOpenFileDescriptors();
    if (fd > 0) {
        // fd can be -1 if not supported on platform
        totalOpenFileDescriptors += fd;
    }
    // we still do min max calc on -1, so we'll have an indication of it not being supported on one of the nodes.
    minOpenFileDescriptors = Math.min(minOpenFileDescriptors, fd);
    maxOpenFileDescriptors = Math.max(maxOpenFileDescriptors, fd);
}
 
Example 2
Source File: ProcessStatsMonitor.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;
    }

    ProcessStatsBean processStatsBean = new ProcessStatsBean();

    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("Process stats are not available (node stats is not available)");
            return;
        }

        ProcessStats processStats = nodeStats.getProcess();
        if (processStats == null) {
            logger.info("Process stats are not available");
            return;
        }

        //Memory
        processStatsBean.totalVirtualInBytes = processStats.getMem().getTotalVirtual().getBytes();

        //CPU
        processStatsBean.cpuPercent = processStats.getCpu().getPercent();
        processStatsBean.totalInMillis = processStats.getCpu().getTotal().getMillis();

        //Open file descriptors
        processStatsBean.openFileDescriptors = processStats.getOpenFileDescriptors();

        //Timestamp
        processStatsBean.cpuTimestamp = processStats.getTimestamp();
    } catch (Exception e) {
        logger.warn("Failed to load process stats data", e);
    }

    processStatsReporter.processStatsBean.set(processStatsBean);
}