Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Red Hat / CentOS / Fedora – Splunk – PERL – Apache Server Status

Posted on April 2, 2021August 17, 2024 By David Kittell

Guide Followed: https://community.splunk.com/t5/Getting-Data-In/Reading-Apache-server-status-output/m-p/48158

First make sure your Apache server-status is setup (assuming you already have Apache/httpd installed)

# Create apache_exporter user
sudo useradd apache_exporter -s /sbin/nologin
 
# Create Apache Location
declare apache_exporter=$(cat <<EOF
ExtendedStatus on
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Location>
EOF
)
echo "$apache_exporter"
echo -e "$apache_exporter"|sudo tee /etc/httpd/conf.d/server-status.conf
 
# Restart Apache
sudo systemctl restart httpd
 
# Validate Page
curl http://127.0.0.1/server-status

# Validate Scrape-Able Page
curl http://127.0.0.1/server-status?auto

PERL script for scraping the data for SPLUNK

#!/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");
# @apache_urls=("http://127.0.0.1/server-status");
@apache_urls = $ARGV[0];

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>/;
        $body=~ m/<dt>([^\s]+) requests\/sec - ([^\s]+) (k*B)\/second - ([^\s]+) ([k,M]*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";
}

Example:

perl Splunk-Apache_Server-Status.pl "http://127.0.0.1/server-status"
02-Apr-2021 08:56:36 EDT,ServerName=127.0.0.1 (via 127.0.0.1),requests_per_second=02-Apr-2021 08:56:36 EDT,_per_second=,_per_request=,requests_currently_being_processed=1,idle_workers=74,user_cpu=.22,system_cpu=.45,cpu_load=.0333%
Originally Posted on April 2, 2021
Last Updated on August 17, 2024
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

CentOS Code Fedora PERL Red Hat Splunk UNIX UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

Unix Shell – Set/Change IP

Posted on October 19, 2015October 19, 2015

By default UNIX computers/servers are setup with a DHCP/Dynamic IP address, below is how to change the IP to static Before you do either process understand what these settings should be: Network Interace you plan to modify (eth0, eth1, etc.) IP Address (address) Subnet Mask (netmask) Default Gateway (gateway) Whether…

Read More

BASH – Find all files with tab in the text

Posted on October 19, 2021August 17, 2024

grep -rnw . -e ‘\t’ // -r or -R is recursive, // -n is line number, and // -w stands for match the whole word. // -l (lower-case L) can be added to just give the file name of matching files. // -e is the pattern used during the search…

Read More

HEX to RGB

Posted on August 15, 2013October 26, 2015

function html2rgb($color) { if ($color[0] == ‘#’) $color = substr($color, 1); if (strlen($color) == 6) list($r, $g, $b) = array($color[0].$color[1], $color[2].$color[3], $color[4].$color[5]); elseif (strlen($color) == 3) list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]); else return false; $r = hexdec($r); $g = hexdec($g); $b = hexdec($b); return array($r, $g, $b); }…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes