-
Notifications
You must be signed in to change notification settings - Fork 1
/
asap-graph.py
executable file
·1282 lines (965 loc) · 53.3 KB
/
asap-graph.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
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3
"""
Usage: asap-graph file [-aoclmsb] (FILE) [FILE]... [ -p SAVEPATH]
asap-graph cat [-aoclmsb] (FILE) (FILE) [-p SAVEPATH]
asap-graph xp [-aoclmsb] [-p SAVEPATH] [-x XPATH]
Modes:
file Provide one sar file to plot.
cat Concatenate sar files together.
xp Extract sar files recursively and plot it.
Arguments:
FILE Mandatory sar file / two sar files as range for concatenation.
Options:
-h --help
-a All graphs switched on.
-o Overview graphs.
-c CPU graphs.
-l Load graphs.
-m Memory graphs.
-s Miscellaneous graphs.
-b Storage (block) graphs.
-p SAVEPATH Provide save path.
-x XPATH Optional path when extracting recursively (Default: cwd).
"""
import warnings
warnings.filterwarnings("ignore")
import re
import os
import sys
import shutil
import matplotlib.pyplot as plt
import matplotlib as mpl
import datetime
import time
import numpy as np
import numpy.ma as ma
from docopt import docopt
def list_get(lst, index, default = None): # returns list index (time only)
if len(lst) >= index + 1:
return lst[index]
return default
def complete_concat_sars(concat_sars): # complete sarfiles for concatenation
try:
from_path_prefix = re.search('(.*)(?=sar)', "".join(concat_sars[0])).group(0)
to_path_prefix = re.search('(.*)(?=sar)', "".join(concat_sars[1])).group(0)
sar_from = int(re.search('(?<=sar)(\d+)', "".join(concat_sars[0])).group(1))
sar_to = int(re.search('(?<=sar)(\d+)', "".join(concat_sars[1])).group(1))
sarfiles_filled = []
if from_path_prefix == to_path_prefix:
if sar_from <= sar_to:
for suffix in range(sar_from, sar_to + 1):
if len(str(suffix)) == 1:
sarfiles_filled.append(from_path_prefix + "sar0" + str(suffix))
else:
sarfiles_filled.append(from_path_prefix + "sar" + str(suffix))
else:
for suffix in range(sar_from, 32):
if len(str(suffix)) == 1:
sarfiles_filled.append(from_path_prefix + "sar0" + str(suffix))
else:
sarfiles_filled.append(from_path_prefix + "sar" + str(suffix))
for suffix in range(1, sar_to + 1):
if len(str(suffix)) == 1:
sarfiles_filled.append(from_path_prefix + "sar0" + str(suffix))
else:
sarfiles_filled.append(from_path_prefix + "sar" + str(suffix))
return sarfiles_filled
else:
print(Bcolors.FAIL + ("Different paths for concatenation") + Bcolors.ENDC)
exit(1)
except AttributeError:
print(Bcolors.FAIL + ("Is provided file a valid sar file?") + Bcolors.ENDC)
exit(1)
class Bcolors: # just class for colors
FAIL = '\033[91m'
ENDC = '\033[0m'
class SARAnalyzer:
def __init__(self):
self.data = {} # main data dict
self.hostname = ''
self.cpu_num = ''
# list of used titles
self.indeces = {'%usr': None, '%user': None, '%nice': None, '%sys': None, '%system': None, '%idle': None, '%iowait': None,
'cswch/s': None, 'proc/s': None,
'ldavg-1': None, 'ldavg-5': None, 'ldavg-15': None, 'runq-sz': None, 'plist-sz': None,
'kbmemfree': None, 'kbmemused': None, 'kbcached': None, 'kbswpfree': None, 'kbswpused': None,
'pswpin/s': None, 'pswpout/s': None,
'dentunusd': None, 'file-nr': None, 'inode-nr': None, 'file-sz': None, 'inode-sz': None,
'tcpsck': None, 'udpsck': None,
'bread/s': None, 'bwrtn/s': None}
def get_sars_recursively(self, wd = os.getcwd()):
sar_files_list = []
for root, dirs, files in os.walk(wd):
for sarfiles in files:
sarfile = re.match('sar\d{2}$', sarfiles)
if sarfile:
file_with_path = os.path.join(os.path.abspath(root), sarfiles)
sar_files_list.append(file_with_path)
return sar_files_list
def return_indeces(self, row):
temp_dict = {}
for index in self.indeces:
for num, dat in enumerate(row):
if dat in index:
temp_dict.update({dat: num})
return temp_dict
def get_data(self, sarfile):
print('Processing "%s"...' % sarfile)
cpu_captured = []
procs_captured = []
cswch_captured = []
load_captured = []
mem_captured = []
swp_captured = []
pswp_captured = []
misc_captured = []
sck_captured = []
blocks_captured = []
restarts = []
graphdate = ''
try:
with open(sarfile, "r") as data:
state = "default" # state for not capturing
first_line = data.readline().rstrip() # check first line to determine for RHEL version we are working with (means different sar)
commas = re.compile("(?<=\d),(?=\d)") # workaround to deal with different locales (e.g. comma instead of dot)
self.hostname = re.search(r"\((.*?)\)", first_line).group(1)
if re.search('(2.6.18)', first_line):
self.rhel_version = 5
elif re.search('(2.6.32)', first_line):
self.rhel_version = 6
elif re.search('(3.10)', first_line):
self.rhel_version = 7
elif re.search('(4.18)', first_line):
self.rhel_version = 8
else:
print(Bcolors.FAIL + ("FAIL: Unsupported RHEL") + Bcolors.ENDC)
return
try:
self.cpu_num = re.search(r"\((\d+ CPU)\)$", first_line).group(1)
except AttributeError:
self.cpu_num = ""
graphdateparts = re.search('(?<=\s)(?:(\d+)([-/])(\d+)[-/](\d+))', first_line).groups() #
# Normalize graphdate
# year(four digits)-month-day
if graphdateparts[1] == "-":
graphdate = "%s-%s-%s" % (graphdateparts[0][-2:], graphdateparts[2], graphdateparts[3])
# month-day-year(two digits)
elif graphdateparts[1] == "/" and len(graphdateparts[3]) == 2:
graphdate = "%s-%s-%s" % (graphdateparts[3], graphdateparts[0], graphdateparts[2])
# month-day-year(four digits)
elif graphdateparts[1] == "/" and len(graphdateparts[3]) == 4:
graphdate = "%s-%s-%s" % (graphdateparts[3][-2:], graphdateparts[0], graphdateparts[2])
else:
raise LookupError("Unknown graph date format: %s" % str(graphdateparts))
for line in data:
if line == '\n':
continue
else:
commarow = commas.sub('.', line) # implementing the comma workaround
row = commarow.split()
am_pm = list_get(row, 1)
locale = ['Average:', 'Среднее:', 'Media:', 'Média:', 'Moyenne:', 'Durchschn.:']
if am_pm in ("PM", "AM"):
t_split = row[0].split(":",1)
h = t_split[0]
if am_pm == "PM" and t_split[0] != "12":
h = (int(t_split[0])+12)
if am_pm == "AM" and t_split[0] == "12":
h = "00"
row[0] = "%s:%s" % (h, t_split[1])
del(row[1]) # fixes the BUG with concatenation where there is both non-AM_PM and AM_PM timing.
if state == "default":
if any(x in row for x in ["%usr", "%user"]):
state = "cpu_capturing"
self.indeces.update(self.return_indeces(row))
elif self.rhel_version == 5 and "cswch/s" in row:
state = "cswch_capturing"
self.indeces.update(self.return_indeces(row))
elif self.rhel_version == 5 and "proc/s" in row:
state = "procs_capturing"
self.indeces.update(self.return_indeces(row))
elif all(x in row for x in ["cswch/s", "proc/s"]):
state = "procs_cswch_capturing"
self.indeces.update(self.return_indeces(row))
elif "pswpin/s" in row:
state = "pswp_capturing"
self.indeces.update(self.return_indeces(row))
elif "ldavg-15" in row:
state = "load_capturing"
self.indeces.update(self.return_indeces(row))
elif "kbmemfree" in row:
state = "mem_capturing"
self.indeces.update(self.return_indeces(row))
elif self.rhel_version in (6, 7, 8) and "kbswpfree" in row:
state = "swp_capturing"
self.indeces.update(self.return_indeces(row))
elif self.rhel_version == 5 and "kbswpfree" in row:
state = "swp_rhel5_capturing" # finish
elif "dentunusd" in row:
state = "dent_capturing"
self.indeces.update(self.return_indeces(row))
elif "tcpsck" in row:
state = "sck_capturing"
self.indeces.update(self.return_indeces(row))
elif "bread/s" in row:
state = "blocks_capturing"
self.indeces.update(self.return_indeces(row))
elif all(x in row for x in ["LINUX", "RESTART"]):
restarts.append(row[0])
elif state == "cpu_capturing":
if any(x in row for x in locale):
state = "default"
elif "all" in row:
cpu_captured.append(row)
elif state == "cswch_capturing":
if any(x in row for x in locale):
state = "default"
else:
cswch_captured.append(row)
elif state == "procs_capturing":
if any(x in row for x in locale):
state = "default"
else:
procs_captured.append(row)
elif state == "procs_cswch_capturing":
if any(x in row for x in locale):
state = "default"
else:
procs_captured.append(row)
cswch_captured.append(row)
elif state == "pswp_capturing":
if any(x in row for x in locale):
state = "default"
else:
pswp_captured.append(row)
elif state == "load_capturing":
if any(x in row for x in locale):
state = "default"
else:
load_captured.append(row)
elif state == "mem_capturing":
if any(x in row for x in locale):
state = "default"
else:
mem_captured.append(row)
elif state == "swp_rhel5_capturing":
if any(x in row for x in locale):
state = "default"
else:
swp_captured.append(row)
elif state == "swp_capturing":
if any(x in row for x in locale):
state = "default"
else:
swp_captured.append(row)
elif state == "dent_capturing":
if any(x in row for x in locale):
state = "default"
else:
misc_captured.append(row)
elif state == "sck_capturing":
if any(x in row for x in locale):
state = "default"
else:
sck_captured.append(row)
elif state == "blocks_capturing":
if any(x in row for x in locale):
state = "default"
else:
blocks_captured.append(row)
# Dict of dicts of our data (graphdate for contacanation)
self.data[graphdate] = {
"cpu_captured": cpu_captured,
"procs_captured": procs_captured,
"cswch_captured": cswch_captured,
"load_captured": load_captured,
"mem_captured": mem_captured,
"swp_captured": swp_captured,
"pswp_captured": pswp_captured,
"misc_captured": misc_captured,
"sck_captured": sck_captured,
"blocks_captured": blocks_captured,
"restarts": restarts,
}
except ValueError:
print(Bcolors.FAIL + ("FAIL: Error capturing %s data!" % sarfile) + Bcolors.ENDC)
return
except FileNotFoundError:
print(Bcolors.FAIL + ("FAIL: %s not found!" % sarfile) + Bcolors.ENDC)
return
except AttributeError:
print(Bcolors.FAIL + ("FAIL: Check %s validity" % sarfile) + Bcolors.ENDC)
return
except PermissionError:
print(Bcolors.FAIL + ("FAIL: Permission denied!") + Bcolors.ENDC)
# Method for generating the graphs
def generate_graphs(self, file_prefix = None,
plot_all = False,
plot_overview = True,
plot_cpu = False,
plot_load = False,
plot_memory = False,
plot_misc = False,
plot_blocks = False,
save_path = None
):
if plot_all == True:
plot_overview = True
plot_cpu = True
plot_load = True
plot_memory = True
plot_misc = True
plot_blocks = True
default = [plot_all, plot_overview, plot_cpu, plot_load, plot_memory, plot_misc, plot_blocks] # complicated as was not able to find default for 'docopt'
if not any(default):
plot_overview = True
if not file_prefix:
ks = sorted(self.data.keys()) # sorted keys (graph dates)
if not ks:
return
file_suffix = (ks[0] + "_to_" + ks[-1]) if ks[0] != ks[-1] else ks[0] # generate file prefix (from graphdates)
file_prefix = self.hostname + "__"
save_name = save_path + "/" + file_prefix + file_suffix if save_path != None else file_prefix + file_suffix
# variables init as extend used later
restarttime = []
cputime = []
user = []
nice = []
system = []
iowait = []
idle = []
procstime = []
cswchtime = []
procs = []
cswch = []
loadtime = []
runq = []
plist = []
avg1min = []
avg5min = []
avg15min = []
memtime = []
kbmemfree = []
kbmemused = []
kbcached = []
kbswpfree = []
pswptime = []
pswpin = []
pswpout = []
scktime = []
misctime = []
dentunusd = []
file_nr = []
inode_nr = []
tcp_sck = []
udp_sck = []
blockstime = []
bread = []
bwrtn = []
# for non-data masking
masked_cputime = []
masked_procstime = []
masked_cswchtime = []
masked_loadtime = []
masked_memtime = []
masked_pswptime = []
masked_scktime = []
masked_misctime = []
masked_blockstime = []
for graphdate, data_struct in sorted(self.data.items(), key = lambda x: x[0]):
cpu_captured = data_struct["cpu_captured"]
procs_captured = data_struct["procs_captured"]
cswch_captured = data_struct["cswch_captured"]
load_captured = data_struct["load_captured"]
mem_captured = data_struct["mem_captured"]
swp_captured = data_struct["swp_captured"]
pswp_captured = data_struct["pswp_captured"]
misc_captured = data_struct["misc_captured"]
sck_captured = data_struct["sck_captured"]
blocks_captured = data_struct["blocks_captured"]
restarts = data_struct["restarts"]
get_time_func = lambda x: datetime.datetime.strptime(graphdate+" "+x[0], "%y-%m-%d %H:%M:%S")
restarttime.extend(list(map(lambda x: get_time_func((x,)), restarts)))
cputime.extend(list(map(get_time_func, cpu_captured)))
masked_cputime.append(len(cputime))
if self.rhel_version == 5:
user.extend(list(map(lambda x: float(x[self.indeces.get('%user')]), cpu_captured)))
else:
user.extend(list(map(lambda x: float(x[self.indeces.get('%usr')]), cpu_captured)))
nice.extend(list(map(lambda x: float(x[self.indeces.get("%nice")]), cpu_captured)))
if self.rhel_version == 5:
system.extend(list(map(lambda x: float(x[self.indeces.get("%system")]), cpu_captured)))
else:
system.extend(list(map(lambda x: float(x[self.indeces.get("%sys")]), cpu_captured)))
iowait.extend(list(map(lambda x: float(x[self.indeces.get("%iowait")]), cpu_captured)))
idle.extend(list(map(lambda x: float(x[self.indeces.get("%idle")]), cpu_captured)))
procstime.extend(list(map(get_time_func, procs_captured)))
cswchtime.extend(list(map(get_time_func, cswch_captured)))
masked_procstime.append(len(procstime))
masked_cswchtime.append(len(cswchtime))
procs.extend(list(map(lambda x: float(x[self.indeces.get('proc/s')]), procs_captured)))
cswch.extend(list(map(lambda x: float(x[self.indeces.get('cswch/s')]), cswch_captured)))
loadtime.extend(list(map(get_time_func, load_captured)))
masked_loadtime.append(len(loadtime))
runq.extend(list(map(lambda x: float(x[self.indeces.get('runq-sz')]), load_captured)))
plist.extend(list(map(lambda x: float(x[self.indeces.get('plist-sz')]), load_captured)))
avg1min.extend(list(map(lambda x: float(x[self.indeces.get('ldavg-1')]), load_captured)))
avg5min.extend(list(map(lambda x: float(x[self.indeces.get('ldavg-5')]), load_captured)))
avg15min.extend(list(map(lambda x: float(x[self.indeces.get('ldavg-15')]), load_captured)))
memtime.extend(list(map(get_time_func, mem_captured)))
masked_memtime.append(len(memtime))
kbmemfree.extend(list(map(lambda x: float(x[self.indeces.get('kbmemfree')]) / 1024 / 1024, mem_captured)))
kbmemused.extend(list(map(lambda x: float(x[self.indeces.get('kbmemused')]) / 1024 / 1024, mem_captured)))
kbcached.extend(list(map(lambda x: float(x[self.indeces.get('kbcached')]) / 1024 / 1024, mem_captured)))
if self.rhel_version == 5:
kbswpfree.extend(list(map(lambda x: float(x[self.indeces.get('kbswpfree')]) / 1024 / 1024, mem_captured)))
else:
kbswpfree.extend(list(map(lambda x: float(x[self.indeces.get('kbswpfree')]) / 1024 / 1024, swp_captured)))
pswptime.extend(list(map(get_time_func, pswp_captured)))
masked_pswptime.append(len(pswptime))
pswpin.extend(list(map(lambda x: float(x[self.indeces.get('pswpin/s')]), pswp_captured)))
pswpout.extend(list(map(lambda x: float(x[self.indeces.get('pswpout/s')]), pswp_captured)))
misctime.extend(list(map(get_time_func, misc_captured)))
masked_misctime.append(len(misctime))
dentunusd.extend(list(map(lambda x: float(x[self.indeces.get('dentunusd')]), misc_captured)))
if self.rhel_version == 5:
file_nr.extend(list(map(lambda x: float(x[self.indeces.get('file-sz')]), misc_captured)))
inode_nr.extend(list(map(lambda x: float(x[self.indeces.get('inode-sz')]), misc_captured)))
else:
file_nr.extend(list(map(lambda x: float(x[self.indeces.get('file-nr')]), misc_captured)))
inode_nr.extend(list(map(lambda x: float(x[self.indeces.get('inode-nr')]), misc_captured)))
scktime.extend(list(map(get_time_func, sck_captured)))
masked_scktime.append(len(scktime))
tcp_sck.extend(list(map(lambda x: float(x[self.indeces.get('tcpsck')]), sck_captured)))
udp_sck.extend(list(map(lambda x: float(x[self.indeces.get('udpsck')]), sck_captured)))
blockstime.extend(list(map(get_time_func, blocks_captured)))
masked_blockstime.append(len(blockstime))
bread.extend(list(map(lambda x: float(x[self.indeces.get('bread/s')]), blocks_captured)))
bwrtn.extend(list(map(lambda x: float(x[self.indeces.get('bwrtn/s')]), blocks_captured)))
if plot_cpu: # CPU usage graph plot
plt.style.use('/usr/share/asap-graph/mystyle.mplstyle')
plt.subplot2grid((2,2), (0, 0), colspan=2)
user = ma.MaskedArray(user)
nice = ma.MaskedArray(nice)
system = ma.MaskedArray(system)
iowait = ma.MaskedArray(iowait)
idle = ma.MaskedArray(idle)
if masked_cputime:
for m in masked_cputime[:-1]:
user[m] = ma.masked
nice[m] = ma.masked
system[m] = ma.masked
iowait[m] = ma.masked
idle[m] = ma.masked
plt.plot(np.array(cputime), user, label="%user")
plt.plot(np.array(cputime), nice, label="%nice")
plt.plot(np.array(cputime), system, label="%system")
plt.plot(np.array(cputime), iowait, label="%iowait")
plt.plot(np.array(cputime), idle, label="%idle")
plt.plot([], [], label=self.cpu_num, color='black', marker='+', markeredgewidth=3, markersize=3)
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=1, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)
plt.xticks(rotation=30)
plt.gca().xaxis.set_major_formatter(mpl.dates.DateFormatter('%m-%d %H:%M'))
plt.subplot2grid((2,2), (1, 0))
procs = ma.MaskedArray(procs)
if masked_procstime:
for m in masked_procstime[:-1]:
procs[m] = ma.masked
plt.plot(np.array(procstime), procs, label="procs/s", color='c')
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=1, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)
plt.xticks(rotation=30)
plt.gca().xaxis.set_major_formatter(mpl.dates.DateFormatter('%m-%d %H:%M'))
plt.subplot2grid((2,2), (1, 1))
cswch = ma.MaskedArray(cswch)
if masked_cswchtime:
for m in masked_cswchtime[:-1]:
cswch[m] = ma.masked
plt.plot(np.array(cputime), cswch, label="cswch/s", color='g')
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=1, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)
plt.xticks(rotation=30)
plt.gca().xaxis.set_major_formatter(mpl.dates.DateFormatter('%m-%d %H:%M'))
fig = plt.gcf()
fig.set_size_inches(16.00, 09.00)
plt.tight_layout()
plt.savefig((save_name + "_CPU.png"), bbox_extra_artists=(lgd,), dpi = 100)
plt.clf()
if plot_load: # load graph plot
plt.style.use('/usr/share/asap-graph/mystyle.mplstyle')
plt.subplot(311)
avg1min = ma.MaskedArray(avg1min)
avg5min = ma.MaskedArray(avg5min)
avg15min = ma.MaskedArray(avg15min)
if masked_loadtime:
for m in masked_loadtime[:-1]:
avg1min[m] = ma.masked
avg5min[m] = ma.masked
avg15min[m] = ma.masked
plt.plot(np.array(loadtime), avg1min, label="avg1min", color='#595b01')
plt.plot(np.array(loadtime), avg5min, label="avg5min", color='#ffe600')
plt.plot(np.array(loadtime), avg15min, label="avg15min", color='#fe7d00')
plt.plot([], [], label=self.cpu_num, color='black', marker='+', markeredgewidth=3, markersize=3)
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=1, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)
plt.xticks(rotation=30)
plt.gca().xaxis.set_major_formatter(mpl.dates.DateFormatter('%m-%d %H:%M'))
plt.subplot(312)
runq = ma.MaskedArray(runq)
if masked_loadtime:
for m in masked_loadtime[:-1]:
runq[m] = ma.masked
plt.plot(np.array(loadtime), runq, label="runq", color='#fec842')
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=1, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)
plt.xticks(rotation=30)
plt.gca().xaxis.set_major_formatter(mpl.dates.DateFormatter('%m-%d %H:%M'))
plt.subplot(313)
plist = ma.MaskedArray(plist)
if masked_loadtime:
for m in masked_loadtime[:-1]:
plist[m] = ma.masked
plt.plot(np.array(loadtime), plist, label="plist", color='#e97a2e')
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=1, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)
plt.xticks(rotation=30)
plt.gca().xaxis.set_major_formatter(mpl.dates.DateFormatter('%m-%d %H:%M'))
fig = plt.gcf()
fig.set_size_inches(16.00, 09.00)
plt.tight_layout()
plt.savefig((save_name + "_load.png"), bbox_extra_artists=(lgd,), dpi = 100)
plt.cla()
plt.clf()
if plot_memory: # memory usage graph plot
plt.style.use('/usr/share/asap-graph/mystyle.mplstyle')
kbmemfree = ma.MaskedArray(kbmemfree)
kbmemused = ma.MaskedArray(kbmemused)
kbcached = ma.MaskedArray(kbcached)
kbswpfree = ma.MaskedArray(kbswpfree)
if masked_memtime:
for m in masked_memtime[:-1]:
kbmemfree[m] = ma.masked
kbmemused[m] = ma.masked
kbcached[m] = ma.masked
kbswpfree[m] = ma.masked
plt.plot(np.array(memtime), kbmemfree, label="memfree/GB")
plt.plot(np.array(memtime), kbmemused, label="memused/GB")
plt.plot(np.array(memtime), kbcached, label="cacheused/GB")
plt.plot(np.array(memtime), kbswpfree, label="kbswpfree/GB")
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=1, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)
plt.xticks(rotation=30)
plt.gca().xaxis.set_major_formatter(mpl.dates.DateFormatter('%m-%d %H:%M'))
fig = plt.gcf()
fig.set_size_inches(16.00, 09.00)
plt.tight_layout()
plt.savefig((save_name + "_memory.png"), bbox_extra_artists=(lgd,), dpi = 100)
plt.clf()
if plot_misc: # m isc graph plot
plt.style.use('/usr/share/asap-graph/mystyle.mplstyle')
plt.subplot2grid((2,2), (0, 0))
file_nr = ma.MaskedArray(file_nr)
if masked_misctime:
for m in masked_misctime[:-1]:
file_nr[m] = ma.masked
plt.plot(np.array(misctime), file_nr, label="file_nr")
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=1, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)
plt.xticks(rotation=30)
plt.gca().xaxis.set_major_formatter(mpl.dates.DateFormatter('%m-%d %H:%M'))
plt.subplot2grid((2,2), (0, 1))
inode_nr = ma.MaskedArray(inode_nr)
dentunusd = ma.MaskedArray(dentunusd)
if masked_misctime:
for m in masked_misctime[:-1]:
inode_nr[m] = ma.masked
dentunusd[m] = ma.masked
plt.plot(np.array(misctime), inode_nr, label="inode_nr")
plt.plot(np.array(misctime), dentunusd, label="dentunusd")
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=1, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)
plt.xticks(rotation=30)
plt.gca().xaxis.set_major_formatter(mpl.dates.DateFormatter('%m-%d %H:%M'))
plt.subplot2grid((2,2), (1, 0), colspan=2)
tcp_sck = ma.MaskedArray(tcp_sck)
udp_sck = ma.MaskedArray(udp_sck)
if masked_scktime:
for m in masked_scktime[:-1]:
tcp_sck[m] = ma.masked
udp_sck[m] = ma.masked
plt.plot(np.array(scktime), tcp_sck, label="tcp_sck", color='c')
plt.plot(np.array(scktime), udp_sck, label="udp_sck", color='m')
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=1, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)
plt.xticks(rotation=30)
plt.gca().xaxis.set_major_formatter(mpl.dates.DateFormatter('%m-%d %H:%M'))
fig = plt.gcf()
fig.set_size_inches(16.00, 09.00)
plt.tight_layout()
plt.savefig((save_name + "_misc.png"), bbox_extra_artists=(lgd,), dpi = 100)
plt.cla()
if plot_blocks:
plt.style.use('/usr/share/asap-graph/mystyle.mplstyle')
plt.subplot(211)
bread = ma.MaskedArray(bread)
if masked_blockstime:
for m in masked_loadtime[:-1]:
bread[m] = ma.masked
plt.plot(np.array(loadtime), bread, label="bread/s", color='#E95D22')
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=1, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)
plt.xticks(rotation=30)
plt.gca().xaxis.set_major_formatter(mpl.dates.DateFormatter('%m-%d %H:%M'))
plt.subplot(212)
bwrtn = ma.MaskedArray(bwrtn)
if masked_loadtime:
for m in masked_loadtime[:-1]:
bwrtn[m] = ma.masked
plt.plot(np.array(loadtime), bwrtn, label="bwrtn/s", color='#017890')
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=1, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)
plt.xticks(rotation=30)
plt.gca().xaxis.set_major_formatter(mpl.dates.DateFormatter('%m-%d %H:%M'))
fig = plt.gcf()
fig.set_size_inches(16.00, 09.00)
plt.tight_layout()
plt.savefig((save_name + "_blocks.png"), bbox_extra_artists=(lgd,), dpi = 100)
plt.cla()
if plot_overview: # all in one graph plot
plt.style.use('/usr/share/asap-graph/mystyle.mplstyle')
# CPU
plt.subplot2grid((3,4), (0,0), colspan=2)
user = ma.MaskedArray(user)
nice = ma.MaskedArray(nice)
system = ma.MaskedArray(system)
iowait = ma.MaskedArray(iowait)
idle = ma.MaskedArray(idle)
if masked_cputime:
for m in masked_cputime[:-1]:
user[m] = ma.masked
nice[m] = ma.masked
system[m] = ma.masked
iowait[m] = ma.masked
idle[m] = ma.masked
plt.plot(np.array(cputime), user, label="%user", color='#e73571')
plt.plot(np.array(cputime), nice, label="%nice", color='#f0e3d5')
plt.plot(np.array(cputime), system, label="%sys", color='#ff9302')
plt.plot(np.array(cputime), iowait, label="%iowait", color='#0382aa')
plt.plot(np.array(cputime), idle, label="%idle", color='#000e17')
plt.plot([], [], label=self.cpu_num, color='black', marker='+', markeredgewidth=3, markersize=3)
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=3, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)
plt.xticks(rotation=30)
plt.gca().xaxis.set_major_formatter(mpl.dates.DateFormatter('%m-%d %H:%M'))
# LOAD
plt.subplot2grid((3,4), (0, 2), colspan=2)
avg1min = ma.MaskedArray(avg1min)
avg5min = ma.MaskedArray(avg5min)
avg15min = ma.MaskedArray(avg15min)
if masked_loadtime:
for m in masked_loadtime[:-1]:
avg1min[m] = ma.masked
avg5min[m] = ma.masked
avg15min[m] = ma.masked
plt.plot(np.array(loadtime), avg1min, label="avg1min", color='#595b01')
plt.plot(np.array(loadtime), avg5min, label="avg5min", color='#ffe600')
plt.plot(np.array(loadtime), avg15min, label="avg15min", color='#fe7d00')
plt.plot([], [], label=self.cpu_num, color='black', marker='+', markeredgewidth=3, markersize=3)
if len(restarttime) > 0:
[plt.axvline(_x, linestyle="dashed", color='r', label='RESTART' if not i else None, zorder=5) for i, _x in enumerate(restarttime)]
lgd = plt.legend(ncol=2, loc='best')
lgd.get_frame().set_alpha(0)
ymin, ymax = plt.ylim()
ydiff = (ymax - ymin)* 0.05
ymin -= ydiff
ymax += ydiff
plt.ylim(ymin, ymax)