Created
November 13, 2013 16:32
-
-
Save razie/7452003 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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