How To Check Apache Web Server Uptime In Linux

We all know about uptime command purpose in Linux, it is used to check system uptime like, how long the system has been running without reboot and down. If you want to check other service uptime like Apache, MySQL, Sftp, etc, in Linux, how to do?

Each services has their own commands to check the service uptime, also we can check the services uptime using ps command. It will shows when the parent process started (i mean when it’s restarted/start) and how long the service has been running with [HH:MM:SS].

In this tutorial we are going to show you, how to check Apache web server uptime in different method. This is a small geek and most of us aren’t aware that’s why i made it for public.

  • Apache mod_status module
  • ps command

Method-1 : Check Apache web server uptime via mod_status module

The Apache mod_status module allows a server administrator to check apache web server uptime, concurrent connections and server performance with given interval through CLI, also we can access this through web browser with HTML interface.

Apache mod_status will display following useful information about Apache web server.

  • Apache Web server built & version information
  • Web server last restart & uptime information
  • Total number of incoming requests
  • Idle workers
  • Server load & Web server CPU usage
  • Total traffic (Bandwidth usage)
  • Average number of requests per second
  • Average number of bytes per request
  • Number of bytes served per second
  • How many requests currently being processed
  • Details about running process

Install/Enable mod_status module in Apache

By default, mod_status module enabled on Apache. The reports are commented and you can not access it. Just uncomment below code in your Apache config file to enable it.

For RHEL/CentOS/Fedora systems, open /etc/httpd/conf/httpd.conf file and uncomment the below codes.

[For Apache 2.2]
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from all
</Location>

[For Apache 2.4]
<Location "/server-status">
    SetHandler server-status
    Require host localhost
</Location>

For Debian/Ubuntu systems, open /etc/apache2/mods-enabled/status.conf file and uncomment the below codes. Uncomment and change the “192.0.2.0/24” to allow access from other hosts.

<Location "/server-status">
    SetHandler server-status
    Require local
    #Require ip 192.0.2.024
</Location>

Run the following commands based on your distribution to get an Apache uptime. For Debian/Ubuntu systems run the following command.

$ apachectl status
or
$ apache2ctl status
               Apache Server Status for localhost (via 127.0.0.1)
   Server Version: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.21 OpenSSL/1.0.1f
   Server MPM: prefork
   Server Built: Jul 27 2017 15:20:24
     ----------------------------------------------------------------------
   Current Time: Thursday, 24-Aug-2017 15:44:44 MDT
   Restart Time: Friday, 28-Jul-2017 18:16:53 MDT
   Parent Server Config. Generation: 8
   Parent Server MPM Generation: 7
   Server uptime: 26 days 21 hours 27 minutes 51 seconds
   Server load: 0.06 0.06 0.20
   Total accesses: 9889499 - Total Traffic: 93.0 GB
   CPU Usage: u247.11 s23.87 cu0 cs0 - .0117% CPU load
   4.26 requests/sec - 42.0 kB/second - 9.9 kB/request
   5 requests currently being processed, 6 idle workers

 K__W.K.._._.K_W..._.............................................
 ................................................................
 ......................

   Scoreboard Key:
   "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
   "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
   "C" Closing connection, "L" Logging, "G" Gracefully finishing,
   "I" Idle cleanup of worker, "." Open slot with no current process

For RHEL/CentOS/Fedora systems run the following command.

$ apachectl status
or
$ service httpd fullstatus
                       Apache Server Status for localhost
   Server Version: Apache/2.2.15 (Unix) DAV/2 mod_ssl/2.2.15
   OpenSSL/1.0.1e-fips
   Server Built: Jul 26 2017 05:23:12
   --------------------------------------------------------------------------
   Current Time: Friday, 25-Aug-2017 09:02:34 MDT
   Restart Time: Wednesday, 23-Aug-2017 19:28:36 MDT
   Parent Server Generation: 0
   Server uptime: 1 day 13 hours 33 minutes 58 seconds
   1 requests currently being processed, 7 idle workers

 ______W_........................................................
 ................................................................
 ................................................................
 ................................................................

   Scoreboard Key:
   "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
   "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
   "C" Closing connection, "L" Logging, "G" Gracefully finishing,
   "I" Idle cleanup of worker, "." Open slot with no current process

   PID Key:
    4269 in state: _ ,   4270 in state: _ ,   4271 in state: _
    4272 in state: _ ,   4273 in state: _ ,   4274 in state: _
    4275 in state: W ,   4276 in state: _ ,
   --------------------------------------------------------------------------
   To obtain a full report with current status information you need to use
   the ExtendedStatus On directive.
   --------------------------------------------------------------------------
   SSL/TLS Session Cache Status:
   cache type: SHMCB, shared memory: 512000 bytes, current sessions: 0
   subcaches: 32, indexes per subcache: 133
   index usage: 0%, cache usage: 0%
   total sessions stored since starting: 0
   total sessions expired since starting: 0
   total (pre-expiry) sessions scrolled out of the cache: 0
   total retrieves since starting: 0 hit, 0 miss
   total removes since starting: 0 hit, 0 miss
   --------------------------------------------------------------------------
    Apache/2.2.15 (Red Hat) Server at localhost Port 80

Alternatively we can run the command using text-mode browser.

$ elinks http://localhost/server-status

Apache uptime with page refresh every N seconds.

$ elinks http://localhost/server-status?refresh=5

For HTML output via web browser.

For HTML output via web browser with page refresh every N seconds.

Method-2 : Check Apache Web server uptime via PS Command

ps displays information about a selection of the active processes. By default, ps selects all processes with the same effective user ID (euid=EUID) as the current user and associated with the same terminal as the invoker. It displays the process ID (pid=PID), the terminal associated with the process (tname=TTY), the cumulated CPU time in [DD-]hh:mm:ss format (time=TIME), and the executable name (ucmd=CMD).

Run the following command to display the Apache web server last bounced date. Our web server was bounced on Jul28 so it’s up and running 29 days.

Run the following command to display the Apache web server uptime in For RPM based systems. As you can see lots of httpd process but make sure you have to take parent process.

$ ps -aux | grep httpd
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root      2110  0.0  0.0 105372   848 pts/0    S+   09:09   0:00 grep httpd
apache    4071  0.0  0.0 213392  5968 ?        S    Aug24   0:05 /usr/sbin/httpd
apache    4072  0.0  0.0 213300  5940 ?        S    Aug24   0:05 /usr/sbin/httpd
apache    4073  0.0  0.0 213396  5948 ?        S    Aug24   0:05 /usr/sbin/httpd
apache    4074  0.0  0.0 213396  5944 ?        S    Aug24   0:05 /usr/sbin/httpd
apache    4075  0.0  0.0 213300  5936 ?        S    Aug24   0:05 /usr/sbin/httpd
apache    4076  0.0  0.0 213300  5952 ?        S    Aug24   0:05 /usr/sbin/httpd
apache    4077  0.0  0.0 213392  5948 ?        S    Aug24   0:05 /usr/sbin/httpd
apache    4078  0.0  0.0 213396  5960 ?        S    Aug24   0:05 /usr/sbin/httpd
root      8354  0.0  0.0 200788  6676 ?        Ss   Jul28   1:36 /usr/sbin/httpd
apache   14689  0.0  0.0 213392  5940 ?        S    Aug24   0:05 /usr/sbin/httpd
apache   15469  0.0  0.0 213396  5952 ?        S    Aug24   0:05 /usr/sbin/httpd
apache   20376  0.0  0.0 213396  5940 ?        S    Aug24   0:04 /usr/sbin/httpd
apache   31618  0.0  0.0 213300  5888 ?        S    Aug24   0:01 /usr/sbin/httpd
apache   32139  0.0  0.0 213300  5892 ?        S    Aug24   0:01 /usr/sbin/httpd
apache   32140  0.0  0.0 213300  5892 ?        S    Aug24   0:01 /usr/sbin/httpd
apache   32141  0.0  0.0 213300  5884 ?        S    Aug24   0:01 /usr/sbin/httpd

Run the following command to display the Apache web server uptime in For DEB based systems

$ ps -aux | grep apache2
root     20827  0.0  0.4 445772 24820 ?        Ss   Jul28   6:47 /usr/sbin/apache2 -k start
www-data 31456  2.3  0.5 459572 36312 ?        S    15:29   0:23 /usr/sbin/apache2 -k start
www-data 31744  1.8  0.5 458264 35892 ?        S    15:37   0:10 /usr/sbin/apache2 -k start
www-data 31962  3.6  0.5 459040 35820 ?        S    15:41   0:10 /usr/sbin/apache2 -k start
www-data 31963  1.7  0.5 458748 35396 ?        S    15:41   0:04 /usr/sbin/apache2 -k start
www-data 32024  2.5  0.5 459012 35244 ?        S    15:43   0:04 /usr/sbin/apache2 -k start
www-data 32026  2.0  0.5 453916 30860 ?        S    15:43   0:03 /usr/sbin/apache2 -k start
www-data 32111  2.1  0.5 458492 35360 ?        R    15:45   0:01 /usr/sbin/apache2 -k start
www-data 32114  2.0  0.5 455088 31668 ?        S    15:45   0:01 /usr/sbin/apache2 -k start
www-data 32115  5.0  0.5 459016 35624 ?        S    15:45   0:02 /usr/sbin/apache2 -k start
www-data 32116  1.2  0.5 454064 30652 ?        S    15:45   0:00 /usr/sbin/apache2 -k start
www-data 32117  2.0  0.5 459016 35568 ?        S    15:45   0:01 /usr/sbin/apache2 -k start
root     32135  0.0  0.0  11756   924 pts/4    S+   15:46   0:00 grep --color=auto apache2

Run the following command to display the Apache web server uptime in For RPM based systems [HH:MM:SS].

$ ps -eo comm,etime | grep httpd
httpd            1-05:53:32
httpd            1-05:53:32
httpd            1-05:53:32
httpd            1-05:53:32
httpd            1-05:53:32
httpd            1-05:53:32
httpd            1-05:53:32
httpd            1-05:53:32
httpd           27-15:44:20
httpd            1-01:20:55
httpd            1-01:00:04
httpd              22:56:22
httpd              17:19:07
httpd              17:05:54
httpd              17:05:53
httpd              17:05:53

Run the following command to display the Apache web server uptime in For DEB based systems [HH:MM:SS].

$ ps -eo comm,etime | grep apache2
apache2         26-21:28:54
apache2               16:23
apache2               08:44
apache2               04:16
apache2               04:15
apache2               02:23
apache2               02:19
apache2               02:19
apache2               00:33
apache2               00:32
apache2               00:31
apache2               00:31
apache2               00:31
apache2               00:31

The above output shows the elapsed time since the process was started. Our web server is up and running 26 days, 21 hours, 28 mins, and 54 secs.

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...