Projet

Général

Profil

Révision 4771fd2b

ID4771fd2b53abffaed26f1a86b135437994635a50
Parent 4f29ff59
Enfant d189784c

Ajouté par rfrail3 il y a environ 13 ans

New plugins for Apache web server

Voir les différences:

plugins/apache/apache_average_requests
1
#!/usr/bin/perl
2
# -*- cperl -*-
3

  
4
=head1 NAME
5

  
6
apache_average_request - Munin plugin to monitor the average request to
7
Apache servers. It handles a list of ports passed in from a plugin
8
configuration file.
9

  
10
=head1 APPLICABLE SYSTEMS
11

  
12
Apache HTTP servers with C</server-status> enabled.
13

  
14
=head1 CONFIGURATION
15

  
16
Enable stats in apache first!:
17

  
18
<VirtualHost 127.0.0.1:80>
19
        <Location /server-status>
20
         SetHandler server-status
21
         AuthUserFile /route/to/auth.file
22
         AuthName Login-Stats
23
         AuthType Basic
24
         require valid-user
25
        </Location>
26
</VirtualHost>
27

  
28
And now in munin conf:
29

  
30
[apache_*]
31
env.url http://USER:PASS@127.0.0.1/server-status?auto
32
env.ports 80
33

  
34
=head1 AUTHOR
35

  
36
Ricardo Fraile <rfrail3@yahoo.es>
37
Unknown
38

  
39
=head1 LICENSE
40

  
41
GPLv2
42

  
43
=head1 MAGIC MARKERS
44

  
45
  #%# family=auto
46
  #%# capabilities=autoconf
47

  
48
=cut
49

  
50
use strict;
51
use warnings;
52
use Munin::Plugin;
53

  
54
my $ret = undef;
55

  
56
if (! eval "require LWP::UserAgent;")
57
{
58
	$ret = "LWP::UserAgent not found";
59
        if ( ! defined $ARGV[0] ) {
60
                die $ret;
61
        }
62
}
63

  
64
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/server-status?auto";
65
my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (80);
66

  
67
if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" )
68
{
69
	if ($ret)
70
	{
71
		print "no ($ret)\n";
72
		exit 0;
73
	}
74

  
75
	my $ua = LWP::UserAgent->new(timeout => 30);
76

  
77
	foreach my $port (@PORTS) {
78
		my $url = sprintf $URL, $port;
79
		my $response = $ua->request(HTTP::Request->new('GET',$url));
80
                if ($response->is_success) {
81
                        if ($response->content =~ /^Total Accesses:/im ){
82
                                next;
83
                        }
84
                        else {
85
                                print "no (ExtendedStatus option for apache" 
86
				      . " mod_status is missing on port $port)\n";
87
                                exit 0;
88
                        }
89
                }
90
                elsif ($response->code == 404)  {
91
                        print "no (apache server-status not found. check if mod_status is enabled)\n";
92
                        exit 0;
93
                }
94
                else {
95
                        print "no (Port $port: ". $response->message .")\n";
96
                        exit 0;
97
                }
98
	}
99
	print "yes\n";
100
	exit 0;
101
}
102

  
103
if ( defined $ARGV[0] and $ARGV[0] eq "config" )
104
{
105

  
106
	print "graph_title Average apache request\n";
107
	print "graph_title Average apache Requests per second\n";
108
	print "graph_vlabel average reqs/sec\n";
109
	print "graph_scale no\n";
110
	print "graph_category apache\n";
111
	print "request.label Average apache reqs/sec\n";
112
        exit 0;
113

  
114
}
115

  
116
my $ua = LWP::UserAgent->new(timeout => 30);
117

  
118
foreach my $port (@PORTS) {
119
	my $url = sprintf $URL, $port;
120
	my $response = $ua->request(HTTP::Request->new('GET',$url));
121
	if ($response->content =~ /^ReqPerSec:\s+(.+)$/im) {
122
		print "request.value $1\n";
123
	} else {
124
		print "request.value U\n";
125
	}
126
}
127

  
128
# vim:syntax=perl
plugins/apache/apache_memmory
1
#!/bin/sh
2
# -*- sh -*-
3

  
4
: << =cut
5

  
6
=head1 NAME
7

  
8
apache_memmory -Indicate the medium size of all the apache child process
9

  
10
=head1 CONFIGURATION
11

  
12
[apache_*]
13
env.url http://USER:PASS@127.0.0.1/server-status?auto
14
env.apuser user_runnin_apache
15
env.binname apache_binary_name
16

  
17

  
18
=head1 AUTHOR
19

  
20
Ricardo Fraile <rfrail3@yahoo.es>
21

  
22
=head1 LICENSE
23

  
24
GPLv2
25

  
26
=head1 MAGICK MARKERS
27

  
28
 #%# family=auto
29
 #%# capabilities=autoconf
30

  
31
=cut
32

  
33
. $MUNIN_LIBDIR/plugins/plugin.sh
34

  
35
USR=$apuser
36
PROCS=$binname
37

  
38

  
39
if [ "$1" = "autoconf" ]; then
40
	echo yes 
41
	exit 0
42
fi
43

  
44
if [ "$1" = "config" ]; then
45

  
46
	echo 'graph_title Medium size of apache child process.'
47
	echo 'graph_args --base 1000 -l 0 '
48
	echo 'graph_vlabel Kb'
49
	echo 'graph_scale no'
50
	echo 'graph_category apache'
51
	echo 'graph_info Indicate the memdium size of all the apache child process.'
52

  
53

  
54

  
55
        echo "servers.label servers"
56
        echo "servers.type GAUGE"
57
        echo "servers.min 0"
58

  
59
	exit 0
60
fi
61

  
62
VAL1=`ps auxf | grep ${PROCS} | grep ${USR} | grep -v grep | wc -l`
63

  
64
VAL2=`ps auxf | grep ${PROCS} | grep ${USR} | grep -v grep | awk '{s+=$6} END {print s}'`
65

  
66
VAL3=`expr $VAL2 / $VAL1`
67

  
68
echo "servers.value $VAL3"
69
	
70

  
plugins/apache/apache_servers
1
#!/bin/sh
2
# -*- sh -*-
3

  
4
: << =cut
5

  
6
=head1 NAME
7

  
8
apache_servers -Indicate the number of apache servers running (child process)
9

  
10
=head1 CONFIGURATION
11

  
12
[apache_*]
13
env.url http://USER:PASS@127.0.0.1/server-status?auto
14
env.apuser user_runnin_apache
15
env.binname apache_binary_name
16

  
17
=head1 AUTHOR
18

  
19
Ricardo Fraile <rfrail3@yahoo.es>
20

  
21
=head1 LICENSE
22

  
23
GPLv2
24

  
25
=head1 MAGICK MARKERS
26

  
27
 #%# family=auto
28
 #%# capabilities=autoconf
29

  
30
=cut
31

  
32
. $MUNIN_LIBDIR/plugins/plugin.sh
33

  
34
USR=$apuser
35
PROCS=$binname
36

  
37
if [ "$1" = "autoconf" ]; then
38
	echo yes 
39
	exit 0
40
fi
41

  
42
if [ "$1" = "config" ]; then
43

  
44
	echo 'graph_title Number of apache servers running.'
45
	echo 'graph_args --base 1000 -l 0 '
46
	echo 'graph_vlabel servers'
47
	echo 'graph_scale no'
48
	echo 'graph_category apache'
49
	echo 'graph_info Indicate the number of apache servers running (child process).'
50

  
51

  
52

  
53
        echo "servers.label servers"
54
        echo "servers.type GAUGE"
55
        echo "servers.min 0"
56
        echo "servers.info I/O on nfs"
57

  
58
	exit 0
59
fi
60

  
61
VAL1=`ps auxf | grep ${PROCS} | grep ${USR} | grep -v grep | wc -l`
62

  
63
echo "servers.value $VAL1"
64

  
65

  
plugins/apache/apache_threads
1
#!/bin/sh
2
# -*- sh -*-
3

  
4
: << =cut
5

  
6
=head1 NAME
7

  
8
apache_threads -Indicate the memdium number of threads for all child process
9

  
10
=head1 CONFIGURATION
11

  
12
[apache_*]
13
env.url http://USER:PASS@127.0.0.1/server-status?auto
14
env.apuser user_runnin_apache
15
env.binname apache_binary_name
16

  
17
=head1 AUTHOR
18

  
19
Ricardo Fraile <rfrail3@yahoo.es>
20

  
21
=head1 LICENSE
22

  
23
GPLv2
24

  
25
=head1 MAGICK MARKERS
26

  
27
 #%# family=auto
28
 #%# capabilities=autoconf
29

  
30
=cut
31

  
32
. $MUNIN_LIBDIR/plugins/plugin.sh
33

  
34

  
35
if [ "$1" = "autoconf" ]; then
36
	echo yes 
37
	exit 0
38
fi
39

  
40
if [ "$1" = "config" ]; then
41

  
42
	echo 'graph_title Medium number of threads for child process.'
43
	echo 'graph_args --base 1000 -l 0 '
44
	echo 'graph_vlabel Threads'
45
	echo 'graph_scale no'
46
	echo 'graph_category apache'
47
	echo 'graph_info Indicate the memdium number of threads for all child process.'
48

  
49

  
50

  
51
        echo "threads.label threads"
52
        echo "threads.type GAUGE"
53
        echo "threads.min 0"
54

  
55
	exit 0
56
fi
57

  
58
SUM=0
59
COUNT=0
60
USR=$apuser
61
PROCS=$binname
62

  
63

  
64
# Catch proccess pid
65
VAL1=`ps auxf | grep ${PROCS} | grep ${USR} | grep -v grep | awk '{print $2}' `
66

  
67
# Count pids
68
COUNT=`ps auxf | grep ${PROCS} | grep ${USR} | grep -v grep | wc -l`
69

  
70
# Read threads per pid
71
for i in $VAL1; do
72

  
73
        VAL2="$VAL2 `cat /proc/$i/status | grep 'Threads:' | awk '{print $2}'`"
74
done
75

  
76
# Sun threads
77
for z in ${VAL2}; do
78

  
79
        SUM=`expr $SUM + $z`
80

  
81
done
82

  
83

  
84
echo "threads.value `echo $((SUM /  $COUNT))`"
85

  
86

  
87

  
88
	
89

  
plugins/apache/apache_tmemmory
1
#!/bin/sh
2
# -*- sh -*-
3

  
4
: << =cut
5

  
6
=head1 NAME
7

  
8
apache_tmemmory -Indicate the total memory used by apache
9

  
10
=head1 CONFIGURATION
11

  
12
[apache_*]
13
env.url http://USER:PASS@127.0.0.1/server-status?auto
14
env.binname apache_binary_name
15

  
16
=head1 AUTHOR
17

  
18
Ricardo Fraile <rfrail3@yahoo.es>
19

  
20
=head1 LICENSE
21

  
22
GPLv2
23

  
24
=head1 MAGICK MARKERS
25

  
26
 #%# family=auto
27
 #%# capabilities=autoconf
28

  
29
=cut
30

  
31
. $MUNIN_LIBDIR/plugins/plugin.sh
32

  
33

  
34
USR=$apuser
35
PROCS=$binname
36

  
37

  
38
if [ "$1" = "autoconf" ]; then
39
	echo yes 
40
	exit 0
41
fi
42

  
43
if [ "$1" = "config" ]; then
44

  
45
	echo 'graph_title Total memory used by apache'
46
	echo 'graph_args --base 1000 -l 0 '
47
	echo 'graph_vlabel Mb'
48
	echo 'graph_scale no'
49
	echo 'graph_category apache'
50
	echo 'graph_info Indicate the total memory used by apache.'
51

  
52
        echo "servers.label servers"
53
        echo "servers.type GAUGE"
54
        echo "servers.min 0"
55

  
56
	exit 0
57
fi
58

  
59
VAL1=`ps auxf | grep ${PROCS} | grep -v grep | awk '{s+=$6} END {print s}'`
60

  
61
VAL2=`expr $VAL1 / 1024`
62

  
63
echo "servers.value $VAL2"
64
	
65

  

Formats disponibles : Unified diff