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

Unified Diff: modules/nagios/files/check_connections

Issue 11773028: Added connections and memory monitoring (Closed)
Patch Set: Created Sept. 20, 2013, 10:25 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: modules/nagios/files/check_connections
===================================================================
new file mode 100644
--- /dev/null
+++ b/modules/nagios/files/check_connections
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+
+import subprocess
+
+if __name__ == "__main__":
+ process_output = subprocess.check_output(["netstat", "-nt"])
+
+ established = 0
+ opening = 0
+ closing = 0
+ for line in process_output.splitlines():
+ data = line.split()
+ if len(data) < 6:
+ continue
+
+ status = data[5]
+ if status == "ESTABLISHED":
+ established += 1
+ elif status == "SYN_RECV":
+ opening += 1
+ elif status in ("FIN_WAIT1", "FIN_WAIT2", "CLOSE_WAIT", "LAST_ACK", "CLOSING"):
+ closing += 1
+
+ status = "established %i opening %i closing %i" % (established, opening, closing)
+
+ perfdata = "established=%i opening=%i closing=%i" % (established, opening, closing)
+
+ output = "%s|%s" % (status, perfdata)
+
+ print "OK - " + output

Powered by Google App Engine
This is Rietveld