forked from abrt/retrace-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.wsgi
201 lines (170 loc) · 6.74 KB
/
stats.wsgi
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
#!/usr/bin/python3
from retrace import *
sys.path.insert(0, "/usr/share/retrace-server/")
status_queries = {"SELECT COUNT(*) FROM tasks": "{total}",
"SELECT COUNT(*) FROM tasks WHERE status = {0}".format(STATUS_SUCCESS): "{success}",
"SELECT COUNT(*) FROM tasks WHERE status = {0}".format(STATUS_FAIL): "{fail}",
"SELECT COUNT(*) FROM reportfull": "{denied}",
}
def replace_by_count(input, q, key, query):
query.execute(q)
row = query.fetchone()
return input.replace(key, str(row[0]))
plugins = plugins.Plugins()
def application(environ, start_response):
con = init_crashstats_db()
query = con.cursor()
request = Request(environ)
_ = parse_http_gettext("%s" % request.accept_language,
"%s" % request.accept_charset)
strings = {
"{_Architecture}": _("Architecture"),
"{_Architectures}": _("Architectures"),
"{_Build-id}": _("Build-id"),
"{_Count}": _("Count"),
"{_Denied_jobs}": _("Denied jobs"),
"{_Failed}": _("Failed"),
"{_First_retrace}": _("First retrace"),
"{_Global_statistics}": _("Global statistics"),
"{_Missing_build-ids}": _("Missing build-ids"),
"{_Name}": _("Name"),
"{_Release}": _("Release"),
"{_Releases}": _("Releases"),
"{_Required_packages}": _("Required packages"),
"{_Retraced_packages}": _("Retraced packages"),
"{_Retrace_Server_statistics}": _("Retrace Server statistics"),
"{_Shared_object_name}": _("Shared object name"),
"{_Successful}": _("Successful"),
"{_Total}": _("Total"),
"{_Versions}": _("Versions"),
}
with open("/usr/share/retrace-server/stats.xhtml") as f:
output = f.read(1 << 20) # 1 MB
for key in strings:
output = output.replace(key, strings[key])
output = output.replace("{host}", environ["HTTP_HOST"])
# fill in statuses
for key in status_queries.keys():
output = replace_by_count(output, key, status_queries[key], query)
# first retrace
query.execute("SELECT starttime FROM tasks \
ORDER BY starttime ASC LIMIT 0,1")
row = query.fetchone()
if row:
date = time.localtime(int(row[0]))
output = output.replace("{first}", "%04d-%02d-%02d %02d:%02d" % \
(date.tm_year, date.tm_mon, \
date.tm_mday, date.tm_hour, \
date.tm_min))
else:
output = output.replace("{first}", "No retrace yet")
# by architecture
query.execute("SELECT arch, COUNT(*) FROM tasks WHERE arch IS NOT NULL \
GROUP BY arch")
tablerows = []
i = 1
row = query.fetchone()
while row:
if i % 2:
style = "odd"
else:
style = "even"
tablerows.append("<tr class=\"%s\">" % style)
tablerows.append(" <td>%s</td>" % str(row[0]))
tablerows.append(" <td>%s</td>" % str(row[1]))
tablerows.append("</tr>")
row = query.fetchone()
i += 1
# spaces to keep the xml nicely indented
output = output.replace("{arch_rows}", "\n ".join(tablerows))
# by release
versions = {}
for entry in plugins.all():
for key in entry.versionlist:
versions[key] = entry.displayrelease
tablerows = []
i = 1
for key in versions.keys():
query.execute("SELECT COUNT(*) FROM tasks WHERE version LIKE '%"+key+"'")
row = query.fetchone()
retstr = str(versions[key]) + " " + str(key[-1])
if i % 2:
style = "odd"
else:
style = "even"
if row[0] > 0:
tablerows.append("<tr class=\"%s\">" % style)
tablerows.append(" <td>%s</td>" % retstr)
tablerows.append(" <td>%s</td>" % str(row[0]))
tablerows.append("</tr>")
i += 1
output = output.replace("{release_rows}", "\n ".join(tablerows))
# most retraced
query.execute("SELECT package, COUNT(*) as c FROM tasks GROUP BY package \
ORDER BY c DESC LIMIT 0,37")
tablerows = []
i = 1
row = query.fetchone()
while row:
if i % 2:
style = "odd"
else:
style = "even"
tablerows.append("<tr class=\"%s\">" % style)
tablerows.append(" <td>%s</td>" % str(row[0]))
tablerows.append(" <td>%s</td>" % str(row[1]))
tablerows.append("</tr>")
row = query.fetchone()
i += 1
# spaces to keep the xml nicely indented
output = output.replace("{retraced_rows}", "\n ".join(tablerows))
# most required
query.execute("SELECT name, COUNT(*) AS cnt, SUM(c) AS s FROM \
(SELECT pkgid, COUNT(*) AS c FROM packages_tasks \
GROUP BY pkgid) AS sub, packages WHERE \
NOT packages.name LIKE '%-debuginfo' AND \
packages.id = sub.pkgid GROUP BY packages.name \
ORDER BY s DESC LIMIT 0,32")
tablerows = []
i = 1
row = query.fetchone()
while row:
if i % 2:
style = "odd"
else:
style = "even"
tablerows.append("<tr class=\"%s\">" % style)
tablerows.append(" <td>%s</td>" % str(row[0]))
tablerows.append(" <td>%s</td>" % str(row[1]))
tablerows.append(" <td>%s</td>" % str(row[2]))
tablerows.append("</tr>")
row = query.fetchone()
i += 1
# spaces to keep the xml nicely indented
output = output.replace("{required_rows}", "\n ".join(tablerows))
# most missing build-ids
query.execute("SELECT * FROM (SELECT buildid, soname, COUNT(*) as c \
FROM buildids WHERE buildid = '-' OR buildid IS NULL \
GROUP BY soname UNION SELECT buildid, soname, COUNT(*) as c \
FROM buildids WHERE buildid != '-' AND buildid IS NOT NULL \
GROUP BY buildid) ORDER BY c DESC LIMIT 0,20")
tablerows = []
i = 1
row = query.fetchone()
while row:
if i % 2:
style = "odd"
else:
style = "even"
tablerows.append("<tr class=\"%s\">" % style)
tablerows.append(" <td>%s</td>" % str(row[0]))
tablerows.append(" <td>%s</td>" % str(row[1]))
tablerows.append(" <td>%s</td>" % str(row[2]))
tablerows.append("</tr>")
row = query.fetchone()
i += 1
# spaces to keep the xml nicely indented
output = output.replace("{buildids_rows}", "\n ".join(tablerows))
con.close()
return response(start_response, "200 OK", output,
[("Content-Type", "text/xml")])