From 40ec9801f161331caaf6bbd81a609ba91081288d Mon Sep 17 00:00:00 2001 From: "Roman V. Nikolaev" Date: Wed, 8 May 2013 22:08:06 +0400 Subject: [PATCH 1/4] add syslog-ng plugin --- plugins/syslog/syslog_ng_stats | 132 +++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 plugins/syslog/syslog_ng_stats diff --git a/plugins/syslog/syslog_ng_stats b/plugins/syslog/syslog_ng_stats new file mode 100644 index 00000000..9c806b37 --- /dev/null +++ b/plugins/syslog/syslog_ng_stats @@ -0,0 +1,132 @@ +#!/usr/bin/perl + +=head1 NAME + +syslog_ng_stats - Plugin for syslog-ng use C utility to +make grapths. + +=head1 DESCRIPTION + +See C for C option. All options used as regexp. + +=over + +=item source_name + +=item source_id + +=item source_instance + +=item state + +=item type + +=back + +Example of input and destination via tcp for my application: + + [syslog_ng_stats] + user root + env.source_name = source dst\.tcp + env.source_id = myname + +=head1 AUTHORS + +Dmitry E. Oboukhov , +Roman V. Nikolaev + +=head1 COPYRIGHT + +Copyright (C) 2013 Dmitry E. Oboukhov +Copyright (C) 2013 Roman V. Nikolaev + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.8.8 or, +at your option, any later version of Perl 5 you may have available. + +=cut + +use strict; +use warnings; +use utf8; +use open qw(:utf8 :std); +use List::MoreUtils qw(any); + +# Filters +my (@source_name, @source_id, @source_instance, @state, @type); +@source_name = split m{\s+}, $ENV{source_name} if $ENV{source_name}; +@source_id = split m{\s+}, $ENV{source_id} if $ENV{source_id}; +@source_instance = split m{\s+}, $ENV{source_instance} + if $ENV{source_instance}; +@state = split m{\s+}, $ENV{state} if $ENV{state}; +@type = split m{\s+}, $ENV{type} if $ENV{type}; + +# Get stats +my $data = `syslog-ng-ctl stats`; +die 'Can`t get stats from syslog-ng-ctl' unless $data; + +# Split to graphs +my @str = split m{\n+}, $data; +# Remove title +shift @str; + +my @gpaths; +for my $graph (@str) { + # Split to data + $graph = [ split m{;}, $graph ]; + $graph = { + source_name => $graph->[0], + source_id => $graph->[1], + source_instance => $graph->[2], + state => $graph->[3], + type => $graph->[4], + number => $graph->[5], + }; + + # Apply filters + next if @source_name and + ! any {$graph->{source_name} =~ m{$_}i } @source_name; + next if @source_id and + ! any {$graph->{source_id} =~ m{$_}i } @source_id; + next if @source_instance and + ! any {$graph->{source_instance} =~ m{$_}i } @source_instance; + next if @state and + ! any {$graph->{state} =~ m{$_}i } @state; + next if @type and + ! any {$graph->{type} =~ m{$_}i } @type; + + # Save graph + push @gpaths, $graph; +} + +# Show config +if( grep m{^config$}, @ARGV ) { + print "graph_title Syslog-ng statistics\n"; + print "graph_vlabel count\n"; + print "graph_args --base 1000 --lower-limit 0 --rigid\n"; + print "graph_info This graph show syslog-ng-ctl stats\n"; + print "graph_category syslog\n"; + for my $graph (@gpaths) { + # ID + my $id = sprintf '%s_%s', + $graph->{source_id} || $graph->{source_instance}, + $graph->{type}; + s{#(\d+)}{[$1]}, s{[^\w\]\[]+}{_}g for $id; + + printf "%s.label %s: %s, %s\n", $id, + $graph->{source_name},$graph->{source_id}, $graph->{type}; + printf "%s.min 0\n", $id; + } +} + +for my $graph (@gpaths) { + # ID + my $id = sprintf '%s_%s', + $graph->{source_id} || $graph->{source_instance}, + $graph->{type}; + s{#(\d+)}{[$1]}, s{[^\w\]\[]+}{_}g for $id; + + printf "%s.value %s\n", $id, $graph->{number}; +} + +exit; From 928f9d3dfe1d841d807a0dbf8c43b3dc184c98a8 Mon Sep 17 00:00:00 2001 From: "Roman V. Nikolaev" Date: Sun, 12 May 2013 16:31:12 +0400 Subject: [PATCH 2/4] remove grep for args --- plugins/syslog/syslog_ng_stats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/syslog/syslog_ng_stats b/plugins/syslog/syslog_ng_stats index 9c806b37..17750b1e 100644 --- a/plugins/syslog/syslog_ng_stats +++ b/plugins/syslog/syslog_ng_stats @@ -100,7 +100,7 @@ for my $graph (@str) { } # Show config -if( grep m{^config$}, @ARGV ) { +if( exists $ARGV[0] and $ARGV[0] eq "config" ) { print "graph_title Syslog-ng statistics\n"; print "graph_vlabel count\n"; print "graph_args --base 1000 --lower-limit 0 --rigid\n"; From f68e4c96960d14251ab8cded94e5eb70481ab3e0 Mon Sep 17 00:00:00 2001 From: "Roman V. Nikolaev" Date: Sun, 12 May 2013 16:33:27 +0400 Subject: [PATCH 3/4] add comment --- plugins/syslog/syslog_ng_stats | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/syslog/syslog_ng_stats b/plugins/syslog/syslog_ng_stats index 17750b1e..73ed6ef2 100644 --- a/plugins/syslog/syslog_ng_stats +++ b/plugins/syslog/syslog_ng_stats @@ -119,6 +119,7 @@ if( exists $ARGV[0] and $ARGV[0] eq "config" ) { } } +# Print values for my $graph (@gpaths) { # ID my $id = sprintf '%s_%s', From 6368f71a013c40044179691f862cc1caea7fa69e Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Tue, 21 May 2013 14:02:51 +0200 Subject: [PATCH 4/4] plugins/syslog_ng_stats: comment formating --- plugins/syslog/syslog_ng_stats | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/syslog/syslog_ng_stats b/plugins/syslog/syslog_ng_stats index 73ed6ef2..6170c25c 100644 --- a/plugins/syslog/syslog_ng_stats +++ b/plugins/syslog/syslog_ng_stats @@ -2,12 +2,13 @@ =head1 NAME -syslog_ng_stats - Plugin for syslog-ng use C utility to -make grapths. +syslog_ng_stats - Plugin for syslog-ng. +It uses the C utility to grab values. =head1 DESCRIPTION -See C for C option. All options used as regexp. +See C for the C option. +All options used are regexp. =over