Skip to content
This repository was archived by the owner on Jan 10, 2019. It is now read-only.

Commit e1dd7aa

Browse files
authored
Merge pull request #3 from michep/patch
One map with all patterms
2 parents 4bebdec + 4e59cd1 commit e1dd7aa

2 files changed

Lines changed: 158 additions & 234 deletions

File tree

sar/__init__.py

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
#!/usr/bin/env python
22

33

4-
"""Indicates CPU part of SAR file"""
5-
PART_CPU = 0
6-
7-
"""Indicates RAM memory usage part of SAR file"""
8-
PART_MEM = 1
9-
10-
"""Indicates swap memory usage part of SAR file"""
11-
PART_SWP = 2
12-
13-
"""I/O usage part of SAR file"""
14-
PART_IO = 3
15-
164
"""CPU regexp pattern for detecting SAR section header"""
175
PATTERN_CPU = ".*CPU.*(usr|user).*nice.*sys.*"
186

@@ -28,7 +16,7 @@
2816
}
2917

3018
"""Mem usage regexp pattern for detecting SAR section header"""
31-
PATTERN_MEM = ".*kbmemfree.*kbmemused.*memused.*kbbuffers.*kbcached.*"
19+
PATTERN_MEM = '.*kbmemfree.*kbmemused.*memused.*kbbuffers.*kbcached.*'
3220

3321
"""Regexp terms for finding fields in SAR parts for memory usage"""
3422
FIELDS_MEM = [
@@ -43,7 +31,7 @@
4331
}
4432

4533
"""Swap usage regexp pattern for detecting SAR section header"""
46-
PATTERN_SWP = ".*kbswpfree.*kbswpused.*swpused.*"
34+
PATTERN_SWP = '.*kbswpfree.*kbswpused.*swpused.*'
4735

4836
"""Regexp terms for finding fields in SAR parts for swap usage"""
4937
FIELDS_SWP = [
@@ -57,31 +45,71 @@
5745
}
5846

5947
"""I/O usage regexp pattern for detecting SAR section header"""
60-
PATTERN_IO = ".*tps.*rtps.*wtps.*bread\/s.*bwrtn\/s.*"
48+
PATTERN_IO = '.*tps.*rtps.*wtps.*bread\/s.*bwrtn\/s.*'
6149

62-
"""Regexp terms for finding fields in SAR parts for swap usage"""
50+
"""Regexp terms for finding fields in SAR parts for I/O usage"""
6351
FIELDS_IO = [
6452
'^tps', '^rtps', '^wtps', 'bread\/s', 'bwrtn\/s'
6553
]
6654

67-
"""Pair regexp terms with field names in swap usage output dictionary"""
55+
"""Pair regexp terms with field names in I/O usage output dictionary"""
6856
FIELD_PAIRS_IO = {
6957
'tps': FIELDS_IO[0], 'rtps': FIELDS_IO[1], 'wtps': FIELDS_IO[2],
7058
'bread': FIELDS_IO[3], 'bwrite': FIELDS_IO[4],
59+
}
60+
61+
"""Task creation and system switching regexp pattern for SAR section header"""
62+
PATTERN_TASK = '.*proc\/s.*cswch\/s.*'
7163

64+
"""Regexp terms for finding fields in SAR parts for task creation and system switching"""
65+
FIELDS_TASK = [
66+
'proc', 'cswch'
67+
]
68+
69+
"""Pair regexp terms with field names in Task creation and system switching output dictionary"""
70+
FIELD_PAIRS_TASK = {
71+
'proc': FIELDS_TASK[0], 'cswch': FIELDS_TASK[1]
7272
}
7373

7474
"""Restart time regexp pattern for detecting SAR restart notices"""
75-
PATTERN_RESTART = ".*LINUX\ RESTART.*"
75+
PATTERN_RESTART = '.*LINUX\ RESTART.*'
7676

7777
"""Pattern for splitting multiple combined SAR file"""
78-
PATTERN_MULTISPLIT = "Linux"
78+
PATTERN_MULTISPLIT = 'Linux'
7979

8080
"""Split by date in multiday SAR file"""
81-
PATTERN_DATE = "[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]"
81+
PATTERN_DATE = '[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]'
82+
83+
ALL_PATTERNS = {
84+
'CPU': {
85+
'PATTERN': PATTERN_CPU,
86+
'FIELDS': FIELDS_CPU,
87+
'PAIRS': FIELD_PAIRS_CPU
88+
},
89+
'MEM': {
90+
'PATTERN': PATTERN_MEM,
91+
'FIELDS': FIELDS_MEM,
92+
'PAIRS': FIELD_PAIRS_MEM
93+
},
94+
'SWP': {
95+
'PATTERN': PATTERN_SWP,
96+
'FIELDS': FIELDS_SWP,
97+
'PAIRS': FIELD_PAIRS_SWP
98+
},
99+
'IO': {
100+
'PATTERN': PATTERN_IO,
101+
'FIELDS': FIELDS_IO,
102+
'PAIRS': FIELD_PAIRS_IO
103+
},
104+
'TASK': {
105+
'PATTERN': PATTERN_TASK,
106+
'FIELDS': FIELDS_TASK,
107+
'PAIRS': FIELD_PAIRS_TASK
108+
109+
}
110+
}
82111

83112
__all__ = [
84-
"PART_CPU", "PART_MEM", "PART_SWP", "PART_IO",
85-
"PATTERN_CPU", "PATTERN_MEM", "PATTERN_SWP", "PATTERN_IO",
86-
"PATTERN_RESTART", "PATTERN_MULTISPLIT", "PATTERN_DATE"
113+
'PATTERN_RESTART', 'PATTERN_MULTISPLIT',
114+
'PATTERN_DATE', 'ALL_PATTERNS'
87115
]

0 commit comments

Comments
 (0)