本文整理汇总了Java中org.elasticsearch.action.admin.cluster.node.stats.NodeStats.getOs方法的典型用法代码示例。如果您正苦于以下问题:Java NodeStats.getOs方法的具体用法?Java NodeStats.getOs怎么用?Java NodeStats.getOs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.admin.cluster.node.stats.NodeStats
的用法示例。
在下文中一共展示了NodeStats.getOs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: OsStats
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; //导入方法依赖的package包/类
/**
* Build the stats from information about each node.
*/
private OsStats(List<NodeInfo> nodeInfos, List<NodeStats> nodeStatsList) {
this.names = new ObjectIntHashMap<>();
int availableProcessors = 0;
int allocatedProcessors = 0;
for (NodeInfo nodeInfo : nodeInfos) {
availableProcessors += nodeInfo.getOs().getAvailableProcessors();
allocatedProcessors += nodeInfo.getOs().getAllocatedProcessors();
if (nodeInfo.getOs().getName() != null) {
names.addTo(nodeInfo.getOs().getName(), 1);
}
}
this.availableProcessors = availableProcessors;
this.allocatedProcessors = allocatedProcessors;
long totalMemory = 0;
long freeMemory = 0;
for (NodeStats nodeStats : nodeStatsList) {
if (nodeStats.getOs() != null) {
long total = nodeStats.getOs().getMem().getTotal().getBytes();
if (total > 0) {
totalMemory += total;
}
long free = nodeStats.getOs().getMem().getFree().getBytes();
if (free > 0) {
freeMemory += free;
}
}
}
this.mem = new org.elasticsearch.monitor.os.OsStats.Mem(totalMemory, freeMemory);
}
示例2: addNodeInfoStats
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; //导入方法依赖的package包/类
public void addNodeInfoStats(NodeInfo nodeInfo, NodeStats nodeStats) {
availableProcessors += nodeInfo.getOs().getAvailableProcessors();
allocatedProcessors += nodeInfo.getOs().getAllocatedProcessors();
if (nodeInfo.getOs().getName() != null) {
names.addTo(nodeInfo.getOs().getName(), 1);
}
if (nodeStats.getOs() != null && nodeStats.getOs().getMem() != null) {
availableMemory += nodeStats.getOs().getMem().getFree().bytes();
}
}
示例3: execute
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; //导入方法依赖的package包/类
@Override
public void execute() throws Exception {
// If Elasticsearch is started then only start the monitoring
if (!ElasticsearchProcessMonitor.isElasticsearchRunning()) {
String exceptionMsg = "Elasticsearch is not yet started, check back again later";
logger.info(exceptionMsg);
return;
}
OsStatsBean osStatsBean = new OsStatsBean();
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("OS stats is not available (node stats is not available)");
return;
}
OsStats osStats = nodeStats.getOs();
if (osStats == null) {
logger.info("OS stats is not available");
return;
}
//Memory
osStatsBean.freeInBytes = osStats.getMem().getFree().getBytes();
osStatsBean.usedInBytes = osStats.getMem().getUsed().getBytes();
osStatsBean.actualFreeInBytes = osStats.getMem().getFree().getBytes();
osStatsBean.actualUsedInBytes = osStats.getMem().getUsed().getBytes();
osStatsBean.freePercent = osStats.getMem().getFreePercent();
osStatsBean.usedPercent = osStats.getMem().getUsedPercent();
//CPU
osStatsBean.cpuSys = osStats.getCpu().getPercent();
osStatsBean.cpuUser = 0;
osStatsBean.cpuIdle = 0;
osStatsBean.cpuStolen = 0;
//Swap
osStatsBean.swapFreeInBytes = osStats.getSwap().getFree().getBytes();
osStatsBean.swapUsedInBytes = osStats.getSwap().getUsed().getBytes();
//Uptime
osStatsBean.uptimeInMillis = 0;
//Timestamp
osStatsBean.osTimestamp = osStats.getTimestamp();
} catch (Exception e) {
logger.warn("Failed to load OS stats data", e);
}
osStatsReporter.osStatsBean.set(osStatsBean);
}