Created
December 15, 2015 06:35
-
-
Save apemberton/36575f40024e78c473b6 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
/*** BEGIN META { | |
"name" : "Count executors", | |
"comment" : "Shows the total number of nodes and executors on Jenkins", | |
"parameters" : [ ], | |
"core": "1.350", | |
"authors" : [ | |
{ name : "Andy Pemberton" } | |
] | |
} END META**/ | |
import jenkins.model.Jenkins | |
println("====== Regular Slave Executors ======") | |
println() | |
// Jenkins Master and slaves | |
def regularSlaves = Jenkins.instance.computers.grep{ | |
it.class.superclass?.simpleName != 'AbstractCloudComputer' && | |
it.class.superclass?.simpleName != 'AbstractCloudSlave' && | |
it.class.simpleName != 'EC2AbstractSlave' | |
} | |
int regularSlaveExecutorCount = regularSlaves.inject(0, {a, c -> a + c.numExecutors}) | |
//TODO perhaps filter other known cloud slaves; shame there isn't a cleaner way to know them | |
println("| Node Name | Type | Executors |") | |
regularSlaves.each { | |
println "| ${it.displayName} | ${it.class.simpleName} | ${it.numExecutors} |" | |
} | |
println() | |
println("Total: " + regularSlaveExecutorCount + " executors") | |
println() | |
println("====== Shared Slave Executors ======") | |
println() | |
// CJOC Shared Slaves | |
def sharedSlaves = Jenkins.instance.allItems.grep{ | |
it.class.name == 'com.cloudbees.opscenter.server.model.SharedSlave' | |
} | |
int sharedSlaveExecutorCount = sharedSlaves.inject(0, {a, c -> a + c.numExecutors}) | |
println("| Node Name | Type | Executors |") | |
sharedSlaves.each { | |
println "| ${it.displayName} | ${it.class.simpleName} | ${it.numExecutors} |" | |
} | |
println() | |
println("Total: " + sharedSlaveExecutorCount + " executors") | |
println() | |
println("====== Cloud Slave Executors ======") | |
println() | |
println("| Cloud Name | Type | Max. Executors |") | |
int totalInstanceCaps | |
Jenkins.instance.clouds.each { cloud -> | |
Integer instanceCaps | |
try{ | |
instanceCaps = cloud.templates?.inject(0, {a, c -> a + (c.numExecutors * c.instanceCap)}) | |
totalInstanceCaps += instanceCaps | |
}catch(e){ | |
}finally{ | |
} | |
println "| ${cloud.displayName} | ${cloud.descriptor.displayName} | ${instanceCaps ?: ''} |" | |
} | |
println() | |
if(totalInstanceCaps != null && totalInstanceCaps > 0){ | |
println("Total: up to " + totalInstanceCaps + " executors") | |
} else { | |
println("Total: None") | |
} | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment