Skip to content

Instantly share code, notes, and snippets.

@olim7t
Created December 8, 2014 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olim7t/08026acfff09e475390d to your computer and use it in GitHub Desktop.
Save olim7t/08026acfff09e475390d to your computer and use it in GitHub Desktop.
Monitor inFlight queries of DataStax Java driver
static void reportInFlightQueries(Session session) {
Session.State state = session.getState();
System.out.printf("State of %s:%n", session);
for (Host host : state.getConnectedHosts()) {
int connections = state.getOpenConnections(host);
int inFlight = state.getInFlightQueries(host);
System.out.printf("\t%s:\tconnections=%2s\tinFlight=%4s\tmean=%4s%n",
host,
connections,
inFlight,
inFlight / connections);
}
}
// Example of scheduling it at regular intervals:
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
executor.scheduleWithFixedDelay(new Runnable() {
@Override public void run() {
reportInFlightQueries(session);
}
}, 60, 60, TimeUnit.SECONDS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment