Skip to content

Instantly share code, notes, and snippets.

@gunlee01
Created May 23, 2018 13:38
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 gunlee01/414cb58eb744f89901a663bd45dcf45a to your computer and use it in GitHub Desktop.
Save gunlee01/414cb58eb744f89901a663bd45dcf45a to your computer and use it in GitHub Desktop.
String counterName = "Elapsed90%";
String objType = $counter.getObjType();
String objName = $counter.getObjName();
float value = $counter.getFloatValue();
float tps = $counter.getFloatValue("TPS");
String widgetUrl = "http://my-scouter-webapi-ip:6180/widget/simple/counter.html?source=";
java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyyMMdd");
long now = System.currentTimeMillis();
String today = dateFormat.format(new java.util.Date(now));
String yesterday = dateFormat.format(new java.util.Date(now-24*60*60*1000));
String counterApi = counterName + "/ofType/" + objType;
counterApi += "?startTimeMillis=" + (now-600*1000L);
counterApi += "&endTimeMillis=" + now;
String counterApiLatest = counterName + "/latest/600/ofType/" + objType;
String dayStatApi = "stat/" + counterName + "/ofType/" + objType;
dayStatApi += "?startYmd=" + yesterday;
dayStatApi += "&endYmd=" + today;
String title = "Elapsed time alert";
String message = "Elapsed is over 2,000ms\n";
message += "[current value] " + $$.formatNumber(value, 0) + "ms\n";
message += "[objType] " + objType + "\n";
message += "[objName] " + objName + "\n";
message += "[TPS] " + $$.formatNumber(tps) + "\n";
message += "[On-time chart]\n";
message += widgetUrl + java.net.URLEncoder.encode(counterApi) + "\n";
message += "[Current chart]\n";
message += widgetUrl + java.net.URLEncoder.encode(counterApiLatest) + "\n";
message += "[Daily chart]\n";
message += widgetUrl + java.net.URLEncoder.encode(dayStatApi);
if(value > 2000 && tps > 10.0) {
$counter.fatal(title, message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment