Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: modules/nagios/files/check_bandwidth

Issue 10992045: Switch to bwm-ng for bandwidth monitoring (Closed)
Left Patch Set: Created June 28, 2013, 10:02 a.m.
Right Patch Set: Created July 2, 2013, 10:24 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | modules/nagios/manifests/client.pp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import os, re, subprocess, sys 3 import os, re, subprocess, sys
4 4
5 def format_bandwidth(bits): 5 def format_bandwidth(bits):
6 if bits >= 2000000: 6 if bits >= 1000000:
Felix Dahlke 2013/07/02 09:55:32 Shouldn't it be 1000000 here and 1000 below?
Wladimir Palant 2013/07/02 10:25:16 Not sure, I slightly remember that 1610 kbit/s is
7 return "%.2f Mbit/s" % (bits / 1000000) 7 return "%.2f Mbit/s" % (bits / 1000000)
8 elif bits >= 2000: 8 elif bits >= 1000:
9 return "%.2f kbit/s" % (bits / 1000) 9 return "%.2f kbit/s" % (bits / 1000)
10 else: 10 else:
11 return "%.2f bit/s" % bits 11 return "%.2f bit/s" % bits
12 12
13 if __name__ == "__main__": 13 if __name__ == "__main__":
14 if len(sys.argv) != 3: 14 if len(sys.argv) != 3:
15 script_name = os.path.basename(sys.argv[0]) 15 script_name = os.path.basename(sys.argv[0])
16 print "Usage: %s WARN CRIT" % script_name 16 print "Usage: %s WARN CRIT" % script_name
17 sys.exit(0) 17 sys.exit(0)
18 18
19 (warn, crit) = sys.argv[1:3] 19 (warn, crit) = sys.argv[1:3]
20 warn = int(sys.argv[1]) 20 warn = int(sys.argv[1])
21 crit = int(sys.argv[2]) 21 crit = int(sys.argv[2])
22 22
23 vnstat_output = subprocess.check_output(["bwm-ng", "-I", "eth0", "-t", "5000", "-c", "1", "-o", "csv"]) 23 process_output = subprocess.check_output(["bwm-ng", "-I", "eth0", "-t", "5000" , "-c", "1", "-o", "csv"])
Wladimir Palant 2013/06/28 10:12:22 Oops, maybe I should have changed the name of that
Felix Dahlke 2013/07/02 09:55:32 Yup, please do :P
24 data = vnstat_output.splitlines()[0].split(";") 24 data = process_output.splitlines()[0].split(";")
25 tx = float(data[2]) * 8 25 tx = float(data[2]) * 8
26 rx = float(data[3]) * 8 26 rx = float(data[3]) * 8
27 status = "rx %s tx %s" % (format_bandwidth(rx), format_bandwidth(tx)) 27 status = "rx %s tx %s" % (format_bandwidth(rx), format_bandwidth(tx))
28 28
29 perfdata = "rx=%i;%s;%s tx=%i;%s;%s" % (rx, warn, crit, tx, warn, crit) 29 perfdata = "rx=%i;%i;%i tx=%i;%i;%i" % (rx, warn, crit, tx, warn, crit)
Wladimir Palant 2013/06/28 10:12:22 Might be better to use %i for the other parameters
Felix Dahlke 2013/07/02 09:55:32 Yes, no idea why I didn't.
30 30
31 output = "%s|%s" % (status, perfdata) 31 output = "%s|%s" % (status, perfdata)
32 32
33 if rx >= crit or tx >= crit: 33 if rx >= crit or tx >= crit:
34 print "CRITICAL - " + output 34 print "CRITICAL - " + output
35 sys.exit(2) 35 sys.exit(2)
36 36
37 if rx >= warn or tx >= warn: 37 if rx >= warn or tx >= warn:
38 print "WARNING - " + output 38 print "WARNING - " + output
39 sys.exit(1) 39 sys.exit(1)
40 40
41 print "OK - " + output 41 print "OK - " + output
LEFTRIGHT

Powered by Google App Engine
This is Rietveld