PluginCat: apache_volume

File apache_volume, 5.2 kB (added by fra519@fra519.no-ip.org, 6 years ago)

Modified Apache volume for Apache and Apache SSL in same graph see plugin for env variable

Line 
1 #!/usr/bin/perl
2 #
3 # Plugin to monitor the volume of data sent from Apache servers. It handles
4 # a list of ports passed in from a plugin configuration file.
5 #
6 # Requirements:
7 #       - Needs access to http://localhost/server-status?auto (or modify the
8 #         address for another host). See your apache documentation on how to
9 #         set up this url in your httpd.conf. Apache needs ExtendedStatus
10 #         enabled for this plugin to work.
11 #
12 # Tip: To see if it's already set up correctly, just run this plugin
13 # with the parameter "autoconf". If you get a "yes", everything should
14 # work like a charm already.
15 #
16 # Parameters supported:
17 #
18 #       config
19 #       autoconf
20 #
21 # Configurable variables
22 #
23 #       url      - Override default status-url
24 #       port     - HTTP port numbers
25 #
26 #       ssl      - activate SSL (add env.ssl yes in munin plugin configuration)
27 #       urls     - Override default status-url (SSL)
28 #       ports    - HTTP port numbers (SSL)
29 #
30 # $Log$
31 # Revision 1.13  2006/03/07 20:30:00  fra519
32 # adapt script for Apache-SSL Server.
33 #
34 # Revision 1.12  2004/12/10 18:51:43  jimmyo
35 # linux/apt* has been forced to LANG=C, to get predictable output.
36 #
37 # Revision 1.11  2004/12/10 10:47:47  jimmyo
38 # Change name from ${scale} to ${graph_period}, to be more consistent.
39 #
40 # Revision 1.10  2004/12/09 22:12:54  jimmyo
41 # Added "graph_period" option, to make "graph_sums" usable.
42 #
43 # Revision 1.9  2004/09/26 22:14:39  jimmyo
44 # Changd COUNTER -> DERIVE for some plugins. Set min/max values.
45 #
46 # Revision 1.8  2004/05/20 13:57:12  jimmyo
47 # Set categories to some of the plugins.
48 #
49 # Revision 1.7  2004/05/14 21:16:46  jimmyo
50 # "Upped" som plugins from contrib/manual to auto.
51 #
52 # Revision 1.6  2004/04/27 21:32:06  jimmyo
53 # Clarified the vlabels in the apache-plugins (Deb#238594).
54 #
55 # Revision 1.5  2004/04/27 08:46:57  jimmyo
56 # Fixed broken autoconf in apache-* plugins (Deb#236144).
57 #
58 # Revision 1.4  2004/02/18 15:47:35  jimmyo
59 # The generic/apache_* plugins now have defined max values.
60 #
61 # Revision 1.3  2004/02/03 17:17:25  jimmyo
62 # Generic/apache-plugins have been modified to properly to report the correct autoconf value. Also, bugfixes in _processes and _volume.
63 #
64 # Revision 1.2  2004/01/29 18:47:30  jimmyo
65 # Made plugins apache_* compatible with older versions of LWP::UserAgent (SF#881411).
66 #
67 # Revision 1.1  2004/01/02 18:50:00  jimmyo
68 # Renamed occurrances of lrrd -> munin
69 #
70 # Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
71 # Import of LRRD CVS tree after renaming to Munin
72 #
73 # Revision 1.4  2003/12/18 16:35:33  jimmyo
74 # fail more gracefully when using uninstalled perl modules.
75 #
76 # Revision 1.3  2003/11/07 17:43:16  jimmyo
77 # Cleanups and log entries
78 #
79 #
80 #
81 # Magic markers:
82 #%# family=auto
83 #%# capabilities=autoconf
84
85 my $ret = undef;
86 my $ssl = undef;
87
88 if (! eval "require LWP::UserAgent;")
89 {
90         $ret = "LWP::UserAgent not found";
91 }
92 if (! eval "require Crypt::SSLeay;" and exists $ENV{'ssl'})
93 {
94         $ret = "Crypt::SSLeay not found";
95 }
96
97 my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/server-status?auto";
98 my @PORT = exists $ENV{'port'} ? split(' ', $ENV{'port'}) : (80);
99
100 my $URLS = exists $ENV{'urls'} ? $ENV{'urls'} : "https://127.0.0.1:%d/server-status?auto";
101 my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (443);
102
103 if ( exists $ARGV[0] and $ARGV[0] eq "autoconf" )
104 {
105         if ($ret)
106         {
107                 print "no ($ret)\n";
108                 exit 1;
109         }
110        
111         if ($ssl) {
112                 print "no ($ssl)\n";
113                 exit 1;
114         }
115
116         my $ua = LWP::UserAgent->new(timeout => 30);
117
118         my @badports;
119         foreach my $port (@PORT) {
120                 my $url = sprintf $URL, $port;
121                 my $response = $ua->request(HTTP::Request->new('GET',$url));
122                 push @badports, $port unless $response->is_success and $response->content =~ /^Total Accesses:/im;
123         }
124         if (exists $ENV{'ssl'}) {
125                 foreach my $port (@PORTS) {
126                         my $url = sprintf $URLS, $port;
127                         my $response = $ua->request(HTTP::Request->new('GET',$url));
128                         push @badports, $port unless $response->is_success and $response->content =~ /^Total Accesses:/im;
129                 }
130         }
131        
132         if (@badports) {
133                 print "no (no apache server-status or ExtendedStatus missing on ports @badports)\n";
134                 exit 1;
135         } else {
136                 print "yes\n";
137                 exit 0;
138         }
139 }
140
141 if ( exists $ARGV[0] and $ARGV[0] eq "config" )
142 {
143         print "graph_title Apache volume\n";
144         print "graph_args --base 1000\n";
145         print "graph_vlabel bytes per \${graph_period}\n";
146         print "graph_category apache\n";
147         foreach my $port (@PORT) {
148                 print "volume$port.label port $port\n";
149                 print "volume$port.type DERIVE\n";
150                 print "volume$port.max 1000000000\n";
151                 print "volume$port.min 0\n";
152         }
153         if (exists $ENV{'ssl'}) {
154                 foreach my $port (@PORTS) {
155                         print "volume$port.label port $port\n";
156                         print "volume$port.type DERIVE\n";
157                         print "volume$port.max 1000000000\n";
158                         print "volume$port.min 0\n";
159                 }
160         }
161         exit 0;
162 }
163
164 my $ua = LWP::UserAgent->new(timeout => 30);
165
166 foreach my $port (@PORT) {
167         my $url = sprintf $URL, $port;
168         my $response = $ua->request(HTTP::Request->new('GET',$url));
169         if ($response->content =~ /^Total kBytes:\s+(.+)$/im) {
170                 print "volume$port.value ", ($1*1024), "\n";
171         } else {
172                 print "volume$port.value U\n";
173         }
174 }
175 if (exists $ENV{'ssl'}) {
176         foreach my $port (@PORTS) {
177                 my $url = sprintf $URLS, $port;
178                 my $response = $ua->request(HTTP::Request->new('GET',$url));
179                 if ($response->content =~ /^Total kBytes:\s+(.+)$/im) {
180                         print "volume$port.value ", ($1*1024), "\n";
181                 } else {
182                         print "volume$port.value U\n";
183                 }
184         }
185 }
186 # vim:syntax=perl