forked from dmwm/cms-htcondor-es
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spider_cms.py
executable file
·272 lines (249 loc) · 7.12 KB
/
spider_cms.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/usr/bin/env python
"""
Script for processing the contents of the CMS pool.
"""
import os
import sys
import time
import signal
import logging
import argparse
import multiprocessing
try:
import htcondor_es
except ImportError:
if os.path.exists("src/htcondor_es/__init__.py") and "src" not in sys.path:
sys.path.append("src")
import htcondor_es.history
import htcondor_es.queues
from htcondor_es.utils import (
get_schedds,
get_schedds_from_file,
set_up_logging,
send_email_alert,
)
from htcondor_es.utils import collect_metadata, TIMEOUT_MINS
def main_driver(args):
"""
Driver method for the spider script.
"""
starttime = time.time()
signal.alarm(TIMEOUT_MINS * 60 + 60)
# Get all the schedd ads
schedd_ads = []
if args.collectors_file:
schedd_ads = get_schedds_from_file(args, collectors_file=args.collectors_file)
del (
args.collectors_file
) # sending a file through postprocessing will cause problems.
else:
schedd_ads = get_schedds(args, collectors=args.collectors)
logging.warning("&&& There are %d schedds to query.", len(schedd_ads))
pool = multiprocessing.Pool(processes=args.query_pool_size)
metadata = collect_metadata()
if not args.skip_history:
htcondor_es.history.process_histories(
schedd_ads=schedd_ads,
starttime=starttime,
pool=pool,
args=args,
metadata=metadata,
)
# Now that we have the fresh history, process the queues themselves.
if args.process_queue:
htcondor_es.queues.process_queues(
schedd_ads=schedd_ads,
starttime=starttime,
pool=pool,
args=args,
metadata=metadata,
)
pool.close()
pool.join()
logging.warning(
"@@@ Total processing time: %.2f mins", ((time.time() - starttime) / 60.0)
)
return 0
def main():
"""
Main method for the spider_cms script.
Parses arguments and invokes main_driver
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--process_queue",
action="store_true",
dest="process_queue",
help="Process also schedd queue (Running/Idle/Pending jobs)",
)
parser.add_argument(
"--feed_es", action="store_true", dest="feed_es", help="Feed to Elasticsearch"
)
parser.add_argument(
"--feed_es_for_queues",
action="store_true",
dest="feed_es_for_queues",
help="Feed queue data also to Elasticsearch",
)
parser.add_argument(
"--feed_amq", action="store_true", dest="feed_amq", help="Feed to CERN AMQ"
)
parser.add_argument(
"--schedd_filter",
default="",
type=str,
dest="schedd_filter",
help=(
"Comma separated list of schedd names to process "
"[default is to process all]"
),
)
parser.add_argument(
"--skip_history",
action="store_true",
dest="skip_history",
help="Skip processing the history. (Only do queues.)",
)
parser.add_argument(
"--read_only",
action="store_true",
dest="read_only",
help="Only read the info, don't submit it.",
)
parser.add_argument(
"--dry_run",
action="store_true",
dest="dry_run",
help=(
"Don't even read info, just pretend to. (Still "
"query the collector for the schedd's though.)"
),
)
parser.add_argument(
"--max_documents_to_process",
default=0,
type=int,
dest="max_documents_to_process",
help=(
"Abort after this many documents (per schedd). "
"[default: %(default)d (process all)]"
),
)
parser.add_argument(
"--keep_full_queue_data",
action="store_true",
dest="keep_full_queue_data",
help="Drop all but some fields for running jobs.",
)
parser.add_argument(
"--amq_bunch_size",
default=5000,
type=int,
dest="amq_bunch_size",
help=("Send docs to AMQ in bunches of this number " "[default: %(default)d]"),
)
parser.add_argument(
"--es_bunch_size",
default=250,
type=int,
dest="es_bunch_size",
help=("Send docs to ES in bunches of this number " "[default: %(default)d]"),
)
parser.add_argument(
"--query_queue_batch_size",
default=50,
type=int,
dest="query_queue_batch_size",
help=(
"Send docs to listener in batches of this number " "[default: %(default)d]"
),
)
parser.add_argument(
"--upload_pool_size",
default=8,
type=int,
dest="upload_pool_size",
help=("Number of parallel processes for uploading " "[default: %(default)d]"),
)
parser.add_argument(
"--query_pool_size",
default=8,
type=int,
dest="query_pool_size",
help=("Number of parallel processes for querying " "[default: %(default)d]"),
)
parser.add_argument(
"--es_hostname",
default="es-cms.cern.ch",
type=str,
dest="es_hostname",
help="Hostname of the elasticsearch instance to be used "
"[default: %(default)s]",
)
parser.add_argument(
"--es_port",
default=9203,
type=int,
dest="es_port",
help="Port of the elasticsearch instance to be used " "[default: %(default)d]",
)
parser.add_argument(
"--es_index_template",
default="cms",
type=str,
dest="es_index_template",
help=(
"Trunk of index pattern. "
"Needs to start with 'cms' "
"[default: %(default)s]"
),
)
parser.add_argument(
"--log_dir",
default="log/",
type=str,
dest="log_dir",
help="Directory for logging information [default: %(default)s]",
)
parser.add_argument(
"--log_level",
default="WARNING",
type=str,
dest="log_level",
help="Log level (CRITICAL/ERROR/WARNING/INFO/DEBUG) " "[default: %(default)s]",
)
parser.add_argument(
"--email_alerts",
default=[],
action="append",
dest="email_alerts",
help="Email addresses for alerts [default: none]",
)
parser.add_argument(
"--collectors",
default=[
"cmssrv623.fnal.gov:9620",
"cmsgwms-collector-tier0.cern.ch:9620",
"cmssrv276.fnal.gov",
"cmsgwms-collector-itb.cern.ch",
"vocms0840.cern.ch",
],
action="append",
dest="collectors",
help="Collectors' addresses",
)
parser.add_argument(
"--collectors_file",
default=None,
action="store",
type=argparse.FileType("r"),
dest="collectors_file",
help="FIle defining the pools and collectors",
)
args = parser.parse_args()
set_up_logging(args)
# --dry_run implies read_only
args.read_only = args.read_only or args.dry_run
main_driver(args)
if __name__ == "__main__":
main()