forked from oVirt/vdsm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repoplot
executable file
·431 lines (355 loc) · 13.4 KB
/
repoplot
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
#!/usr/bin/python3
#
# Copyright 2014 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Refer to the README and COPYING files for full details of the license
#
"""
Parse repoStats log lines and plot graphs of lastCheck and read delay for all
storage domains.
Usage: repoplot vdsm.log [...]
Requirements: python-pandas
"""
from __future__ import absolute_import
import argparse
import fileinput
import sys
from collections import defaultdict
from collections import namedtuple
# Use non-interactive backend so we can generate graphs on a headless server.
# See http://matplotlib.org/faq/howto_faq.html#howto-webapp
import matplotlib
matplotlib.use("Agg")
import pandas
from matplotlib import pyplot
def main(args):
args = parse_args(args)
stats = parse(args.files)
filename = "%s.%s" % ((args.name or args.files[0]), args.format)
plot(stats, filename, (args.width, args.height))
def parse_args(args):
parser = argparse.ArgumentParser(
description="Visualize storage monitoring")
parser.add_argument("--name", "-n", dest="name",
help="output file name (default first log file name)")
parser.add_argument("--format", "-f", dest="format",
help="output file format (default pdf)")
parser.add_argument("--width", "-x", dest="width", type=int,
help="output file width in inches (default 20)")
parser.add_argument("--height", "-y", dest="height", type=int,
help="output file height in inches (default 30)")
parser.add_argument("files", nargs="+",
help="vdsm log files to process")
parser.set_defaults(name=None, format="pdf", width=20, height=30)
return parser.parse_args(args)
Log = namedtuple("Log", (
"thread",
"loglevel",
"timestamp",
"module",
"lineno",
"logger",
"func",
"text"
))
class Stats(object):
def __init__(self):
self.repostats = defaultdict(DomainStats)
self.lvm_commands = defaultdict(CommandStats)
self.mailbox_commands = defaultdict(CommandStats)
self.monitor_commands = defaultdict(CommandStats)
self.disk_commands = defaultdict(CommandStats)
class DomainStats(object):
def __init__(self):
self.timestamp = []
self.lastcheck = []
self.delay = []
def add(self, timestamp, lastcheck, delay):
"""
Called when repoStats event was detected for this domain.
"""
self.timestamp.append(timestamp)
self.lastcheck.append(lastcheck)
self.delay.append(delay)
class CommandStats(object):
def __init__(self):
self.timestamp = []
self.runtime = []
self.running = False
def start(self, timestamp):
"""
Called when a commnad start log was detected for this thread.
"""
self.running = True
self.timestamp.append(timestamp)
self.runtime.append(0)
def end(self, timestamp):
"""
Called when a commnad end log was detected for this thread.
"""
if not self.running:
return
self.running = False
timedelta = timestamp - self.timestamp[-1]
self.timestamp.append(timestamp)
self.runtime.append(timedelta.total_seconds())
# Add zero in the same timestamp, to get nicer triangles in the plots.
self.timestamp.append(timestamp)
self.runtime.append(0)
def parse(files):
"""
Parse patterns from vdsm log and return Stats object.
"""
patterns = [
# Match repoStats response log:
# jsonrpc.Executor/5::INFO::2016-02-17
# 19:26:33,837::logUtils::51::dispatcher::(wrapper) Run and protect:
# repoStats, Return response: ...
(add_repostats, "Run and protect: repoStats, Return response:",
"repostats"),
# Match storage domains getReadDelay commands.
#
# Begin:
# Thread-16::DEBUG::2016-02-17
# 20:14:37,049::blockSD::436::Storage.Misc.excCmd::(getReadDelay)
# /usr/bin/taskset --cpu-list 0-7 /usr/bin/dd ...
#
# End:
# Thread-16::DEBUG::2016-02-17
# 20:14:37,061::blockSD::436::Storage.Misc.excCmd::(getReadDelay)
# SUCCESS: ...
(add_command, "::Storage.Misc.excCmd::(getReadDelay)",
"monitor_commands"),
# Match LVM commands begin or end logs.
#
# Begin:
# Thread-61::DEBUG::2016-02-17
# 19:26:33,854::lvm::286::Storage.Misc.excCmd::(cmd) /usr/bin/taskset
# --cpu-list 0-7 /usr/bin/sudo -n /usr/sbin/lvm vgck ...
#
# End:
# Thread-61::DEBUG::2016-02-17
# 19:26:37,933::lvm::286::Storage.Misc.excCmd::(cmd) SUCCESS: ...
(add_command, "::Storage.Misc.excCmd::(cmd)", "lvm_commands"),
# Match mailbox monitor check for mail dd commands (master domain
# only).
#
# Begin:
# mailbox.SPMMonitor::DEBUG::2016-02-17
# 20:15:24,521::storage_mailbox::731::Storage.Misc.excCmd::
# (_checkForMail)
# /usr/bin/taskset --cpu-list 0-7 dd ...
#
# End:
# mailbox.SPMMonitor::DEBUG::2016-02-17
# 20:15:24,547::storage_mailbox::731::Storage.Misc.excCmd::
# (_checkForMail)
# SUCCESS: ...
(add_command, "::Storage.Misc.excCmd::(_checkForMail)",
"mailbox_commands"),
# Match qemu-img operation used for copying images in 4.0.
#
# Begin:
# 10db509a-d5e4-41e8-8751-1305f0852d68::DEBUG::2016-02-17
# 19:32:49,865::image::137::Storage.Image::
# (_wait_for_qemuimg_operation)
# waiting for qemu-img operation to complete
#
# End:
# 10db509a-d5e4-41e8-8751-1305f0852d68::DEBUG::2016-02-17
# 19:40:14,134::image::146::Storage.Image::
# (_wait_for_qemuimg_operation)
# qemu-img operation has completed
(add_qemuimg_operation,
"::Storage.Image::(_wait_for_qemuimg_operation)",
"disk_commands"),
# Match qemu-img convert used for copying images in 3.6. This matches
# the start of the command.
#
# d9633df0-5f67-442a-861b-91d417b046f5::DEBUG::2016-02-09
# 12:37:59,885::utils::669::root::(execCmd) /usr/bin/taskset --cpu-list
# 0-23 /usr/bin/nice -n 19 /usr/bin/ionice -c 3 /usr/bin/qemu-img
# convert ...
(add_qemuimg_copy, "::root::(execCmd)", "disk_commands"),
# Match qemu-img convert used for copying images in 3.6. This matches
# the end of the command.
#
# d9633df0-5f67-442a-861b-91d417b046f5::DEBUG::2016-02-09
# 12:39:51,177::utils::716::root::(watchCmd) SUCCESS: ...
(add_qemuimg_copy, "::root::(watchCmd)", "disk_commands"),
# Match qemu-img convert used for copying disks on 3.5.
#
# Begin:
# 8c6193e7-cec6-44d1-afa2-2dd3437d40c8::DEBUG::2014-03-25
# 00:37:46,374::utils::546::Storage.Misc.excCmd::(watchCmd) '/bin/nice
# -n 19 /usr/bin/ionice -c 3 /usr/bin/qemu-img convert ...
#
# End:
# ffe3217e-6a91-4499-910b-cab975c5a3e4::DEBUG::2016-02-20
# 21:10:00,808::utils::718::root::(watchCmd) SUCCESS: ...
(add_qemuimg_copy, "::Storage.Misc.excCmd::(watchCmd)",
"disk_commands"),
# Match dd copy commands used for copying disks on 3.5.
#
# Begin:
# d5e74756-f1df-407d-9d83-0b4b4c844b15::DEBUG::2016-02-27
# 20:51:37,210::utils::796::Storage.Misc.excCmd::(watchCmd)
# /usr/bin/nice -n 19 /usr/bin/ionice -c 3 /usr/bin/dd ...
#
# End:
# d5e74756-f1df-407d-9d83-0b4b4c844b15::DEBUG::2016-02-27
# 20:52:00,310::utils::808::Storage.Misc.excCmd::(watchCmd) SUCCESS:
(add_dd_copy, "::Storage.Misc.excCmd::(watchCmd)", "disk_commands"),
]
stats = Stats()
for line in fileinput.input(files):
for func, pattern, name in patterns:
if pattern in line:
log = parse_log(line)
substats = getattr(stats, name)
func(substats, log)
return stats
def add_repostats(repostats, log):
"""
Add repostats samples from repoStats response line
"""
start = log.text.find("{")
response = eval(log.text[start:])
for uuid, info in response.items():
lastcheck = float(info["lastCheck"])
delay = float(info["delay"])
repostats[uuid].add(log.timestamp, lastcheck, delay)
def add_command(commands, log):
"""
Add commands start and stop events from execCmd calls
"""
if is_command_end(log):
commands[log.thread].end(log.timestamp)
else:
commands[log.thread].start(log.timestamp)
def add_qemuimg_operation(commands, log):
"""
Add qemu-img commands start and stop events
"""
if "waiting for qemu-img operation" in log.text:
commands[log.thread].start(log.timestamp)
elif "operation has completed" in log.text:
commands[log.thread].end(log.timestamp)
else:
pass # Periodic progress reports
def add_qemuimg_copy(commands, log):
"""
Add qemu-img copy commands start or stop events (pre 4.0).
"""
if is_command_end(log):
commands[log.thread].end(log.timestamp)
elif "/bin/qemu-img convert " in log.text:
commands[log.thread].start(log.timestamp)
def add_dd_copy(commands, log):
"""
Add dd copy commands start or stop events (3.5).
"""
if is_command_end(log):
commands[log.thread].end(log.timestamp)
elif "/bin/dd " in log.text:
commands[log.thread].start(log.timestamp)
def is_command_end(log):
return log.text.startswith(("SUCCESS:", "ERROR:"))
def parse_log(line):
# thread::loglevel::timestamp::module::lineno::logger::(func) text
fields = line.split("::", 6)
# Split "(func) text"
func, text = fields[6].split(" ", 1)
fields[6] = func[1:-1]
fields.append(text)
# Parse timestamp
timestamp = fields[2]
timestamp = timestamp.replace(",", ".")
fields[2] = pandas.Timestamp(timestamp)
return Log(*fields)
def dataframe(stats, key):
"""
Create pandas.DataFrame with one column per domain for given key.
"""
dfs = []
for uuid, ds in stats.iteritems():
df = pandas.DataFrame(getattr(ds, key), index=ds.timestamp,
columns=[uuid])
dfs.append(df)
combined = pandas.concat(dfs, axis=1)
return combined
def plot(stats, filename, size):
rows = 6
columns = 1
pyplot.figure(figsize=size, dpi=300)
pyplot.subplot(rows, columns, 1)
pyplot.title("lastCheck")
pyplot.ylabel("lastCheck (seconds)")
pyplot.xlabel("time")
pyplot.grid(True)
lastcheck = dataframe(stats.repostats, "lastcheck")
pyplot.plot(lastcheck.index, lastcheck)
pyplot.axhline(y=30, color="gray", linewidth="2")
# Show values up to 330 seconds. Bigger values will cause a host to become
# non-operational.
pyplot.axis([lastcheck.index[0], lastcheck.index[-1], 0, 330])
pyplot.subplot(rows, columns, 2)
pyplot.title("read delay")
pyplot.ylabel("delay (seconds)")
pyplot.xlabel("time")
pyplot.grid(True)
delay = dataframe(stats.repostats, "delay")
pyplot.plot(delay.index, delay)
pyplot.axhline(y=5, color="gray", linewidth="2")
# Show values up to 10 seconds. Values bigger then 5 seconds will show a
# warning in engine log.
pyplot.axis([lastcheck.index[0], lastcheck.index[-1], 0, 10])
pyplot.subplot(rows, columns, 3)
pyplot.title("LVM commands")
pyplot.ylabel("runtime (seconds)")
pyplot.xlabel("time")
pyplot.xlim(lastcheck.index[0], lastcheck.index[-1])
pyplot.grid(True)
for thread, cs in stats.lvm_commands.iteritems():
pyplot.plot(cs.timestamp, cs.runtime)
pyplot.subplot(rows, columns, 4)
pyplot.title("Mailbox commands")
pyplot.ylabel("runtime (seconds)")
pyplot.xlabel("time")
pyplot.xlim(lastcheck.index[0], lastcheck.index[-1])
pyplot.grid(True)
for thread, cs in stats.mailbox_commands.iteritems():
pyplot.plot(cs.timestamp, cs.runtime)
pyplot.subplot(rows, columns, 5)
pyplot.title("Storage domain monitor commands")
pyplot.ylabel("runtime (seconds)")
pyplot.xlabel("time")
pyplot.xlim(lastcheck.index[0], lastcheck.index[-1])
pyplot.grid(True)
for thread, cs in stats.monitor_commands.iteritems():
pyplot.plot(cs.timestamp, cs.runtime)
pyplot.subplot(rows, columns, 6)
pyplot.title("disk commands")
pyplot.ylabel("runtime (seconds)")
pyplot.xlabel("time")
pyplot.xlim(lastcheck.index[0], lastcheck.index[-1])
pyplot.grid(True)
for thread, cs in stats.disk_commands.iteritems():
pyplot.plot(cs.timestamp, cs.runtime)
pyplot.savefig(filename, bbox_inches="tight")
if __name__ == "__main__":
main(sys.argv[1:])