How to get apache server status variables by shell script

Posted on 2009-07-07
Last Modified: 2013-12-26
i am woundering, if any one can help me or give some good article about:

how to get apache server status variable by shell scripting ..

what i meant is : if you  open your , it will give you this kind of info

Current Time: Tuesday, 07-Jul-2009 13:03:16 BST
Restart Time: Sunday, 05-Jul-2009 04:02:03 BST
Parent Server Generation: 1
Server uptime: 2 days 9 hours 1 minute 13 seconds
Total accesses: 1578 - Total Traffic: 5.3 MB
CPU Usage: u13.52 s2.25 cu11.38 cs0 - .0132% CPU load
.00769 requests/sec - 26 B/second - 3504 B/request
1 requests currently being processed, 13 idle workers

Where apache is storing those information, how you can get those value in to a varibles ?? is there any command to get those value ?? example, uptime [ will show you how many days linux server is runing.. load averages .. etc ]  ,
mainly these :
Server uptime: 2 days 9 hours 1 minute 13 seconds
Total accesses: 1578 - Total Traffic: 5.3 MB
.00769 requests/sec - 26 B/second - 3504 B/request
1 requests currently being processed, 13 idle workers

Question by:fosiul01
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 40

Expert Comment

ID: 24793583
did you try to use

wget  > status.txt

cat status.txt | myscript

myscript contains

read line1
read line2
read line3
read line4
read line5
LVL 29

Author Comment

ID: 24793661
hmm , i know what you meant, i just realized from this 2 website

but , without wget

is not there any other way to use ???

i understand, mod_status, will provide those information ...

but can you not get those value directory to script without accessing to server_status
LVL 68

Expert Comment

ID: 24793663
To get content only  (no HTML), try 'lynx'
lynx -nolist -dump  > output.txt

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

LVL 68

Expert Comment

ID: 24793690
OK, now I see your requirement!
apachectl status
apachectl fullstatus
LVL 29

Author Comment

ID: 24793700

 thanks lynx is better then wget or links command ... its gettign the exact valuE!

but still, my question is, withotu accessing server-status, can you not get those value ??

becaues if i try to get those value form server-status, i need to extract line by line ...

if you guys look to this link

there is a picture, its a python programm, but can you create same output via shell script ?? or you need something liek C or pyton ??

LVL 29

Author Comment

ID: 24793973
Ok apachectl fullstatus + some script example  (

might do the job

so, if you guys think that,

server-status or apachectl fullstatus + script  is the only solution to get those values then i will happy to close this question..

is that the only way ??
LVL 16

Expert Comment

ID: 24794098
Are you talking about these?
LVL 68

Expert Comment

ID: 24794169

Of course you can run 'uptime' to get some info, but the other values need to be calculated by apache
(to avoid e.g. excessive logfile analyzing by means of a homemade script),
and afaik they're not stored anywhere in the filesystem.
What exactly are you trying to do with those values?
If it's only for displaying, just use apachectl or lynx without the '-dump' option.
If, however, you're going to work with the values (calculating/storing etc.) you will need to extract them from
the output of a tool like the above - I'm not aware of a better solution.

LVL 29

Author Comment

ID: 24794210

ok suppose if you want to take a mysql status report , you can get those from variables,

right ??

suppose in mysql, if you want to get if you want to get how many thread is runing  you can get the variables like this

Slave_IO_Running=`mysql -Bse "show status\G" | grep Threads_running  | awk '{ print $2 }'`

is not it ???

so what i am asking is,
is there any way to get each data from a apache variable ??

suppose this line

1 requests currently being processed, 7 idle workers

so i want to know, how many request is there,  
its currently 1

now can i get this 1 from any sort of apache variable ??

[ i know if you  use scripting with awk you would be able to get that variable by , may be hard way but you would be ]

my question is, can you get those data from apache variable or not ...
LVL 29

Author Comment

ID: 24794229
also add to my previous  post:

"1 requests currently being processed, 7 idle workers"

suppose if idle worker is low, server will be hang is not it ??

so if i want a script when idle worker will low it will sent me an email ....

LVL 68

Accepted Solution

woolmilkporc earned 500 total points
ID: 24794639
There is a "machine-readable" version of the status page in ...../server-status?auto ,
and there is a perl script in apache's ...src/support subdirectory called "log_server_status" which will reformat the above data into one single line.
You probably don't need to go the "hard way" to parse this line (sorry, I can't test at the moment), but not without things like 'awk' or the like.
As for apache variables (quoting apache docs) -
Although these variables are referred to as environment variables, they are not the same as the environment variables controlled by the underlying operating system. Instead, these variables are stored and manipulated in an internal Apache structure. They only become actual operating system environment variables when they are provided to CGI scripts and Server Side Include scripts.
Again, I'm not aware of  a better way to let you achieve what you want.
Although you don't want to use 'awk', here is a tiny example using normal lynx output -
# server to check
# idle workers low theshold
iw_low=5 # or whatever
iw=$(lynx -nolist -dump http://${server}/server-status | grep "idle workers" |awk '{print $6}')
[ $iw -lt $iw_low ] && echo "Idle workers $iw is below threshold of $iw_low on $server" | mailx -s "Apache Alert" fosiul01@hisdomain.tld  
In case you plan to have this run by cron you will need sort of a "locking" mechanism to avoid receiving tons of mails once the value gets below threshold.
LVL 29

Author Comment

ID: 24794707
i guess you are taking about this one is not it, perl script

ok thanks for your help , i will take it further from here
i just wanted to get some idea..

just one question i will ask you, you do not have to explain to me to much ...

how do you monitor apache performace ??

any software ?? paid or free??

LVL 68

Expert Comment

ID: 24794867
Simple answer - nagios!
Issue a standard http request regularly using check_http and measure response time.
Other http/apache parameters available by check_apache 
Good luck!
LVL 29

Author Comment

ID: 24794977
you know what the last link is really really good!!

thanks again...
LVL 29

Author Closing Comment

ID: 31600554

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension ( This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question