PluginCat: apache_auth_users

File apache_auth_users, 1.4 kB (added by gyufi@direction.hu, 6 years ago)

apache_auth_users

Line 
1 #!/usr/bin/perl -w
2 #
3 # Plugin to monitor authenticated users
4 #
5 # Parameters:
6 #
7 #       logfile      - Location of the apache log
8 #       statefile    - Where to put temporary statefile.
9 #
10 # gyufi@direction.hu
11 # 2006.04.06
12 #
13 #%# family=contrib
14
15 use strict;
16
17 my $QUERYLOG=$ENV{logfile} || '/var/log/apache2/access.log';
18 my $STATEFILE=$ENV{statefile} || '/var/lib/munin/plugin-state/apache_auth_users.state';
19 my $OTHER=0;
20 my %IN;
21
22 sub get_state {
23     open(Q,"< $STATEFILE") or die "Statefile not found";
24     while (<Q>) {
25         chomp;
26         my ($q,$n) = split(/\s+/,$_,2);
27         $IN{$q}=$n unless defined($IN{$q});
28     }
29     close(Q);
30 }
31
32
33 sub do_stats {
34     my $k;
35
36     open(Q,"< $QUERYLOG") or die "$!";
37     while (<Q>) {
38         chomp;
39         if (/^[^\s]+ \- ([^\s]+) /) {
40             if ($1 !~ /\-/ ) {
41                 $IN{$1}++;
42             }
43         }
44     }
45     close(Q);
46
47     get_state;
48
49     open(Q,"> $STATEFILE") or die;
50     foreach $k (keys %IN) {
51         print "query_$k.value ",$IN{$k},"\n";
52         print Q "$k ",$IN{$k},"\n";
53     }
54     close(Q);
55 }
56
57
58 sub do_config {
59     my $k;
60
61     print "graph_title Authenticated Apache users
62 graph_vlabel Hits / \${graph_period}
63 query_other.label Other
64 query_other.type DERIVE
65 query_other.min 0
66 query_other.draw AREA
67 ";
68     get_state;
69
70     foreach $k (keys %IN) {
71         print "query_$k.label $k
72 query_$k.type DERIVE
73 query_$k.min 0
74 query_$k.draw STACK
75 ";
76     }
77 };
78
79 if (defined($ARGV[0]) and ($ARGV[0] eq 'config')) {
80     do_config;
81     exit(0);
82 }
83
84 do_stats;
85
86
87 # vim:syntax=perl