From 4aa7d81e11ea7fcfbb5c9d74337cde617b1a0d5d Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 24 Sep 2021 16:27:11 -0700 Subject: [PATCH] ignore re-printed header rows in output --- jc/parsers/vmstat.py | 3 ++ jc/parsers/vmstat_s.py | 7 +++- tests/fixtures/ubuntu-18.04/vmstat-1-long.out | 42 +++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/ubuntu-18.04/vmstat-1-long.out diff --git a/jc/parsers/vmstat.py b/jc/parsers/vmstat.py index 65a3e29c..1e7d52d6 100644 --- a/jc/parsers/vmstat.py +++ b/jc/parsers/vmstat.py @@ -209,6 +209,9 @@ def parse(data, raw=False, quiet=False): # skip header rows + if (procs or disk) and (line.startswith('procs') or line.startswith('disk')): + continue + if 'swpd' in line and 'free' in line and 'buff' in line and 'cache' in line: buff_cache = True tz = line.strip().split()[-1] if tstamp else None diff --git a/jc/parsers/vmstat_s.py b/jc/parsers/vmstat_s.py index 9600a6f7..663c5316 100644 --- a/jc/parsers/vmstat_s.py +++ b/jc/parsers/vmstat_s.py @@ -169,12 +169,15 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False): # skip header rows - if 'swpd' in line and 'free' in line and 'buff' in line and 'cache' in line: + if (procs or disk) and (line.startswith('procs') or line.startswith('disk')): + continue + + if 'swpd' in line and 'free' in line and 'buff' in line and 'cache' in line: buff_cache = True tz = line.strip().split()[-1] if tstamp else None continue - if 'swpd' in line and 'free' in line and 'inact' in line and 'active' in line: + if 'swpd' in line and 'free' in line and 'inact' in line and 'active' in line: buff_cache = False tz = line.strip().split()[-1] if tstamp else None continue diff --git a/tests/fixtures/ubuntu-18.04/vmstat-1-long.out b/tests/fixtures/ubuntu-18.04/vmstat-1-long.out new file mode 100644 index 00000000..89c0de17 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/vmstat-1-long.out @@ -0,0 +1,42 @@ +procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- + r b swpd free buff cache si so bi bo in cs us sy id wa st + 0 0 524 763388 147216 819640 0 0 288 108 195 2509 4 3 93 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 57 96 0 1 99 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 85 198 0 1 99 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 62 122 0 0 100 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 55 113 0 0 100 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 103 242 1 1 98 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 50 96 0 0 100 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 67 119 0 1 99 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 102 247 0 1 99 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 68 119 1 0 99 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 55 105 0 1 99 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 98 227 0 1 99 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 56 108 0 0 100 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 58 106 0 0 100 0 0 + 0 0 524 763388 147216 819640 0 0 0 0 98 235 0 2 98 0 0 + 0 0 524 763388 147224 819640 0 0 0 24 71 134 1 0 99 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 70 126 0 2 98 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 98 214 1 0 99 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 55 107 0 1 99 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 63 114 0 0 100 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 96 222 1 1 98 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 59 102 0 0 100 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 57 106 0 0 100 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 95 217 0 2 98 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 80 175 0 0 100 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 58 102 0 0 100 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 84 209 1 1 98 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 59 105 0 0 100 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 56 100 0 0 100 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 100 225 0 1 99 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 52 98 0 1 99 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 61 104 0 0 100 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 106 225 0 2 98 0 0 +procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- + r b swpd free buff cache si so bi bo in cs us sy id wa st + 1 0 524 763388 147224 819640 0 0 0 0 69 120 0 0 100 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 94 122 0 0 100 0 0 + 1 0 524 763388 147224 819640 0 0 0 0 111 228 1 1 98 0 0 + 0 0 524 763388 147224 819640 0 0 0 0 98 114 0 0 100 0 0 +