Skip to content

Commit

Permalink
Added: --no-clear option that disables header print and clearscreens.
Browse files Browse the repository at this point in the history
  • Loading branch information
strizhechenko committed Jun 7, 2017
1 parent 41214e1 commit b31f6ca
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
7 changes: 5 additions & 2 deletions netutils_linux_monitoring/base_top.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def __init__(self):
"will be '1 234 567'"),
Option('--random', default=False, action='store_true',
help="Shows random diff data instead of real evaluation. "
"Helpful for testing on static files")
"Helpful for testing on static files"),
Option('--no-clear', default=True, dest='clear', action='store_false',
help="Don't clear screen after each iteration. May be useful in scripts/logging to file."),
]

def parse_options(self):
Expand Down Expand Up @@ -76,7 +78,8 @@ def run(self):
self.options.iterations -= 1
sleep(self.options.interval)
self.tick()
system('clear')
if self.options.clear:
system('clear')
if self.diff:
print self
except KeyboardInterrupt:
Expand Down
4 changes: 3 additions & 1 deletion netutils_linux_monitoring/irqtop.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def __repr__(self):
output_lines.insert(1, self.diff_total + ['TOTAL'])
output_lines.insert(2, [''] * (cpu_count + 1))
table = make_table(output_lines[0], align_map, output_lines[1:])
return BaseTop.header + str(table)
if self.options.clear:
return BaseTop.header + str(table)
return str(table)

def eval_diff_total_column(self, column, cpucount):
""" returns sum of all interrupts on given CPU """
Expand Down
5 changes: 4 additions & 1 deletion netutils_linux_monitoring/link_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def make_rows(self):
yield [_dev] + [repr_source[dev][stat] for stat in self.stats]

def __repr__(self):
return BaseTop.header + str(make_table(self.make_header(), self.align_map, list(self.make_rows())))
table = make_table(self.make_header(), self.align_map, list(self.make_rows()))
if self.options.clear:
return BaseTop.header + str(table)
return str(table)

def __parse_dev__(self, dev):
return dict((stat, self.__parse_dev_stat__(dev, stat)) for stat in self.stats)
Expand Down
7 changes: 5 additions & 2 deletions netutils_linux_monitoring/network_top.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,15 @@ def __repr_cpu(self):
return wrap_header("Load per cpu:") + str(table)

def __repr__(self):
return "\n".join([
output = [
BaseTop.header,
self.__repr_irq(),
self.__repr_cpu(),
self.__repr_dev(),
])
]
if not self.options.clear:
del output[0]
return "\n".join(output)

def parse_options(self):
""" Tricky way to gather all options in one util without conflicts, parse them and do some logic after parse """
Expand Down
5 changes: 4 additions & 1 deletion netutils_linux_monitoring/softirqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def __repr__(self):
self.repr_source().get('NET_TX')[:active_cpu_count]
))
]
return BaseTop.header + str(make_table(header, ['l', 'r', 'r'], rows))
table = make_table(header, ['l', 'r', 'r'], rows)
if self.options.clear:
return BaseTop.header + str(table)
return str(table)


if __name__ == '__main__':
Expand Down
6 changes: 4 additions & 2 deletions netutils_linux_monitoring/softnet_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def parse(self):
return [SoftnetStat(self.options.random).parse_string(row, cpu) for cpu, row in data]

def eval(self):
print self.current
self.diff = [data - self.previous[cpu] for cpu, data in enumerate(self.current)]

def make_header(self):
Expand All @@ -86,7 +85,10 @@ def make_rows(self):
]

def __repr__(self):
return BaseTop.header + str(make_table(self.make_header(), self.align, list(self.make_rows())))
table = make_table(self.make_header(), self.align, list(self.make_rows()))
if self.options.clear:
return BaseTop.header + str(table)
return str(table)


if __name__ == '__main__':
Expand Down

0 comments on commit b31f6ca

Please sign in to comment.