Skip to content

Commit

Permalink
First half-working prototype of network-top.
Browse files Browse the repository at this point in the history
  • Loading branch information
strizhechenko committed May 26, 2017
1 parent 1c87bbe commit c53e505
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 2 additions & 0 deletions netutils_linux/link_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def __init__(self, devices=None):
stats_header1 = " ".join(self.__indent__(n, v) for n, v in enumerate([""] + ["RX"] * 10 + ["TX"] * 3))
stats_header2 = " ".join(self.__indent__(n, stat.shortname) for n, stat in enumerate([Stat("", "")] + self.stats))
self.header = "\n".join([self.header, stats_header1, stats_header2])
if not self.devices:
raise ValueError("Where's my devices?")

def parse(self):
return dict((dev, self.__parse_dev__(dev)) for dev in self.devices)
Expand Down
19 changes: 15 additions & 4 deletions netutils_linux/network_top.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from irqtop import IrqTop
from softirqs import Softirqs
from softnet_stat import SoftnetStatTop
# from link_rate import LinkRateTop


class NetworkTop(Top):
Expand All @@ -13,17 +14,27 @@ def __init__(self):
'irqtop': IrqTop(),
'softnet_stat_top': SoftnetStatTop(),
'softirq_top': Softirqs(),
# 'link-rate': LinkRateTop(),
}

def parse(self):
return dict((top_name, top.parse()) for top_name, top in self.tops.iteritems())
print 'parse called'
return dict((top_name, _top.parse()) for top_name, _top in self.tops.iteritems())

def eval(self):
for top in self.tops.itervalues():
top.eval()
if all((self.current, self.previous)):
self.diff = dict((top_name, _top.diff) for top_name, _top in self.tops.iteritems())

def tick(self):
print 'tick called'
self.previous = self.current
self.current = self.parse()
for _top in self.tops.itervalues():
_top.tick()
self.eval()

def __repr__(self):
return "\n".join(str(top) for top in self.tops)
return "\n".join(str(_top) for top_name, _top in self.tops.iteritems())


if __name__ == '__main__':
Expand Down
7 changes: 7 additions & 0 deletions utils/network-top
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python

from netutils_linux.network_top import NetworkTop


if __name__ == '__main__':
NetworkTop().run()
16 changes: 16 additions & 0 deletions utils/subnet2iplist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python

import optparse
import ipaddress


def main():
parser = optparse.OptionParser()
options, args = parser.parse_args()
for arg in args:
for ip in ipaddress.ip_network(unicode(arg, 'utf-8')):
print ip


if __name__ == '__main__':
main()

0 comments on commit c53e505

Please sign in to comment.