Refine your search:

Has anyone tried to have splunk parse the output of the machine readable apache server-status page, e.g http://$apachehost/server-status?auto

I need to keep track of the status of workers, whether they are waiting, logging, etc.

Thanks

asked 25 Jul '11, 08:46

mhouts001's gravatar image

mhouts001
112
accept rate: 0%


2 Answers:

I use a scripted input - I wrote a perl script to make a call to the Apache servers to pull stats..

I'll include the code below to get you started:

#!/usr/bin/perl

###
#Simple script to parse Apache Server statistics for Splunk
###

use LWP::UserAgent;

@apache_urls=("http://server1/server-status","http://server2/server-status","http://server3/server-status","http://server4/server-status");

foreach $url (@apache_urls) {
        my $ua = new LWP::UserAgent;
        $ua->agent('Splunk Apache Statistics Script');
        my $request = HTTP::Request->new('GET');
        $request->url($url);
        my $response = $ua->request($request);
        my $body = $response->content;

        ### Extract stats
        $body=~ m/Apache Server Status for ([^>]+)<\/h1>/;
        $server_name=$1;
        $body=~ m/Current Time: [^,]+, ([^<]+)<\/dt>/;
        $timestamp=$1;
        $body=~ m/<dt>([^\s]+) requests\/sec - ([^\s]+) kB\/second - ([^\s]+) kB\/request<\/dt>/;
        $request_stats="requests_per_second=$1,kB_per_second=$2,kB_per_request=$3";
        $body=~ m/<dt> ([^\s]+) requests currently being processed, ([^\s]+) idle workers<\/dt>/;
        $processing_stats="requests_currently_being_processed=$1,idle_workers=$2";
        print "$timestamp,ServerName=$server_name,$request_stats,$processing_stats \n";
}
link

answered 25 Jul '11, 09:14

Brian%20Osburn's gravatar image

Brian Osburn
2.8k13
accept rate: 22%

edited 25 Jul '11, 09:16

Outstanding, thank you. Figured this was the direction to take if there was no direct read of the status page.

(25 Jul '11, 14:01) mhouts001

Please accept the answer if it solves your issue.

Thanks!

(26 Jul '11, 10:22) Brian Osburn

Hi,

I fixed a few typos and extended the script to work on lower-traffic servers and to provide CPU usage:

#!/usr/bin/perl

###
#Simple script to parse Apache Server statistics for Splunk
###

use LWP::UserAgent;

@apache_urls=("http://server1/server-status","http://server2/server-status");

foreach $url (@apache_urls) {
        my $ua = new LWP::UserAgent;
        $ua->agent('Splunk Apache Statistics Script');
        my $request = HTTP::Request->new('GET');
        $request->url($url);
        my $response = $ua->request($request);
        my $body = $response->content;

        ### Extract stats
        $body=~ m/Apache Server Status for ([^>]+)<\\/h1>/;
        $server_name=$1;
        $body=~ m/Current Time: [^,]+, ([^<]+)<\\/dt>/;
        $timestamp=$1;
        $body=~ m/<dt>([^\\s]+) requests\\/sec - ([^\\s]+) (k*B)\\/second - ([^\\s]+) (k*B)\\/request<\\/dt>/;
        $request_stats="requests_per_second=$1,$3_per_second=$2,$5_per_request=$4";
        $body=~ m/<dt>([^\\s]+) requests currently being processed, ([^\\s]+) idle workers<\\/dt>/;
        $processing_stats="requests_currently_being_processed=$1,idle_workers=$2";
        $body=~ m/<dt>CPU Usage: u([^\\s]+) s([^\\s]+) cu.* cs.* - ([^\\s]+%) CPU load<\\/dt>/;
        $cpu_stats="user_cpu=$1,system_cpu=$2,cpu_load=$3";
        print "$timestamp,ServerName=$server_name,$request_stats,$processing_stats,$cpu_stats \\n";
}
link

answered 02 Aug '11, 08:58

LK's gravatar image

LK
101
accept rate: 0%

edited 03 Aug '11, 10:49

piebob's gravatar image

piebob ♦♦
2.4k1516

Not sure why all the backslashes doubled themselves. Please be sure to correct that before using the script.

(02 Aug '11, 15:11) LK
Post your answer
toggle preview

Follow this question

Log In to enable email subscriptions

RSS:

Answers

Answers + Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×37
×1

Asked: 25 Jul '11, 08:46

Seen: 1,021 times

Last updated: 03 Aug '11, 10:49

Copyright © 2005-2012 Splunk, Inc. All rights reserved.