[XML] ApacheStats version 0.2

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Rolf Poser
Posts: 42
Joined: Wed Dec 10, 2003 7:19 am

Alan - just checking a few more items

Post by Rolf Poser »

Alan:

Are you running it against the localhost?

Either way, can you check whether the request for /server-status is actually showing up in any of the web server logs on the apache server's end?

If yes, then I'm a bit stumped !

Will have to get back to you if your web server sees the request....

Thanks,
Rolf.
alanyoung1979
Posts: 13
Joined: Mon May 03, 2004 5:26 pm

Post by alanyoung1979 »

Rolf,

The machine that I am running the apache script on, is the machine that i am targeting with the the script.

i.e. uniquehost.foobar.com runs the following command succesfully:

Code: Select all

perl unix_apachestats.pl  uniquehost.foobar.com
apache_total_hits:4536 apache_total_kbytes:17448 apache_busy_workers:17448 apache_idle_workers:17448
Here is the relevant apache log:

Code: Select all

uniquehost.foobar.com - - [18/May/2004:10:12:42 -0700] "GET /server-status?auto HTTP/1.0" 200 432 "-" "Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6b"
however it fails (returns no values) when uniquehost.foobar.com runs the following command:

Code: Select all

perl unix_apachestats.pl  localhost
or
perl unix_apachestats.pl  127.0.0.1
both return
apache_total_hits: apache_total_kbytes: apache_busy_workers: apache_idle_workers:
From my desktop to the server running Cacti there is no proxy. And there is no squid proxy runnning on the machine uniquehost.foobar.com.

Thanks,

Alan
Rolf Poser
Posts: 42
Joined: Wed Dec 10, 2003 7:19 am

Check httpd.conf?

Post by Rolf Poser »

Alan:

Quick question:

Does the logfile entry show up when you access it as localhost as well as unique.foobar.com - sorry for being so laborious about this?

Also - could you check what your permissions are set to in httpd.conf in terms of access to the server-status?

I've set mine to the following:

<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from .foobar.com 127.0.0.1
</Location>

which should ensure that other hosts in my domain can query it, as well as a localhost query?

Another way to try to resolve this perhaps is to check that the "data source" under which the apache monitor is defined is pointing to the right hostname..

Let me know what further information you can garner for me?

Thanks,
Rolf.
alanyoung1979
Posts: 13
Joined: Mon May 03, 2004 5:26 pm

httpd.conf

Post by alanyoung1979 »

Rolf,

No problem it's my pleasure!

When I do this:

Code: Select all

perl /var/www/html/cacti/scripts/unix_apachestats.pl 127.0.0.1
perl /var/www/html/cacti/scripts/unix_apachestats.pl locahost
I get get no data, but I see entries in my httpd access_log:

Code: Select all

localhost.localdomain - - [18/May/2004:13:04:42 -0700] "GET /server-status?auto HTTP/1.0" 403 292 "-" "Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6b"
localhost.localdomain - - [18/May/2004:13:04:50 -0700] "GET /server-status?auto HTTP/1.0" 403 292 "-" "Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6b"
Here is the relevant part of my httpd.conf file:

Code: Select all

<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from .foobar.com 
</Location>
I imagine the reason why it doesn't work from localhost is that I haven't allowed it my httpd.conf file.

Alan
Guest

Post by Guest »

pbulteel wrote:I redid the code so it's completely written in perl. It requires LWP which should be already installed. Thanks for the original script and the modification! And although I didn't put it in there... it's GPL of course!

Code: Select all

#!/usr/bin/perl -w
#
# Taken from ftp://ftp.ora.com/published/oreilly/nutshell/web-client/ 
# 
# Modified by: Patrick Bulteel
# Date: 02/16/2004 - (I love you hunny! It's my anniversary!)
#
# Modified so that it uses perl more extensively instead of running lynx.
# Also modified so that it uses a wildcard for Busy and Idle servers instead
# of having to hit the server twice, we can do it all in one swell swoop.
#

use strict;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;

my $ua = new LWP::UserAgent;
# I added this to the original O'reilly code...
my $fullurl = "http://" . $ARGV[0] . "/server-status?auto";

# I changed this from the original O'reilly code...
my $request = new HTTP::Request('GET', $fullurl);
my $response = $ua->request($request);
if ($response->is_success) {
    # I grabbed this from the original unix_apachestats.pl
     $response->content =~ /Total Accesses: (.*)/; 
    print "apache_total_hits:".$1." "; 
    $response->content =~ /Total kBytes: (.*)/; 
    print "apache_total_kbytes:".$1." ";
    # I wildcarded the Busy and Idle stats... =)
    $response->content =~ /Busy.*: (.*)/;
    print "apache_busy_workers:".$1." ";
    $response->content =~ /Idle.*: (.*)/;
    print "apache_idle_workers:".$1;
} else {
     print $response->error_as_HTML;
}
Running the script i get the following on cosnole:

Code: Select all

# perl /home/htdocs/web1/html/cacti/scripts/unix_apachestats.pl localhost

Use of uninitialized value in concatenation (.) or string at /home/htdocs/web1/html/cacti/scripts/unix_apachestats.pl line 28.
Use of uninitialized value in concatenation (.) or string at /home/htdocs/web1/html/cacti/scripts/unix_apachestats.pl line 30.
Use of uninitialized value in concatenation (.) or string at /home/htdocs/web1/html/cacti/scripts/unix_apachestats.pl line 33.
Use of uninitialized value in concatenation (.) or string at /home/htdocs/web1/html/cacti/scripts/unix_apachestats.pl line 35.

apache_total_hits: apache_total_kbytes: apache_busy_workers: apache_idle_workers:p1000:/srv/www/htdocs #
Guest

Post by Guest »

Above posting - solved !

Was a config mistake in apache2 - mod_status.conf

Set handler and localhost --> OK :)
testtest
Posts: 25
Joined: Mon May 17, 2004 7:19 am
Location: Europe

Post by testtest »

Hello Cacti folks :D

The graphs did not work after importing templates.

On console it worked with both .pl scripts - original + 'pure perl' script with 'parameter' localhost.

So i did simply that:

Data Templates --> Unix - Apache2 Statistics --> Custom Data [data input: Unix - Apache Statistics] --> Host to be queried for "/server-status?auto" --> right field : inserted 'localhost' --> Save -FUN :lol:
[url=http://stef.funpic.de/index.html]Stef.s small Fan Page[/url]
Free your brain with trashing away MS - no pain, no torture, no troubles of learning Linux can compete with your Freedom using it.
Rolf Poser
Posts: 42
Joined: Wed Dec 10, 2003 7:19 am

Localhost and permissions:

Post by Rolf Poser »

Alan:

I think I can see what's wrong here - it seems to substitue either nothing or "localhost" and your httpd.conf doesn't allow for that.

To make it work, I would suggest adding "localhost" to your permissions i.e. "Allow .foobar.com [b]localhost[/b]".

That's a temporary fix though, I'll need to go and figure out why the script isn't passed the correct parameter!

Hope this works for you, if you don't want to use the "localhost" option let me know so that I speed up my investigation.

Thanks,
Rolf.
Rolf Poser
Posts: 42
Joined: Wed Dec 10, 2003 7:19 am

In response to Alan's questions:

Post by Rolf Poser »

Sorry that should read:

Allow .foobar.com localhost


Let me know if it works.

Thanks,
Rolf.
testtest
Posts: 25
Joined: Mon May 17, 2004 7:19 am
Location: Europe

Re: In response to Alan's questions:

Post by testtest »

Rolf Poser wrote:Sorry that should read:

Allow .foobar.com localhost


Let me know if it works.

Thanks,
Rolf.
:oops: Rolf, just for your info - see my above posting - had a similar prob, because i defined "Allow from .servernet.com" and NOT additionally / only "localhost" , too.
After changing it towards "Allow from localhost" + changed the Data Template value towards "localhost" all is working perfect !! :)
[url=http://stef.funpic.de/index.html]Stef.s small Fan Page[/url]
Free your brain with trashing away MS - no pain, no torture, no troubles of learning Linux can compete with your Freedom using it.
Rolf Poser
Posts: 42
Joined: Wed Dec 10, 2003 7:19 am

Apache config stuff.... Hmm

Post by Rolf Poser »

testest:

Thanks for pointing that out.

I thought I understood apache config directives.

Back to RTFM then!

Let's see the documentation then...

OK - having taken a look, my fears are being confirmed - you need to
enable access line-by-line if you want to enable access from more than one place, i.e.:

Allow from localhost
Allow from foobar.com

I don't have any means to test this right now, so if you don't mind confirming this for us? Otherwise I'll try at home tonight.

Thanks,
Rolf.
alanyoung1979
Posts: 13
Joined: Mon May 03, 2004 5:26 pm

httpd.conf changes

Post by alanyoung1979 »

I changed my httpd.conf file to:

Code: Select all

<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from localhost
    Allow from .foobar.com
</Location>
However, when I run the script via localhost or 127.0.0.1 I get no results. When I run the command with the localhost's hostname I get results.

Anyways, when cacti trys to generate the graph it uses the hostname of the server, and doesn't get any data points, even though when I run the same command manually it returns data points. Also I would be using cacti to measure webserver stats for other hosts than the cacti server. I.e my company's www servers.

Hope this helps,

Alan
Rolf Poser
Posts: 42
Joined: Wed Dec 10, 2003 7:19 am

Grrr... Let's see whether this works:

Post by Rolf Poser »

Alan:

I've found that it seems to have much less to do with whether the allow clauses are on separate lines (they actually can be), but that the

<Location /server-status> directory will match only for queries to whatever your ServerName is set to. So that may explain why it works for testtest and not for us.

I've come up with an interesting alternative that I'd like you to try out.

Add the following:

<VirtualHost localhost>
ServerAlias 127.0.0.1
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
</VirtualHost>

Also - what are your "Listen" and "ServerName" settings?

Thanks,
Rolf.
alanyoung1979
Posts: 13
Joined: Mon May 03, 2004 5:26 pm

It works!

Post by alanyoung1979 »

Rolf,

My "Listen" settings are all commented out.
My "Servername" setting is commented out.

I added:
<VirtualHost localhost>
ServerAlias 127.0.0.1

<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
</VirtualHost>
and upgraded to apachestats 0.4 and how my graphs work (at least when I mesaure the machine that cacti runs on) ! I used the "high speed" version as other version you have provided use a module I don't have installed.

Thanks for all the help.

Alan
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests