Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def ping-me() = Action { implicit request =>
Ok(osusage)
}
def osusage = {
var s = ""
val osm: OperatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
for (method <- osm.getClass().getDeclaredMethods()) {
method.setAccessible(true);
if (method.getName().startsWith("get") && Modifier.isPublic(method.getModifiers())) {
val v = try {
method.invoke(osm).toString;
} catch {
case e: Exception => e.toString
} // try
val vn = try {
v.toLong
} catch {
case e: Exception => -1
} // try
s = s + (method.getName() -> (if(vn == -1) v else (nice(vn) + " - "+v))) + "\n";
} // if
} // for
// add Play request monitoring data
s"""$s\n
Global.serving=${GlobalData.serving}\n
Global.served=${GlobalData.served}\n
Global.startedDtm=${GlobalData.startedDtm}\n
"""
}
private def nice(l: Long) =
if (l > 2L*(1024L*1024L*1024L))
l / (1024L*1024L*1024L) + "G"
else if (l > 2*(1024L*1024L))
l / (1024L*1024L) + "M"
else if (l > 1024)
l / 1024 + "K"
else
l.toString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.