Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
imZack committed May 19, 2015
1 parent 7c320b7 commit 455c99e
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions netmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def init(self, *args, **kwargs):
self.do_start()

def read_bandwidth(self):
subprocess.call(["vnstat", "-u", "-i", self.interface])
tmp = subprocess.check_output("vnstat --xml -i " +
self.interface +
"|grep -m 1 total", shell=True)
Expand All @@ -47,29 +48,27 @@ def run(self):
motd = 0
count = self.read_bandwidth()
if count < self.threshold:
sleep(60)
continue

while True:
if motd == 0:
self.publish.event(
_logger.debug(
"Reach limited threshold %s" % self.threshold)
self.publish.event.put(
"/network/bandwidth/event",
data={
"info": self.read_bandwidth(),
"enable": self.vnstat_start,
"interface": self.interface,
"threshold": self.threshold
})
if motd % 60 == 0:
_logger.debug(
"Reach limited threshold %s" % self.threshold)
if (motd >= 60) or (self.read_bandwidth() == 0):
break
else:
motd += 1

sleep(1)
if motd >= 5 or self.read_bandwidth() == 0:
break

sleep(60)
motd += 1
sleep(60)

@Route(methods="get", resource="/network/bandwidth")
def get_root(self, message, response):
Expand Down

0 comments on commit 455c99e

Please sign in to comment.