root / plugins / apache / apache_byprojects / byprojects_inout_bandwidth @ 4b2fcbf8
Historique | Voir | Annoter | Télécharger (3,31 ko)
| 1 | 614c22df | Danny Fullerton | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | 5271859f | Danny Fullerton | use strict; |
| 3 | 614c22df | Danny Fullerton | # |
| 4 | # byprojects_inout_bandwidth |
||
| 5 | # |
||
| 6 | cf03f9b0 | Danny Fullerton | # Perl script to monitor in/out bandwidth *byprojects* (e.g. vhost) from |
| 7 | # multiple files and/or regex. |
||
| 8 | 614c22df | Danny Fullerton | # |
| 9 | # Danny Fullerton <northox@mantor.org> |
||
| 10 | # Mantor Organization <www.mantor.org> |
||
| 11 | cf03f9b0 | Danny Fullerton | # This work is licensed under a MIT license. |
| 12 | 614c22df | Danny Fullerton | # |
| 13 | 5271859f | Danny Fullerton | # You need logtail (https://www.fourmilab.ch/webtools/logtail/) |
| 14 | 614c22df | Danny Fullerton | # |
| 15 | cf03f9b0 | Danny Fullerton | # mod_logio apache module (https://httpd.apache.org/docs/2.0/mod/mod_logio.html) |
| 16 | # Your logformat should look like this: |
||
| 17 | # "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O"
|
||
| 18 | 614c22df | Danny Fullerton | # where %I is input and %O is output. |
| 19 | # |
||
| 20 | cf03f9b0 | Danny Fullerton | # Log can be gathered from multiple sources by simply specifying multiple log |
| 21 | # filename or using wildcards (glob). File content can be selected using regex. |
||
| 22 | # |
||
| 23 | # - 'prod' => [ {'path' => '/home/prod/log/access.log'} ],
|
||
| 24 | # Prod graph will be using everything in /home/prod/log/access.log |
||
| 25 | # |
||
| 26 | # - 'test' => [ {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
||
| 27 | # {'path' => '/home/test/log/access*.log'} ],
|
||
| 28 | # Test graph will be using everything file matching /home/test/log/access*.log |
||
| 29 | # and stuff that match the expression '"[A-Z] /test/' in /var/log/access.log |
||
| 30 | # such as '"GET /test/' |
||
| 31 | 614c22df | Danny Fullerton | |
| 32 | 5271859f | Danny Fullerton | my $server = 'Apache'; |
| 33 | 614c22df | Danny Fullerton | |
| 34 | 4b2fcbf8 | Lars Kruse | my $statepath = $ENV{MUNIN_PLUGSTATE};
|
| 35 | 5271859f | Danny Fullerton | my $logtail = '/usr/local/bin/logtail'; |
| 36 | 614c22df | Danny Fullerton | |
| 37 | 5271859f | Danny Fullerton | my %logs = ( |
| 38 | 'prod' => [ |
||
| 39 | {'path' => '/home/prod/log/access.log'}
|
||
| 40 | ], |
||
| 41 | 'dev' => [ |
||
| 42 | {'path' => '/var/log/httpd/ssl-dev-access.log'},
|
||
| 43 | {'path' => '/home/dev/log/access.log'}
|
||
| 44 | ], |
||
| 45 | 'test' => [ |
||
| 46 | {'path' => '/var/log/access.log', 'regex' => '"[A-Z]+ /test/'},
|
||
| 47 | {'path' => '/home/test/log/access.log'}
|
||
| 48 | ], |
||
| 49 | 614c22df | Danny Fullerton | ); |
| 50 | |||
| 51 | 5271859f | Danny Fullerton | |
| 52 | 614c22df | Danny Fullerton | ########### |
| 53 | |||
| 54 | if(defined($ARGV[0])) {
|
||
| 55 | if ($ARGV[0] eq 'autoconf') {
|
||
| 56 | print "yes\n"; |
||
| 57 | exit(0); |
||
| 58 | } elsif ($ARGV[0] eq 'config') {
|
||
| 59 | print "graph_title $server in/out bandwidth byprojects\n"; |
||
| 60 | print "graph_args --base 1000\n"; |
||
| 61 | print "graph_vlabel bits per \${graph_period} in (-) / out (+)\n";
|
||
| 62 | b19b3a81 | dipohl | print "graph_category webserver\n"; |
| 63 | a2bedd79 | Stig Sandbeck Mathisen | print "graph_info This graph show $server in/out bandwidth used by various" . |
| 64 | cf03f9b0 | Danny Fullerton | " projects.\n"; |
| 65 | 5271859f | Danny Fullerton | while ((my $project, my @files) = each(%logs)) {
|
| 66 | print "i".$project.".label $project\n"; |
||
| 67 | print "i".$project.".type GAUGE\n"; |
||
| 68 | print "i".$project.".graph no\n"; |
||
| 69 | print "i".$project.".cdef i".$project.",8,*\n"; |
||
| 70 | print "o".$project.".label $project\n"; |
||
| 71 | print "o".$project.".type GAUGE\n"; |
||
| 72 | print "o".$project.".negative i".$project."\n"; |
||
| 73 | print "o".$project.".cdef o".$project.",8,*\n"; |
||
| 74 | 614c22df | Danny Fullerton | } |
| 75 | exit(0); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | 5271859f | Danny Fullerton | foreach my $project ( keys %logs ) {
|
| 80 | my $i = 0; |
||
| 81 | my $o = 0; |
||
| 82 | my $x = 0; |
||
| 83 | foreach my $log ( @{$logs{$project}} ) {
|
||
| 84 | cf03f9b0 | Danny Fullerton | my @paths = glob $log->{'path'};
|
| 85 | foreach my $path (@paths) {
|
||
| 86 | my $state = $statepath.'/'.$project.$x.'_inoutbandwidth.state'; |
||
| 87 | open(LT, "$logtail -f ".$log->{'path'}." -o $state |") or
|
||
| 88 | die "Can't open $logtail : $!"; |
||
| 89 | while (<LT>) {
|
||
| 90 | my $buf = $_; |
||
| 91 | if($buf eq '') { next }
|
||
| 92 | if(!defined($log->{'regex'}) || $buf =~ m/$log->{'regex'}/) {
|
||
| 93 | if($buf =~ m/(\d+) (\d+)$/) {
|
||
| 94 | $i += $1; |
||
| 95 | $o += $2; |
||
| 96 | } |
||
| 97 | 614c22df | Danny Fullerton | } |
| 98 | } |
||
| 99 | cf03f9b0 | Danny Fullerton | close(LT); |
| 100 | $x++; |
||
| 101 | 614c22df | Danny Fullerton | } |
| 102 | } |
||
| 103 | 5271859f | Danny Fullerton | print "i".$project.".value $i\n"; |
| 104 | print "o".$project.".value $o\n"; |
||
| 105 | 614c22df | Danny Fullerton | } |
