ES获取磁盘使用率情况

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

 

posted @ 2018-01-18 19:09  woniu4  阅读(1031)  评论(0编辑  收藏  举报