private void diskUage() { ClusterStateResponse stateResponse = client.admin().cluster().prepareState().get(); DiscoveryNodes nodes = stateResponse.getState().nodes(); NodesStatsResponse state = client.admin().cluster().prepareNodesStats().setFs(true).get(); System.out.println("hostIp " + "available " + "used " + "total " + "master"); for(DiscoveryNode node : nodes) { System.out.print(node.address() + " "); Path path = state.getNodesMap().get(node.id()).getFs().getTotal(); System.out.print(path.getAvailable().gb() + " "); System.out.print(path.getTotal().gb() - path.getFree().gb() + " "); System.out.print(path.getTotal().gb() + " "); System.out.println(nodes.getMasterNodeId().equals(node.id()) ? "m" : "-"); } }
显示结果:
hostIp available used total master 172.16.3.5:9300 null null 42 51 98 - 172.16.4.108:9300 null null 45 48 98 m