]>
git.ipfire.org Git - people/ms/suricata.git/blob - contrib/suri-graphite
2 # Copyright (C) 2013 Eric Leblond <eric@regit.org>
4 # You can copy, redistribute or modify this Program under the terms of
5 # the GNU General Public License version 3 as published by the Free
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # version 3 along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 parser
= argparse
.ArgumentParser(prog
='suri-graphite', description
='Export suricata stats to Graphite')
24 parser
.add_argument('-H', '--host', default
='localhost', help='Host running Graphite')
25 parser
.add_argument('-P', '--port', default
=2003, help='Port of Graphite data socket')
26 parser
.add_argument('-O', '--oneshot', action
='store_const', const
=True, help='Send one update and exit', default
=False)
27 parser
.add_argument('-D', '--delay', default
=10, help='Delay between data dump')
28 parser
.add_argument('-r', '--root', default
='suricata.perf', help='Prefix of data name in Graphite')
29 parser
.add_argument('socket', help='suricata socket file to connect to',
30 default
="/usr/local/var/run/suricata/suricata-command.socket", nargs
='?')
31 parser
.add_argument('-v', '--verbose', action
='store_const', const
=True, help='verbose output', default
=False)
33 args
= parser
.parse_args()
34 sc
= suricatasc
.SuricataSC(args
.socket
)
37 sck
= socket
.socket(socket
.AF_INET
, socket
.SOCK_STREAM
)
38 sck
.connect((args
.host
, args
.port
))
41 res
= sc
.send_command("dump-counters")
43 tnow
= int(time
.time())
45 for counter
in res
[thread
]:
46 sck
.send("%s.%s.%s %s %d\n" % (args
.root
, thread
, counter
, res
[thread
][counter
], tnow
))
48 print "%s.%s.%s %s %d\n" % (args
.root
, thread
, counter
, res
[thread
][counter
], tnow
)
51 time
.sleep(float(args
.delay
))