Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can I setup my apache2 (on Ubuntu 12.04) so that a shell script can easily determine how long the web server was idle? By "idle", I mean "has not served any requests". As this is an internal development server and not a public website, this is very likely to occur in the evenings.

I thought of querying the modification date of the access log, but I don't want to fill the disk with (otherwise unnecessary) logging if I don't have to. Is there another, more elegant way?

Background: This is an Amazon EC2 machine for which I'm paying by the hour, so I want to keep it running only while it is actively used. Note that I already have taken care of scheduling automatic machine startup and an "emergency" button to have it start "right now".

share|improve this question
    
"but I don't want to fill the disk with (otherwise unnecessary) logging" so you are saying that you are not logging web server access at all? –  lacrosse1991 Feb 4 '13 at 15:37
    
have a look at the apache scoreboard (mod_status) –  fuero Feb 4 '13 at 15:41
    
"I want to keep it running only while it is actively used" - it's simple enough to check the mtime on the access log - why do you think this will fill up the disk? But while it's possible to do that, and to shutdown the server iafter some threshold - how do you turn it back on again? –  symcbean Feb 4 '13 at 15:44
    
unless your generating millions of requests an hour, there is not really any need to worry about access logs taking up large amounts of space on the server. for instance if you have around 50,000 requests in your access logs (using the default apache log format), your talking about 4-6MB of data max –  lacrosse1991 Feb 4 '13 at 15:52
    
@lacrosse1991: yes, right now server access is not logged at all. You should probably turn your second comment into an answer to make it easier to find. –  Jens Bannmann Feb 5 '13 at 9:53

1 Answer 1

Have a look at the apache scoreboard (mod_status), you can use it to detect activity.

Here's an example:

# wget -q -O - "http://127.0.0.1/server-status?auto"
Total Accesses: 228059
Total kBytes: 55901
CPULoad: 2.0271
Uptime: 202098
ReqPerSec: 1.12846
BytesPerSec: 283.242
BytesPerReq: 250.999
BusyWorkers: 1
IdleWorkers: 19
Scoreboard: ..__.___..W___............___...._..._...._..._.__...__.........................................................................................................................................................................................................

Total Accesses could be used to find out if apache is serving requests.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.