Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / apache / apache_byprojects / byprojects_access @ 614c22df

Historique | Voir | Annoter | Télécharger (2,38 ko)

1
#!/usr/bin/perl -w
2
#
3
# byprojects_access
4
#
5
# Perl script to monitor access *byprojects* (e.g. vhost) from multiple files and/or regex.
6
#
7
# Danny Fullerton <northox@mantor.org> 
8
# Mantor Organization <www.mantor.org>
9
# This work is licensed under a Creative Commons Attribution 3.0 Unported License.
10
#
11
# You need logtail (https://www.fourmilab.ch/webtools/logtail/)
12
#
13
# Log can be gather from multiple sources by simply specifying multiple log filename and/or an array with two
14
# elements: log filename and a regex.
15
#   - 'prod' => array('/home/prod/log/access.log'),
16
#     Prod graph will be using everything in /home/prod/log/access.log
17
#   - 'test' => array(array('/var/log/httpd/access.log', '"[A-Z]+ /test/'), '/home/test/log/access.log')
18
#     Test graph will be using eveything in /home/test/log/access.log and stuff that match '"[A-Z] /test/' in 
19
#     /var/log/httpd/access.log such as '"GET /test/'
20

    
21
$server = 'Apache';
22

    
23
$statepath = '/usr/local/var/munin/plugin-state'; # where logtail will save the state
24
$logtail = '/usr/local/bin/logtail';
25

    
26
%logs = (
27
'prod' => ('/home/prod/log/access.log'),
28
'test' => (
29
            ('/var/log/httpd/access.log', '"[A-Z]+ /test/'),
30
            '/home/test/log/access.log'
31
          )
32
);
33

    
34
###########
35

    
36
if(defined($ARGV[0])) {
37
  if ($ARGV[0] eq 'autoconf') {
38
    print "yes\n";
39
    exit(0);
40
  } elsif ($ARGV[0] eq 'config') {
41
    $order = '';
42
    while (($client, $files) = each(%logs)) { $order .= $client.' ' }
43
    print "graph_order $order\n";
44
    print "graph_title $server access byprojects\n";
45
    print "graph_total Total\n";
46
    print "graph_vlabel Access by \${graph_period}\n";
47
    print "graph_category $server\n";
48
    print "graph_info This graph show $server access by various projects.\n";
49
    while (($client, $files) = each(%logs)) {
50
      print $client.".label $client\n";
51
      print $client.".type DERIVE\n";
52
      print $client.".min 0\n";
53
    }
54
    exit(0);
55
  }
56
}
57

    
58
while (($client, $files) = each(%logs)) {
59
  $x = $i = 0;
60
  foreach $file ($files) {
61
    $regex = '';
62
    $state = $statepath.'/'.$client.$x.'_access.state';
63
    if(ref($file) eq 'ARRAY') { ($file, $regex) = @file }
64
    open(my $lt, "$logtail -f $file -o $state |") or die "Can't open $logtail : $!";
65
    while (<$lt>) {
66
      $buf = $_;
67
      if($buf eq '') { next }
68
      if(!defined($regex) || $buf =~ m/$regex/) {
69
        $i++;
70
      }
71
    }
72
    close($lt);
73
    $x++;
74
  }
75
  print $client.".value $i\n";
76
}