]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Import suri-graphite script
authorEric Leblond <eric@regit.org>
Wed, 13 Mar 2013 09:50:21 +0000 (10:50 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 19 Jun 2013 10:23:37 +0000 (12:23 +0200)
This patch import suri-graphite into suricata contrib directory.
This script reads counters from suricata unix socket and send them
to a Graphite graphing server.

contrib/Makefile.am
contrib/suri-graphite [new file with mode: 0755]

index 2fe815ad9ef3fc884b53ea76061d3f2efbcc460f..0f7e35caec20eb83d946c3ad4785d1e1a8943af4 100644 (file)
@@ -1 +1,3 @@
 SUBDIRS = file_processor
+
+EXTRA_DIST = suri-graphite
diff --git a/contrib/suri-graphite b/contrib/suri-graphite
new file mode 100755 (executable)
index 0000000..c7d675b
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+# Copyright (C) 2013 Eric Leblond <eric@regit.org>
+#
+# You can copy, redistribute or modify this Program under the terms of
+# the GNU General Public License version 3 as published by the Free
+# Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# version 3 along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+import suricatasc
+import socket
+import time
+import argparse
+
+parser = argparse.ArgumentParser(prog='suri-graphite', description='Export suricata stats to Graphite')
+parser.add_argument('-H', '--host', default='localhost', help='Host running Graphite')
+parser.add_argument('-P', '--port', default=2003, help='Port of Graphite data socket')
+parser.add_argument('-D', '--delay', default=10, help='Delay between data dump')
+parser.add_argument('-r', '--root', default='suricata.perf', help='Prefix of data name in Graphite')
+parser.add_argument('socket', help='suricata socket file to connect to',
+                    default="/usr/local/var/run/suricata/suricata-command.socket", nargs='?')
+parser.add_argument('-v', '--verbose', action='store_const', const=True, help='verbose output', default=False)
+
+args = parser.parse_args()
+sc = suricatasc.SuricataSC(args.socket)
+sc.connect()
+
+sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+sck.connect((args.host, args.port))
+
+while 1:
+    res = sc.send_command("dump-counters")
+    res = res['message']
+    tnow = int(time.time())
+    for thread in res:
+        for counter in res[thread]:
+            sck.send("%s.%s.%s %s %d\n" % (args.root, thread , counter, res[thread][counter], tnow))
+            if args.verbose:
+                print "%s.%s.%s %s %d\n" % (args.root, thread , counter, res[thread][counter], tnow)
+    time.sleep(float(args.delay))