Created
June 27, 2018 12:54
-
-
Save buty4649/99f5466c8a1252476a3989b444104219 to your computer and use it in GitHub Desktop.
dstatでsnat netnsごとにトラフィックを見る奴
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class dstat_plugin(dstat): | |
def __init__(self): | |
self.nick = ('#recv', '#send') | |
self.type = 'd' | |
self.width = 5 | |
self.scale = 1024 | |
self.cols = 2 | |
def vars(self): | |
import subprocess | |
cmd = "ip netns | grep snat-" | |
ret = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).stdout.readlines() | |
return [str(x).rstrip("\n") for x in ret] | |
def name(self): | |
return [name[5:14] for name in self.vars] | |
def extract(self): | |
import subprocess | |
for netns in self.vars: | |
cmd = "ip netns exec %s cat /proc/net/dev" % netns | |
for line in subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).stdout.readlines(): | |
l = line.split() | |
if len(l) < 17: continue | |
if l[1] == '0' and l[9] == '0': continue | |
self.set2[netns] = (long(l[1]), long(l[9])) | |
if update: | |
for name in self.set2: | |
self.val[name] = map(lambda x, y: (y - x) * 1.0 / elapsed, self.set1[name], self.set2[name]) | |
if step == op.delay: | |
self.set1.update(self.set2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment