-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsummaryWMStatsFailures.py
65 lines (52 loc) · 2.1 KB
/
summaryWMStatsFailures.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
#!/usr/bin/env python
"""
Fetch data from wmstats - for a specific workflow - and print a summary of job
failures (amount of failures for each task that can be recovered).
"""
from __future__ import print_function
import httplib
import json
import os
import sys
from pprint import pformat
def getWMStatsData(workflow):
url = 'cmsweb.cern.ch'
headers = {"Accept": "application/json", "Content-type": "application/json"}
conn = httplib.HTTPSConnection(url, cert_file=os.getenv('X509_USER_PROXY'), key_file=os.getenv('X509_USER_PROXY'))
urn = "/wmstatsserver/data/request/%s" % workflow
conn.request("GET", urn, headers=headers)
r2 = conn.getresponse()
request = json.loads(r2.read())["result"][0]
return request
def main():
if len(sys.argv) != 2:
print("A workflow name must be provided!")
sys.exit(1)
wf = sys.argv[1]
data = getWMStatsData(wf)
if 'AgentJobInfo' not in data[wf]:
print("Request doesn't have a `AgentJobInfo` key, nothing to be done")
sys.exit(2)
data = data[wf]['AgentJobInfo']
summary = {}
for agent in data.keys():
print("\nChecking AgentJobInfo for: %s" % agent)
print(" Skipped files: %s" % pformat(data[agent]['skipped']))
print(" Overall agent status:\t\t %s" % data[agent]['status'])
for task, values in data[agent]['tasks'].iteritems():
if values['jobtype'] not in ['Production', 'Processing', 'Merge', 'Harvest']:
# print("Skipping task type %s, for %s" % (values['jobtype'], task))
continue
taskName = task.split('/')[-1]
if 'status' not in values:
print("'status' key not available under task: %s" % taskName)
continue
if 'failure' in values['status']:
taskName = task.split('/')[-1]
summary.setdefault(taskName, 0)
summary[taskName] += sum(values['status']['failure'].values())
print("\nSummary of failures for workflow: %s" % wf)
print(pformat(summary))
sys.exit(0)
if __name__ == '__main__':
sys.exit(main())