forked from stfc/telegraf-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics-influxdb-condor-general
executable file
·184 lines (157 loc) · 8.1 KB
/
metrics-influxdb-condor-general
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/python
import classad
import htcondor
coll = htcondor.Collector()
# Number of collectors
results = coll.query(htcondor.AdTypes.Collector, "true", ["Name"])
numCollectors = len(results)
data = 'NumCollectors value=' + str(numCollectors) + '\n'
# Negotiator
results = coll.query(htcondor.AdTypes.Negotiator, "true", ["Machine", "LastNegotiationCycleDuration0", "RecentDaemonCoreDutyCycle"])
numNegotiators = len(results)
data += 'NumNegotiators value=' + str(numNegotiators) + '\n'
for result in results:
data += 'NegotiatorRecentDaemonCoreDutyCycle,host=' + result["Machine"] + ' value=' + str(result["RecentDaemonCoreDutyCycle"]) + '\n'
data += 'LastNegotiationCycleDuration,host=' + result["Machine"] + ' value=' + str(result["LastNegotiationCycleDuration0"]) + '\n'
# Schedds
results = coll.query(htcondor.AdTypes.Schedd, "true", ["Name", "RecentDaemonCoreDutyCycle", "Autoclusters", "RecentJobsStarted", "RecentJobsExited", "RecentJobsSubmitted", "RecentJobsKilled", "RecentStatsLifetime"])
numSchedds = len(results)
data += 'NumSchedds value=' + str(numSchedds) + '\n'
for result in results:
data += 'ScheddRecentDaemonCoreDutyCycle,host=' + result["Name"] + ' value=' + str(result["RecentDaemonCoreDutyCycle"]) + '\n'
data += 'AutoClusters,host=' + result["Name"] + ' value=' + str(result["Autoclusters"]) + '\n'
lifetime = result["RecentStatsLifetime"]
recentJobsStarted = 0
recentJobsExited = 0
recentJobsSubmitted = 0
recentJobsKilled = 0
if lifetime > 0:
recentJobsStarted = result["RecentJobsStarted"]*60.0/lifetime
recentJobsExited = result["RecentJobsExited"]*60.0/lifetime
recentJobsSubmitted = result["RecentJobsSubmitted"]*60.0/lifetime
recentJobsKilled = result["RecentJobsKilled"]*60.0/lifetime
data += 'RecentJobs,host=' + result["Name"] + ' Started=' + str(recentJobsStarted) + ',Exited=' + str(recentJobsExited) + ',Submitted=' + str(recentJobsSubmitted) + ',Killed=' + str(recentJobsKilled) + '\n'
# Startds
numStartds = 0
numGoodStartds = 0
memoryUsed = 0
memoryFree = 0
cpuUsed = 0
cpuFree = 0
cpusUseable = 0
cpuUsedCloud = 0
cpuFreeCloud = 0
cpuUsedMesos = 0
cpuFreeMesos = 0
numStartdsPreemptableOnly = 0
TotalLoadAvg = 0
MemoryUseableTotal = 0
TotalUseableDisk = 0
cpuUsedMesosI = {}
cpuFreeMesosI = {}
memUsedMesosI = {}
memFreeMesosI = {}
numStartdsMesosI = {}
numStartdsGoodMesosI = {}
numCpusUseableMesosI = {}
numCpusUseableMesos = 0
numCpusMesos = 0
results = coll.query(htcondor.AdTypes.Startd, "PartitionableSlot=?=True", ["NODE_IS_HEALTHY", "StartJobs", "TotalCpus", "Cpus", "TotalMemory", "Memory","Machine","PREEMPTABLE_ONLY", "MESOS_TASK_ID", "CONTAINER_IMAGE_NAME", "RecentJobStarts", "TotalLoadAvg", "TotalDisk"])
for result in results:
cpuUsed += result["TotalCpus"] - result["Cpus"]
cpuFree += result["Cpus"]
cpusUseable += result["TotalCpus"] - result["Cpus"]
memoryUsed += result["TotalMemory"] - result["Memory"]
memoryFree += result["Memory"]
TotalLoadAvg += result["TotalLoadAvg"]
numStartds += 1
if "NODE_IS_HEALTHY" in result and "StartJobs" in result:
if result["NODE_IS_HEALTHY"] == True and result["StartJobs"] == True:
numGoodStartds += 1
cpusUseable += result["Cpus"]
MemoryUseableTotal += result["TotalMemory"]
TotalUseableDisk += result["TotalDisk"]
if "Machine" in result:
if "RecentJobStarts" in result and result["Machine"] != "":
data += 'RecentJobStarts,host=%s value=%d\n' % (result["Machine"], result["RecentJobStarts"])
if "nubes" in result["Machine"]:
cpuUsedCloud += result["TotalCpus"] - result["Cpus"]
cpuFreeCloud += result["Cpus"]
if "MESOS_TASK_ID" in result:
cpuUsedMesos += result["TotalCpus"] - result["Cpus"]
cpuFreeMesos += result["Cpus"]
if "CONTAINER_IMAGE_NAME" in result:
if not cpuUsedMesosI.has_key(result["CONTAINER_IMAGE_NAME"]):
cpuUsedMesosI[result["CONTAINER_IMAGE_NAME"]] = 0
if not cpuFreeMesosI.has_key(result["CONTAINER_IMAGE_NAME"]):
cpuFreeMesosI[result["CONTAINER_IMAGE_NAME"]] = 0
if not memUsedMesosI.has_key(result["CONTAINER_IMAGE_NAME"]):
memUsedMesosI[result["CONTAINER_IMAGE_NAME"]] = 0
if not memFreeMesosI.has_key(result["CONTAINER_IMAGE_NAME"]):
memFreeMesosI[result["CONTAINER_IMAGE_NAME"]] = 0
if not numStartdsMesosI.has_key(result["CONTAINER_IMAGE_NAME"]):
numStartdsMesosI[result["CONTAINER_IMAGE_NAME"]] = 0
if not numStartdsGoodMesosI.has_key(result["CONTAINER_IMAGE_NAME"]):
numStartdsGoodMesosI[result["CONTAINER_IMAGE_NAME"]] = 0
if not numCpusUseableMesosI.has_key(result["CONTAINER_IMAGE_NAME"]):
numCpusUseableMesosI[result["CONTAINER_IMAGE_NAME"]] = 0
cpuFreeMesosI[result["CONTAINER_IMAGE_NAME"]] += result["Cpus"]
cpuUsedMesosI[result["CONTAINER_IMAGE_NAME"]] += result["TotalCpus"] - result["Cpus"]
memFreeMesosI[result["CONTAINER_IMAGE_NAME"]] += result["Memory"]
memUsedMesosI[result["CONTAINER_IMAGE_NAME"]] += result["TotalMemory"] - result["Memory"]
numStartdsMesosI[result["CONTAINER_IMAGE_NAME"]] += 1
numCpusMesos += result["TotalCpus"]
if "NODE_IS_HEALTHY" in result and "StartJobs" in result:
if result["NODE_IS_HEALTHY"] == True and result["StartJobs"] == True:
numStartdsGoodMesosI[result["CONTAINER_IMAGE_NAME"]] += 1
numCpusUseableMesosI[result["CONTAINER_IMAGE_NAME"]] += result["Cpus"]
numCpusUseableMesos += result["Cpus"]
if "PREEMPTABLE_ONLY" in result:
if result["PREEMPTABLE_ONLY"]:
numStartdsPreemptableOnly += 1
data += 'NumCpusUsed value=' + str(cpuUsed) + '\n'
data += 'NumCpusFree value=' + str(cpuFree) + '\n'
data += 'NumCpusUseable value=' + str(cpusUseable) + '\n'
data += 'NumMemoryUsed value=' + str(memoryUsed) + '\n'
data += 'NumMemoryFree value=' + str(memoryFree) + '\n'
data += 'MemoryUseableTotal value=' + str(MemoryUseableTotal) + '\n'
data += 'NumStartds value=' + str(numStartds) + '\n'
data += 'NumGoodStartds value=' + str(numGoodStartds) + '\n'
data += 'NumCpusUsedCloud value=' + str(cpuUsedCloud) + '\n'
data += 'NumCpusFreeCloud value=' + str(cpuFreeCloud) + '\n'
data += 'NumCpusUsedMesos value=' + str(cpuUsedMesos) + '\n'
data += 'NumCpusFreeMesos value=' + str(cpuFreeMesos) + '\n'
data += 'NumStartdsPreemptableOnly value=' + str(numStartdsPreemptableOnly) + '\n'
data += 'TotalLoadAvg value=' + str(TotalLoadAvg) + '\n'
data += 'TotalUseableDisk value=' + str(TotalUseableDisk) + '\n'
if numCpusMesos > 0:
cpusUsedPercentMesos = 100.0*float(cpuUsedMesos)/numCpusMesos
cpusUseablePercentMesos = 100.0*float(numCpusUseableMesos)/numCpusMesos
else:
cpusUsedPercentMesos = 0
cpusUseablePercentMesos = 0
if numCpusUseableMesos > 0:
cpusUseableUsedPercentMesos = 100.0*float(cpuUsedMesos)/numCpusUseableMesos
else:
cpusUseableUsedPercentMesos = 0
data += 'mesoscpus percentUsedOfUseable=' + str(cpusUseableUsedPercentMesos) + ',percentUseable=' + str(cpusUseablePercentMesos) + ',percentUsed=' + str(cpusUsedPercentMesos) + '\n'
for image in cpuUsedMesosI:
data += 'mesosbatch,image='+image+' freeCpu='+str(cpuFreeMesosI[image])+',usedCpu='+str(cpuUsedMesosI[image])+',freeMemory='+str(memFreeMesosI[image])+',usedMemory='+str(memUsedMesosI[image])+',numStartds='+str(numStartdsMesosI[image])+',numGoodStartds='+str(numStartdsGoodMesosI[image])+'\n'
if cpuUsed + cpuFree > 0:
cpuUsedPercent = float(cpuUsed)*100/(cpuUsed + cpuFree)
cpuUseablePercent = float(cpusUseable)*100/(cpuUsed + cpuFree)
else:
cpuUsedPercent = 0
cpuUseablePercent = 0
if cpusUseable > 0:
cpuUsedPercentGood = float(cpuUsed)*100/cpusUseable
else:
cpuUsedPercentGood = 0
data += 'cpus numUsed=' + str(int(cpuUsed)) + ',' + \
'numFree=' + str(cpuFree) + ',' + \
'numTotal=' + str(int(cpuFree+cpuUsed)) + ',' + \
'numTotalUseable=' + str(int(cpusUseable)) + ',' + \
'percentUsed=' + str(cpuUsedPercent) + ',' + \
'percentUseable=' + str(cpuUseablePercent) + ',' + \
'percentUsedOfUseable=' + str(cpuUsedPercentGood) + '\n'
print data