Example usage for org.apache.cassandra.tools.nodetool HostStat ipOrDns

List of usage examples for org.apache.cassandra.tools.nodetool HostStat ipOrDns

Introduction

In this page you can find the example usage for org.apache.cassandra.tools.nodetool HostStat ipOrDns.

Prototype

public String ipOrDns() 

Source Link

Usage

From source file:com.wenyu.clustertools.Ring.java

License:Apache License

private void printDc(ClusterToolNodeProbe probe, String format, String dc,
            LinkedHashMultimap<String, String> endpointsToTokens, SetHostStat hoststats,
            boolean showEffectiveOwnership) {
        Collection<String> liveNodes = probe.getLiveNodes();
        Collection<String> deadNodes = probe.getUnreachableNodes();
        Collection<String> joiningNodes = probe.getJoiningNodes();
        Collection<String> leavingNodes = probe.getLeavingNodes();
        Collection<String> movingNodes = probe.getMovingNodes();
        Map<String, String> loadMap = probe.getLoadMap();

        System.out.println("Datacenter: " + dc);
        System.out.println("==========");

        // get the total amount of replicas for this dc and the last token in this dc's ring
        List<String> tokens = new ArrayList<>();
        String lastToken = "";

        for (HostStat stat : hoststats) {
            tokens.addAll(endpointsToTokens.get(stat.endpoint.getHostAddress()));
            lastToken = tokens.get(tokens.size() - 1);
        }/*from w  w  w. ja va2  s. c  o m*/

        System.out.printf(format, "Address", "Rack", "Status", "State", "Load", "Owns", "Token");

        if (hoststats.size() > 1)
            System.out.printf(format, "", "", "", "", "", "", lastToken);
        else
            System.out.println();

        for (HostStat stat : hoststats) {
            String endpoint = stat.endpoint.getHostAddress();
            String rack;
            try {
                rack = probe.getEndpointSnitchInfoProxy().getRack(endpoint);
            } catch (UnknownHostException e) {
                rack = "Unknown";
            }

            String status = liveNodes.contains(endpoint) ? "Up" : deadNodes.contains(endpoint) ? "Down" : "?";

            String state = "Normal";

            if (joiningNodes.contains(endpoint))
                state = "Joining";
            else if (leavingNodes.contains(endpoint))
                state = "Leaving";
            else if (movingNodes.contains(endpoint))
                state = "Moving";

            String load = loadMap.containsKey(endpoint) ? loadMap.get(endpoint) : "?";
            String owns = stat.owns != null && showEffectiveOwnership
                    ? new DecimalFormat("##0.00%").format(stat.owns)
                    : "?";
            System.out.printf(format, stat.ipOrDns(), rack, status, state, load, owns, stat.token);
        }
        System.out.println();
    }

From source file:com.wenyu.clustertools.Status.java

License:Apache License

private void findMaxAddressLength(Map<String, SetHostStat> dcs) {
        maxAddressLength = 0;//w  ww  .ja v  a2 s  .c  o  m
        for (Map.Entry<String, SetHostStat> dc : dcs.entrySet()) {
            for (HostStat stat : dc.getValue()) {
                maxAddressLength = Math.max(maxAddressLength, stat.ipOrDns().length());
            }
        }
    }