Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #82

Merged
merged 10 commits into from Jun 17, 2017
2 changes: 2 additions & 0 deletions .flake8
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 120
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -7,4 +7,4 @@ python:

install: make env

script: make test
script: make test lint
13 changes: 12 additions & 1 deletion Makefile
Expand Up @@ -32,7 +32,8 @@ clean:
find . -name '*~' -exec rm -f {} \;

lint:
flake8 twitter > violations.flake8.txt
. env/bin/activate && \
flake8 netutils_linux_monitoring netutils_linux_tuning netutils_linux_hardware

coverage:
nosetests --with-coverage --cover-package=twitter
Expand Down Expand Up @@ -62,3 +63,13 @@ mac_run_irqtop: env
. env/bin/activate && \
irqtop --random \
--interrupts-file=./tests/interrupts/singlequeue_8cpu/interrupts_short

mac_run_softirq_top: env
. env/bin/activate && \
softirq-top --random \
--softirqs-file=./tests/softirqs/i7/softirqs1

mac_run_softnet_stat_top:
. env/bin/activate && \
softnet-stat-top --random \
--softnet-stat-file=./tests/softnet_stat/softnet_stat1
6 changes: 4 additions & 2 deletions netutils_linux_monitoring/irqtop.py
Expand Up @@ -4,14 +4,16 @@
from copy import deepcopy
from optparse import Option
from netutils_linux_monitoring.base_top import BaseTop
from netutils_linux_monitoring.colors import colorize_cpu_list, wrap_header, wrap
from netutils_linux_monitoring.colors import colorize_cpu_list, colorize
from netutils_linux_monitoring.numa import Numa
from netutils_linux_monitoring.layout import make_table


class IrqTop(BaseTop):
""" Utility for monitoring hardware interrupts distribution """
diff_total = None
irq_warning = 40000
irq_error = 80000

def __init__(self, numa=None):
BaseTop.__init__(self)
Expand Down Expand Up @@ -67,7 +69,7 @@ def make_rows(self):
def __repr__(self):
output_lines, cpu_count = self.make_rows()
align_map = self.make_align_map(cpu_count)
output_lines.insert(1, self.diff_total + ['TOTAL'])
output_lines.insert(1, [colorize(irq, self.irq_warning, self.irq_error) for irq in self.diff_total] + ['TOTAL'])
output_lines.insert(2, [''] * (cpu_count + 1))
table = make_table(output_lines[0], align_map, output_lines[1:])
return self.__repr_table__(table)
Expand Down
37 changes: 20 additions & 17 deletions netutils_linux_monitoring/network_top.py
Expand Up @@ -8,7 +8,7 @@
from netutils_linux_monitoring import LinkRateTop
from netutils_linux_monitoring.numa import Numa
from netutils_linux_monitoring.base_top import BaseTop
from netutils_linux_monitoring.colors import cpu_color, colorize_cpu_list, ColorsNode, wrap, colorize, wrap_header
from netutils_linux_monitoring.colors import cpu_color, wrap, colorize, wrap_header
from netutils_linux_monitoring.layout import make_table


Expand Down Expand Up @@ -60,34 +60,37 @@ def __repr_cpu(self):
# all these evaluations are better to put in softirqs.parse()
active_cpu = softirq_top.__active_cpu_count__(
softirq_top.current)
softirq_rx = softirq_top.repr_source().get('NET_RX')[:active_cpu]
softirq_tx = softirq_top.repr_source().get('NET_TX')[:active_cpu]
softnet_stat_top_output = softnet_stat_top.repr_source()
network_output = zip(irqtop.diff_total,
softirq_rx,
softirq_tx,
softirq_top.repr_source()['NET_RX'][:active_cpu],
softirq_top.repr_source()['NET_TX'][:active_cpu],
softnet_stat_top_output)
fields = [
"CPU", "Interrupts", "NET RX", "NET TX",
"total", "dropped", "time_squeeze", "cpu_collision", "received_rps",
]
fields = [wrap(word, Style.BRIGHT) for word in fields]
rows = self.__repr_cpu_make_rows(irqtop, network_output, softirq_top, softnet_stat_top)
table = make_table(fields, ['l'] + ['r'] * (len(fields) - 1), rows)
return wrap_header("Load per cpu:") + str(table)

def __repr_cpu_make_rows(self, irqtop, network_output, softirq_top, softnet_stat_top):
rows = [
[
wrap("CPU{0}".format(softnet_stat.cpu), cpu_color(softnet_stat.cpu, self.numa)),
colorize(irq, 40000, 80000),
colorize(softirq_rx, 40000, 80000),
colorize(softirq_tx, 20000, 30000),
colorize(softnet_stat.total, 300000, 900000),
colorize(softnet_stat.dropped, 1, 1),
colorize(softnet_stat.time_squeeze, 1, 300),
colorize(softnet_stat.cpu_collision, 1, 1000),
softnet_stat.received_rps
wrap("CPU{0}".format(stat.cpu), cpu_color(stat.cpu, self.numa)),
colorize(irq, irqtop.irq_warning, irqtop.irq_error),
colorize(softirq_rx, softirq_top.net_rx_warning, softirq_top.net_rx_error),
colorize(softirq_tx, softirq_top.net_tx_warning, softirq_top.net_tx_error),
colorize(stat.total, softnet_stat_top.total_warning, softnet_stat_top.total_error),
colorize(stat.dropped, softnet_stat_top.dropped_warning, softnet_stat_top.dropped_error),
colorize(stat.time_squeeze, softnet_stat_top.time_squeeze_warning, softnet_stat_top.time_squeeze_error),
colorize(stat.cpu_collision, softnet_stat_top.cpu_collision_warning,
softnet_stat_top.cpu_collision_error),
stat.received_rps
]
for irq, softirq_rx, softirq_tx, softnet_stat in network_output
for irq, softirq_rx, softirq_tx, stat in network_output
]
table = make_table(fields, ['l'] + ['r'] * (len(fields) - 1), rows)
return wrap_header("Load per cpu:") + str(table)
return rows

def __repr__(self):
output = [
Expand Down
1 change: 1 addition & 0 deletions netutils_linux_monitoring/numa.py
Expand Up @@ -67,6 +67,7 @@ def detect_layouts(self):
self.numa_layout = dict(enumerate(numa_layout))
self.socket_layout = dict(enumerate(socket_layout))


if __name__ == '__main__':
numa = Numa()
print 'SOCKET', numa.socket_layout
Expand Down
5 changes: 5 additions & 0 deletions netutils_linux_monitoring/softirqs.py
Expand Up @@ -8,6 +8,11 @@
class Softirqs(BaseTop):
""" Utility for monitoring software interrupts distribution """

net_rx_warning = 40000
net_rx_error = 80000
net_tx_warning = 20000
net_tx_error = 30000

def __init__(self, numa=None):
BaseTop.__init__(self)
specific_options = [
Expand Down
12 changes: 10 additions & 2 deletions netutils_linux_monitoring/softnet_stat.py
Expand Up @@ -3,7 +3,7 @@
from netutils_linux_monitoring.base_top import BaseTop
from netutils_linux_monitoring.layout import make_table
from netutils_linux_monitoring.numa import Numa
from netutils_linux_monitoring.colors import cpu_color, wrap
from netutils_linux_monitoring.colors import cpu_color, wrap, colorize


class SoftnetStat(object):
Expand Down Expand Up @@ -54,6 +54,10 @@ class SoftnetStatTop(BaseTop):
""" Utility for monitoring packets processing/errors distribution per CPU """

align = ['l'] + ['r'] * 5
total_warning, total_error = 300000, 900000
dropped_warning = dropped_error = 1
time_squeeze_warning, time_squeeze_error = 1, 300
cpu_collision_warning, cpu_collision_error = 1, 1000

def __init__(self, numa=None):
BaseTop.__init__(self)
Expand Down Expand Up @@ -82,7 +86,11 @@ def make_header(self):
def make_rows(self):
return [[
wrap("CPU{0}".format(stat.cpu), cpu_color(stat.cpu, self.numa)),
stat.total, stat.dropped, stat.time_squeeze, stat.cpu_collision, stat.received_rps
colorize(stat.total, self.total_warning, self.total_error),
colorize(stat.dropped, self.dropped_warning, self.dropped_error),
colorize(stat.time_squeeze, self.time_squeeze_warning, self.time_squeeze_error),
colorize(stat.cpu_collision, self.cpu_collision_warning, self.cpu_collision_error),
stat.received_rps
]
for stat in self.repr_source()
]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -4,3 +4,4 @@ pyyaml
ipaddress
six
colorama
flake8
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -14,7 +14,7 @@ def read(*paths):

setuptools.setup(
name='netutils-linux',
version='1.3.3',
version='1.3.4',
author='Oleg Strizhechenko',
author_email='oleg.strizhechenko@gmail.com',
license='MIT',
Expand Down