forked from cloudbees/jenkins-scripts
-
Notifications
You must be signed in to change notification settings - Fork 6
/
count-executors.groovy
74 lines (62 loc) · 2.23 KB
/
count-executors.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*** 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