Skip to content

Instantly share code, notes, and snippets.

@paul-brebner
Created September 5, 2017 04:57
Show Gist options
  • Save paul-brebner/532cf4b92a2cb52999e1da3c993978d4 to your computer and use it in GitHub Desktop.
Save paul-brebner/532cf4b92a2cb52999e1da3c993978d4 to your computer and use it in GitHub Desktop.
Cassandra - summary statistics for GC (partial code)
/* simple use case
* using new materialized view instametrics.host_service_value
* for all nodes find max and min and avg values of gc duration for each node and print out.
*/
/* host names table
* CREATE TABLE instametrics.host (
host text PRIMARY KEY
*/
System.out.println("getting all node names");
t1 = System.currentTimeMillis();
rs = session.execute("select * from instametrics.host");
System.out.println("Got rows (without fetching) = " + rs.getAvailableWithoutFetching());
int i = 0;
ArrayList<Double> allMax = new ArrayList<Double>(); // keep track of all max values
double overallMin = Double.MAX_VALUE;
double overallAvg = 0;
double overallSum = 0;
long overallCount = 0;
double overallMax = Double.MIN_VALUE;
for (Row rowN : rs)
{
i++;
String host = rowN.getString(0);
System.out.println(host);
// get min, avg, max values for gc duration for this node
ResultSet summary = session.execute("select min(metric), avg(metric), max(metric) from instametrics.host_service_value where host='"+ host + "' and service='/cassandra/jvm/gc/ConcurrentMarkSweep/lastGc/duration';");
Row arow = summary.one();
System.out.println(arow);
if (arow.isNull(2)) // nothing returned
;
else
{
Double min = arow.getDouble(0);
Double avg = arow.getDouble(1);
Double max = arow.getDouble(2);
// only compute overall results if row has returned non Null values!
overallSum += avg;
if (min < overallMin)
overallMin = min;
if (max > overallMax)
overallMax = max;
allMax.add(max);
overallCount++;
}
}
t2 = System.currentTimeMillis();
time = t2-t1;
System.out.println("Total time = " + time + ", nodes = " + i);
overallAvg = (double)(overallSum/overallCount);
System.out.println("Overall stats: Min = " + overallMin);
System.out.println("Overall stats: Avg = " + overallAvg);
System.out.println("Overall stats: Max = " + overallMax);
Collections.sort(allMax);
System.out.println("All max values:" + allMax);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment