Skip to content

Instantly share code, notes, and snippets.

@foxutech
Created March 21, 2018 05:20
Show Gist options
  • Save foxutech/836c136909981ee25aaa1cd285f9f18d to your computer and use it in GitHub Desktop.
Save foxutech/836c136909981ee25aaa1cd285f9f18d to your computer and use it in GitHub Desktop.
import net.bull.javamelody.*;
import net.bull.javamelody.internal.model.*;
url = "http://myserver:8080/mywebapp/monitoring";
double cpu = new RemoteCall(url).collectGraphLastValue("cpu");
println "cpu = " + cpu;
double gc = new RemoteCall(url).collectGraphLastValue("gc");
println "gc = " + gc;
java = new RemoteCall(url).collectJavaInformations();
memory = java.memoryInformations;
println "used memory = " + Math.round(memory.usedMemory / 1024 / 1024) + " Mb";
println "active HTTP threads count = " + java.activeThreadCount;
println "system load average = " + java.systemLoadAverage;
threads = java.getThreadInformationsList();
deadlocked = new java.util.ArrayList();
for (thread in threads) {
if (thread.deadlocked)
deadlocked.add(thread);
}
println deadlocked.size() + " deadlocked threads / " + threads.size() + " threads";
for (thread in deadlocked) {
println "";
println thread;
for (s in thread.getStackTrace())
println " " + s;
}
if (gc > 20) throw new Exception("Alert for mywebapp: gc is " + gc);
if (java.systemLoadAverage > 50) throw new Exception("Alert for mywebapp: systemLoadAverage is " + java.systemLoadAverage);
if (java.activeThreadCount > 100) throw new Exception("Alert for mywebapp: activeThreadCount is " + java.activeThreadCount);
if (deadlocked.size() > 0) throw new Exception("Alert for mywebapp: " + deadlocked.size() + " deadlocked threads");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment