forked from stfc/telegraf-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics-influxdb-condor-cpu-unused
executable file
·48 lines (41 loc) · 1.74 KB
/
metrics-influxdb-condor-cpu-unused
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
#!/usr/bin/python
import classad
import htcondor
# initialization
coresDraining = 0
coresPreemptable = 0
coresMemory = 0
coresUnhealthy = 0
coresStartJobs = 0
coresOther = 0
# Find minimum requested memory from all idle jobs
minimumMemory = 1000000
coll = htcondor.Collector()
results = coll.query(htcondor.AdTypes.Schedd, "true", ["Name"])
for result in results:
host = result["Name"]
if 'arc-ce' in host:
scheddAd = coll.locate(htcondor.DaemonTypes.Schedd, host)
schedd = htcondor.Schedd(scheddAd)
jobs = schedd.query('JobStatus == 1', ["RequestMemory"])
for job in jobs:
if job["RequestMemory"] < minimumMemory and job["RequestMemory"] > 0:
minimumMemory = job["RequestMemory"]
coll = htcondor.Collector()
results = coll.query(htcondor.AdTypes.Startd, "PartitionableSlot =?= True", ["Name", "TotalSlotCpus", "Cpus", "TotalSlotMemory", "Memory", "State", "PREEMPTABLE_ONLY", "StartJobs", "NODE_IS_HEALTHY"])
for result in results:
if result["Cpus"] > 0:
if str(result["State"]) == "Drained":
coresDraining += result["Cpus"]
elif 'PREEMPTABLE_ONLY' in result and result['PREEMPTABLE_ONLY'] == True:
coresPreemptable += result["Cpus"]
elif 'NODE_IS_HEALTHY' in result and result["NODE_IS_HEALTHY"] != True:
coresUnhealthy += result["Cpus"]
elif result["StartJobs"] == False:
coresStartJobs += result["Cpus"]
elif result["Memory"] < minimumMemory:
coresMemory += result["Cpus"]
else:
coresOther += result["Cpus"]
data = 'CoresNotUsed draining=%d,preemptable=%d,unhealthy=%d,disabled=%d,memory=%d,other=%d' % (coresDraining, coresPreemptable, coresUnhealthy, coresStartJobs, coresMemory, coresOther)
print data