Skip to content

Instantly share code, notes, and snippets.

@razie
Created November 13, 2013 16:32
Show Gist options
  • Save razie/7452003 to your computer and use it in GitHub Desktop.
Save razie/7452003 to your computer and use it in GitHub Desktop.
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