We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How to get apache server status variables by shell script

Medium Priority
3,642 Views
Last Modified: 2013-12-26
HI
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 http://11.22.22.22/server-staus , 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


Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007

Commented:
did you try to use

wget http://11.22.22.22/server-staus  > status.txt

cat status.txt | myscript

myscript contains

read line1
var1=$line1
read line2
var1=$line2
read line3
var1=$line3
read line4
var1=$line4
read line5
var1=$line5
Top Expert 2009

Author

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

http://blog.e-shell.org/categorylist_html?cat_id=15
http://www.commandlinefu.com/commands/view/1018/summarize-apache-extended-server-status-to-show-longest-running-requests

but , without wget http://11.22.22.22/server-staus

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
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
To get content only  (no HTML), try 'lynx'
lynx -nolist -dump http://11.22.22.22/server-staus  > output.txt

CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
OK, now I see your requirement!
Try
apachectl status
or
apachectl fullstatus
wmp
 
Top Expert 2009

Author

Commented:
@woolmilkporc,

 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

http://blog.e-shell.org/categorylist_html?cat_id=15

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 ??



Top Expert 2009

Author

Commented:
Ok apachectl fullstatus + some script example  ( http://www.commandlinefu.com/commands/view/1018/summarize-apache-extended-server-status-to-show-longest-running-requests)

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 ??
Are you talking about these? http://httpd.apache.org/docs/1.3/env.html
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:

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.

wmp
Top Expert 2009

Author

Commented:
hmmm

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

right ??

example
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 ...
Top Expert 2009

Author

Commented:
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 ....


CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Top Expert 2009

Author

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

http://forums.cacti.net/post-52815.html&highlight=

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??

CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
Simple answer - nagios!
Issue a standard http request regularly using check_http and measure response time.
Other http/apache parameters available by check_apache
http://www.matejunkie.com/update-apache-check-plugin-for-nagios/ 
Good luck!
wmp
Top Expert 2009

Author

Commented:
you know what the last link is really really good!!

thanks again...
Top Expert 2009

Author

Commented:
Thanks
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.