org.apache.cassandra.tools.NodeProbe Java Examples

The following examples show how to use org.apache.cassandra.tools.NodeProbe. 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: Probe.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
private NodeProbe connectProbe() {
    while (true) {
        try {
            NodeProbe nodeProbe = new NodeProbe("127.0.0.1", task.getConfig().getJmxPort());
            logger.info("Node probe is successfully connected to the Cassandra Daemon: port {}",
                    task.getConfig().getJmxPort());
            return nodeProbe;
        } catch (Exception ex) {
            logger.info("Connection to server failed backing off for 500 ms");
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
            }
        }
    }
}
 
Example #2
Source File: CassandraDaemonProcess.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
private static CassandraStatus getCassandraStatus(final NodeProbe probe) {
    return CassandraStatus.create(
            CassandraMode.valueOf(
                    probe.getOperationMode()
            ), probe.isJoined(),
            probe.isThriftServerRunning(),
            probe.isNativeTransportRunning(),
            probe.isInitialized(),
            probe.isGossipRunning(),
            probe.getLocalHostId(),
            probe.getEndpoint(),
            probe.getTokens().size(),
            probe.getDataCenter(),
            probe.getRack(),
            probe.getReleaseVersion());
}
 
Example #3
Source File: CliSessionState.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public NodeProbe getNodeProbe()
{
    try
    {
        return jmxUsername != null && jmxPassword != null
               ? new NodeProbe(hostName, jmxPort, jmxUsername, jmxPassword)
               : new NodeProbe(hostName, jmxPort);
    }
    catch (Exception e)
    {
        JVMStabilityInspector.inspectThrowable(e);
        err.printf("WARNING: Could not connect to the JMX on %s:%d - some information won't be shown.%n%n", hostName, jmxPort);
    }

    return null;
}
 
Example #4
Source File: JmxCollector.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public GcStats call() throws Exception
{
    final List<Future<GcStats>> futures = new ArrayList<>();
    for (final NodeProbe probe : probes)
    {
        futures.add(TPE.submit(new Callable<GcStats>()
        {
            public GcStats call() throws Exception
            {
                final double[] stats = probe.getAndResetGCStats();
                return new GcStats(stats[5], stats[4], stats[1], stats[2], stats[3]);
            }
        }));
    }

    List<GcStats> results = new ArrayList<>();
    for (Future<GcStats> future : futures)
        results.add(future.get());
    return GcStats.aggregate(results);
}
 
Example #5
Source File: TruncateHints.java    From cassandra-opstools with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
  if (args.length < 1) {
    System.out.println(String.format("Usage: %s [ALL | host [host ...]]", TruncateHints.class.getName()));
    System.exit(1);
  }

  NodeProbe nodeProbe = new NodeProbe(InetAddress.getLocalHost().getCanonicalHostName(), 7199);

  for (String arg : args) {
    if (arg.equals("ALL"))  {
      nodeProbe.truncateHints();
    } else {
      nodeProbe.truncateHints(arg);
    }
  }

  System.out.println("Hints truncated!");
}
 
Example #6
Source File: CassandraMetrics.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
private Map<String, Object> getMetricsByHost(String host) {
    Map<String, Object> metrics = InsertionOrderUtil.newMap();
    // JMX client operations for Cassandra.
    try (NodeProbe probe = this.newNodeProbe(host)) {
        MemoryUsage heapUsage = probe.getHeapMemoryUsage();
        metrics.put(MEM_USED, heapUsage.getUsed() / Bytes.MB);
        metrics.put(MEM_COMMITED, heapUsage.getCommitted() / Bytes.MB);
        metrics.put(MEM_MAX, heapUsage.getMax() / Bytes.MB);
        metrics.put(MEM_UNIT, "MB");
        metrics.put(DATA_SIZE, probe.getLoadString());
    } catch (Throwable e) {
        metrics.put(EXCEPTION, e.toString());
    }
    return metrics;
}
 
Example #7
Source File: Probe.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
public NodeProbe get() {
    if (nodeProbe == null) {
        nodeProbe = connectProbe();
    }

    return nodeProbe;
}
 
Example #8
Source File: JmxCollector.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public JmxCollector(Collection<String> hosts, int port)
{
    probes = new NodeProbe[hosts.size()];
    int i = 0;
    for (String host : hosts)
    {
        probes[i] = connect(host, port);
        probes[i].getAndResetGCStats();
        i++;
    }
}
 
Example #9
Source File: JmxCollector.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private static NodeProbe connect(String host, int port)
{
    try
    {
        return new NodeProbe(host, port);
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #10
Source File: CassandraMetrics.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
private NodeProbe newNodeProbe(String host) throws IOException {
    return this.username.isEmpty() ?
           new NodeProbe(host, this.port) :
           new NodeProbe(host, this.port, this.username, this.password);
}
 
Example #11
Source File: CliClient.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
private void executeDescribe(Tree statement) throws TException, InvalidRequestException, NotFoundException
{
    if (!CliMain.isConnected())
        return;

    printCQL3TablesWarning("describe");

    int argCount = statement.getChildCount();

    if (keySpace == null && argCount == 0)
    {
        sessionState.out.println("Authenticate to a Keyspace, before using `describe` or `describe <column_family>`");
        return;
    }

    KsDef currentKeySpace = null;
    if (keySpace != null)
    {
        keyspacesMap.remove(keySpace);
        currentKeySpace = getKSMetaData(keySpace);
    }

    if (argCount > 1) // in case somebody changes Cli grammar
        throw new RuntimeException("`describe` command take maximum one argument. See `help describe;`");

    if (argCount == 0)
    {
        if (currentKeySpace != null)
        {
            describeKeySpace(currentKeySpace.name, null);
            return;
        }

        sessionState.out.println("Authenticate to a Keyspace, before using `describe` or `describe <column_family>`");
    }
    else if (argCount == 1)
    {
        // name of the keyspace or ColumnFamily
        String entityName = statement.getChild(0).getText();

        KsDef inputKsDef = CliUtils.getKeySpaceDef(entityName, thriftClient.describe_keyspaces());

        if (inputKsDef == null && currentKeySpace == null)
            throw new RuntimeException(String.format("Keyspace with name '%s' wasn't found, " +
                                                     "to lookup ColumnFamily with that name, please, authorize to one " +
                                                     "of the keyspaces first.", entityName));

        CfDef inputCfDef = (inputKsDef == null)
                ? getCfDef(currentKeySpace, entityName, false)
                : null;  // no need to lookup CfDef if we know that it was keyspace

        if (inputKsDef != null)
        {
            describeKeySpace(inputKsDef.name, inputKsDef);
        }
        else if (inputCfDef != null)
        {
            NodeProbe probe = sessionState.getNodeProbe();

            try
            {
                describeColumnFamily(currentKeySpace, inputCfDef, probe);

                if (probe != null)
                    probe.close();
            }
            catch (IOException e)
            {
                sessionState.out.println("Error while closing JMX connection: " + e.getMessage());
            }
        }
        else
        {
            sessionState.out.println("Sorry, no Keyspace nor (non-CQL3) ColumnFamily was found with name: " + entityName + " (if this is a CQL3 table, you should use cqlsh instead)");
        }
    }
}
 
Example #12
Source File: CassandraDaemonProcess.java    From dcos-cassandra-service with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the NodeProbe.
 *
 * @return The NodeProbe instance used to communicate with the Cassandra
 * process.
 */
public NodeProbe getProbe() {
    return this.probe.get();
}