Projet

Général

Profil

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

root / plugins / http / vhost_requests_ @ c6f88968

Historique | Voir | Annoter | Télécharger (3,29 ko)

1
#!/bin/bash
2
# -*- sh -*-
3

    
4
: <<END
5

    
6
=head1 NAME
7

    
8
vhost_requests_ - Wildcard-plugin to monitor http requests by response status code to a particular virtual host.
9

    
10
=head1 CONFIGURATION
11

    
12
Example configuration follows.
13

    
14
  [vhost_requests_*]
15
    user root
16

    
17
Or you can just give read access to munin.
18

    
19
An example way to create links for all logfiles (remove the \ from the \$s):
20
for f in \$(ls /var/log/apache2/*access_log) ; do ln -s /usr/share/munin/plugins/vhost_requests_ vhost_requests_\$(basename \$f); done
21

    
22
Also refer to max_lines, logdir, date_format and status_column below if you have any issue, if
23
you're on fedora you'll need to change at least logdir.
24

    
25
=head2 ENVIRONMENT VARIABLES
26

    
27
This plugin does not use environment variables
28

    
29
=head2 WILDCARD PLUGIN
30

    
31
This is a wildcard plugin.  To show requests by response status code
32
on a particular virtual host, link vhost_requests_<desired_access_log_filename> to this file.
33

    
34
E.g.
35

    
36
 ln -s /usr/share/munin/plugins/vhost_requests_ /etc/munin/plugins/vhost_requests_host.org-access_log
37

    
38
=head1 AUTHOR
39

    
40
Roberto Rodriguez
41

    
42
=cut
43
END
44

    
45
# This is the format that date will use to generate access_log like entries
46
date_format='+%d/%b/%Y:%R'
47
# This is where apache stores logfiles
48
logdir=/var/log/apache2
49

    
50
# By default process the whole logfile, but you can set a value different than 0 to limit the lines to process.
51
# This is useful if the plugin is hurting your performance, a way to calculate this could be:
52
# The expected requests in five minutes (you can grab this from the maximum value in the y legend)
53
# / 5 * 6 (Because we left the last minute to the next round)
54
# times how high can an unexpected peak be (Example 3 times)
55
# So, if we have 1000 requests every five minutes max_lines could be:
56
# 1000 / 5 * 6 * 3 = 3600
57
# It should improve performance because at 1000 requests per 5 minutes you have 288000 per day but it will only read 3600 each time.
58
max_lines=0
59
# If your http status code comes in a different column, you can change it here: (Assuming ' ' is the column separator)
60
status_column=9
61

    
62
file_name=`basename $0 | sed 's/^vhost_requests_//g'`
63

    
64
case $1 in
65
   config)
66
echo graph_category webserver
67
echo graph_title Requests by Status Code $file_name
68
echo graph_vlabel Nr of Requests
69
echo S200.label 200 OK
70
echo S206.label 206 Partial Content
71
echo S301.label 301 Moved Permanently
72
echo S302.label 302 Found
73
echo S303.label 303 See Other
74
echo S304.label 304 Not Modified
75
echo S400.label 400 Bad Request
76
echo S403.label 403 Forbidden
77
echo S404.label 404 Not Found
78
echo S405.label 405 Method Not Allowed
79
echo S500.label 500 Internal Server Error
80
echo S502.label 502 Bad Gateway
81
echo S503.label 503 Service Unavailable
82
echo S200.draw AREA
83
echo S206.draw STACK
84
echo S301.draw STACK
85
echo S302.draw STACK
86
echo S303.draw STACK
87
echo S304.draw STACK
88
echo S400.draw STACK
89
echo S403.draw STACK
90
echo S404.draw STACK
91
echo S405.draw STACK
92
echo S500.draw STACK
93
echo S502.draw STACK
94
echo S503.draw STACK
95
        exit 0;;
96
esac
97

    
98
if [ $max_lines -eq 0 ]
99
then
100
	for f in $(seq 5); do grep $(date $date_format -d "-$f min") $logdir/$file_name; done | cut -d' ' -f $status_column | sort | uniq -c | awk '{ print "S"$2".value "$1; }'
101
else
102
	for f in $(seq 5); do tail -n $max_lines $logdir/$file_name | grep $(date $date_format -d "-$f min"); done | cut -d' ' -f $status_column | sort | uniq -c | awk '{ print "S"$2".value "$1; }'
103
fi