-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollect-pilots.py
executable file
·176 lines (129 loc) · 6.32 KB
/
collect-pilots.py
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
#!/bin/env python
# Gather pilot informaton from the CONNECT Panda Queues
# Import some standard python utilities
import sys, time
import classad, htcondor
# Base path under which to store the gathered data
graphBase = "collect.connect.atlas.pilots"
# The Collectors which are running AutoPyFactory for which we are to Collect the data
collectorADs = [
"rccf-gk.mwt2.org:11010?sock=collector"
]
# The queues which are running pilots on these AutoPyFactories
queueADs = [
[ 'CONNECT' ], # Production SCORE
[ 'CONNECT_CLOUD' ], # Production SCORE
[ 'CONNECT_MCORE' ], # Production MCORE
[ 'CONNECT_PILE' ], # Production PILE
[ 'CONNECT_PILE_MCORE' ], # Production PILE MCORE
[ 'ANALY_CONNECT' ], # Analysis SCORE
[ 'ANALY_CONNECT_SHORT' ], # Analysis SCORE
]
# Start with a blank set of metrics
collectMetrics = {}
# This will add a metric or increment it
def addMetric(metricName, count=1) :
# Build a metric name using the current Collector name
metric = "%s.%s" % (scheddCollect, metricName)
if (metric in collectMetrics) :
collectMetrics[metric] += count
else :
collectMetrics[metric] = count
# Search all Collectors listed
for collectorAD in collectorADs[:] :
# The full name of the collector
collectorName = collectorAD
# Get the Collector information
collectorClassAD = htcondor.Collector(collectorName)
try :
# Get a list of all Schedds associated with this Collector
scheddADs = collectorClassAD.locateAll(htcondor.DaemonTypes.Schedd)
except IOError, e :
print >>sys.stderr, '%s Unable to contact collector to fetch schedds (collector: %s): %s' % (time.strftime("%Y-%m-%d %H:%M:%S"), collectorName, str(e))
continue
# Replace any . with _ in the Collector Name
scheddCollector = '_'.join(collectorName.split('.'))
# Find the jobs from each Schedd
for scheddAD in scheddADs[:] :
# The full name of this schedd
scheddName = scheddAD['Name']
# Replace any . with _ in the Schedd Name
scheddCollect = '_'.join(scheddName.split('.'))
# Get all the ClassADs for this Schedd associated with this Collector
try :
scheddClassADs = collectorClassAD.locate(htcondor.DaemonTypes.Schedd, scheddName)
scheddClassAD = htcondor.Schedd(scheddClassADs)
except IOError, e :
print >>sys.stderr, '%s Unable to contact schedd to fetch schedd classADs (schedd: %s) (collector: %s): %s' % (time.strftime("%Y-%m-%d %H:%M:%S"), scheddName, collectorName, str(e))
continue
# Loop over each Queue
for queueAD in queueADs[:] :
# Extract the queue name
queueName = queueAD[0]
# Running gathers lots of information
try :
jobADs = scheddClassAD.query('MATCH_APF_QUEUE=="%s" && jobstatus==2' % queueName)
except IOError, e :
print >>sys.stderr, '%s Unable to contact schedd to fetch job classADs (schedd: %s) (collector: %s): %s' % (time.strftime("%Y-%m-%d %H:%M:%S"), scheddName, collectorName, str(e))
continue
# Loop over each job that is running
for jobAD in jobADs[:] :
# Get the number of cores used this job
try :
jobCores = jobAD['MachineAttrCpus0']
except :
jobCores = 1
# Get the Pool the job is running in replacing any . with _
jobRemotePool = '_'.join(jobAD['RemotePool'].split('.'))
addMetric( "%s.Running" % queueName )
addMetric( "%s.%s.Running" % (queueName, jobRemotePool) )
addMetric( "%s.Cores" % queueName , jobCores)
addMetric( "%s.%s.Cores" % (queueName, jobRemotePool) , jobCores)
# # Unexpanded
# try :
# jobADs = scheddClassAD.query('MATCH_APF_QUEUE=="%s" && jobstatus==0' % queueName)
# for jobAD in jobADs[:] : addMetric( "%s.Unexpanded" % queueName )
# except IOError, e :
# print >>sys.stderr, '%s Unable to contact schedd to fetch jobADs (schedd: %s) (collector: %s): %s' % (time.strftime("%Y-%m-%d %H:%M:%S"), scheddName, collectorName, str(e))
# continue
# Idle jobs
try :
jobADs = scheddClassAD.query('MATCH_APF_QUEUE=="%s" && jobstatus==1' % queueName)
for jobAD in jobADs[:] : addMetric( "%s.Idle" % queueName )
except IOError, e :
print >>sys.stderr, '%s Unable to contact schedd to fetch jobADs (schedd: %s) (collector: %s): %s' % (time.strftime("%Y-%m-%d %H:%M:%S"), scheddName, collectorName, str(e))
continue
# # Removed
# try :
# jobADs = scheddClassAD.query('MATCH_APF_QUEUE=="%s" && jobstatus==3' % queueName)
# for jobAD in jobADs[:] : addMetric( "%s.Removed" % queueName )
# except IOError, e :
# print >>sys.stderr, '%s Unable to contact schedd to fetch jobADs (schedd: %s) (collector: %s): %s' % (time.strftime("%Y-%m-%d %H:%M:%S"), scheddName, collectorName, str(e))
# continue
# # Completed
# try :
# jobADs = scheddClassAD.query('MATCH_APF_QUEUE=="%s" && jobstatus==4' % queueName)
# for jobAD in jobADs[:] : addMetric( "%s.Completed" % queueName )
# except IOError, e :
# print >>sys.stderr, '%s Unable to contact schedd to fetch jobADs (schedd: %s) (collector: %s): %s' % (time.strftime("%Y-%m-%d %H:%M:%S"), scheddName, collectorName, str(e))
# continue
# # Held
# try :
# jobADs = scheddClassAD.query('MATCH_APF_QUEUE=="%s" && jobstatus==5' % queueName)
# for jobAD in jobADs[:] : addMetric( "%s.Held" % queueName )
# except IOError, e :
# print >>sys.stderr, '%s Unable to contact schedd to fetch jobADs (schedd: %s) (collector: %s): %s' % (time.strftime("%Y-%m-%d %H:%M:%S"), scheddName, collectorName, str(e))
# continue
# # Submission error
# try :
# jobADs = scheddClassAD.query('MATCH_APF_QUEUE=="%s" && jobstatus==6' % queueName)
# for jobAD in jobADs[:] : addMetric( "%s.Error" % queueName )
# except IOError, e :
# print >>sys.stderr, '%s Unable to contact schedd to fetch jobADs (schedd: %s) (collector: %s): %s' % (time.strftime("%Y-%m-%d %H:%M:%S"), scheddName, collectorName, str(e))
# continue
# Get the current time
timestamp = int(time.time())
# Loop over each metric and display its total and the current time
for metricName in collectMetrics :
metricCount = collectMetrics[metricName]
print "%s.%s %s %s" % (graphBase, metricName, metricCount, timestamp)