Created
September 14, 2015 15:04
-
-
Save agile/e6310b0712334f028c06 to your computer and use it in GitHub Desktop.
This file contains 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
import java.lang.management.*; | |
def threadBean = ManagementFactory.getThreadMXBean(); | |
def osBean = ManagementFactory.getOperatingSystemMXBean(); | |
println "\n\n\n[Checking state of (master)]"; | |
println "Current CPU Time used by Jenkins: " + threadBean.getCurrentThreadCpuTime() + "ns"; | |
double processLoad = (osBean.getProcessCpuLoad() * 100).round(2); | |
double cpuLoad = (osBean.getSystemCpuLoad() * 100).round(2); | |
println "Process CPU Load: " + processLoad + "%"; | |
println "CPU Load: " + cpuLoad + "%"; | |
if (processLoad < 90) { | |
println "\n\n\n === Load is less than 90%, nothing to do ===\n\n\n"; | |
println "\n\n\n[Done checking: CPU Load: " + cpuLoad + "%]\n\n\n"; | |
return; | |
} else { | |
println "\n\n\n === Load is more than 90%, checking for stuck threads! ===\n\n\n"; | |
} | |
println "\n\n\n[Checking all threads]\n\n\n"; | |
def threadNum = 0; | |
def killThreadNum = 0; | |
def stacktraces = Thread.getAllStackTraces(); | |
stacktraces.each { thread, stack -> | |
if (thread.getName().contains("trigger/TimerTrigger/check") ) { | |
println "=== Interrupting thread " + thread.getName()+ " ==="; | |
thread.interrupt(); | |
killThreadNum++; | |
} | |
threadNum++; | |
} | |
println "\n\n\n[Done checking: " + threadNum + " threads, killed " + killThreadNum + "]\n\n\n"; | |
return; // Suppress groovy state dump |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment