How To Find Apache Uptime Using Script

The uptime command in Linux/Unix is used to find out how long the system has been running. Both distributions come with built- in commands to check put server uptime. In Linux, the file '/proc/uptime' contains uptime information, and the file '/var/run/utmp' has all the details about who has logged in the system. However, information in these files is not in a readable or comprehensible form. So, you need to use the following command. Often, a cracker will reboot the machine in order to complete a root kit install so it is important to know when was the last time your server was restarted.

# uptime
21:54:11 up 13 days, 4:29, 1 user, load average: 0.21, 0.21, 0.12

The output above gives information about the current time, system running time (for 13 days), how many users are currently logged in(only one user), and about the load average of the system. So,the output tells you the current time, how long the system has been running since it was booted up, how many user sessions are currently open and the load averages.
The load averages are the average number of processes that were active during the past one, five and fifteen minutes. A process is a running instance of a program.

The number of user sessions currently open can include information about multiple sessions for a single user. For example, if a user logs into a graphical user interface and then also opens two terminals then this would be counted as three user sessions.

There are a couple of ways to check Apache status depending on what your goals are.

The HTTP service monitor is used to check site availability by searching for a string in the HTML returned from a web page.

The apache service status can be monitored as follows:

On Unix platforms the Process Count Check service monitor is used to ensure the correct number of Apache processes are running. Besides up/down time, you may also want to check the "user experience" of the web site.

Apache Monitoring Script

This method involves use of python script that loads mod_status page. It should be run regularly via cron.

[[email protected] ~]# ./bin/ --help

This program gathers data from Apache's built-in status page and sends it to Zabbix. The data is sent via zabbix_sender. Author: Paulson McIntyre (GpMidi) and License: GPLv2


--version show program's version number and exit

-h, --help show this help message and exit

-l URL, --url=URL Override the automatically generated URL with one of your own

-o HOST, --host=HOST Host to connect to. [default: localhost]

-p PORT, --port=PORT Port to connect on. [default: 80]

-r PROTO, --proto=PROTO Protocol to connect on. Can be http or https.[default: http]


-u USER, --user=USER HTTP authentication user to use when connecting.[default: None]

-a PASSWD, --passwd=PASSWD HTTP authentication password to use when connecting. [default: None]

-s SENDERLOC, --sender=SENDERLOC Location to the zabbix_sender executable. [default: /usr/bin/zabbix_sender]

-q ZABBIXPORT, --zabbixport=ZABBIXPORT Zabbix port to connect to. [default: 10051]

-c ZABBIXSOURCE, --zabbixsource=ZABBIXSOURCE Zabbix host to use when sending values. [default: localhost]

Add the following text to user’s crontab:

/usr/bin/python path/ -c -z > /dev/null 2>&1

Now, edit the Apache configuration file as follows:

SetHandler server-status
Allow from # If using a remote host for monitoring replace with its IP.
Order deny,allow
Deny from all

Now, you can restart the Apache server for zero downtime.

Another option to check Apache uptime is to use lynx command:

#lynx --dump abc http://localhost/server-status | more

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.