In this tutorial, I'll explain different ways to identify the Apache uptime status on our latest CentOS 7.4 and Ubuntu 16.04 distributions using various command line utilities and other methods.
ps Utility
ps is a program which displays the currently-running processes. This utility shows information concerning a selection of the active processes running on a Linux system, we can use it with grep command to check Apache service uptime as follows.
On Ubuntu /Debian
The sample output below shows that the Apache2 service has been running for 8 hours, 30 minutes and 5 seconds considering the one run as root.
# ps -eo comm,etime,user | grep apache2 apache2 08:30:05 root apache2 08:13:59 www-data apache2 08:13:59 www-data # ps -eo comm,etime,user | grep root | grep apache2 apache2 08:30:18 root
On CentOS/RHEL
The sample output below shows that Apache service has been running for 2 days, 5 hours, 53 minutes and 17 seconds considering the one run as root.
# ps -eo comm,etime,user | grep httpd httpd 2-05:53:17 root httpd 11:07:49 apache httpd 11:07:49 apache httpd 11:07:49 apache httpd 11:07:49 apache httpd 11:07:49 apache httpd 09:19:24 apache # ps -eo comm,etime,user | grep root | grep httpd httpd 2-05:53:17 root
Here, the flag:
-e: enables selection of every processes on the system. -o: is used to specify output comm: command etime: mention process execution time user: specifies the process owner
Systemctl Utility
The systemctl command is the basic command that is used to manage and control systemd, including system services. It allows you to enable, disable, view, start, stop, or restart system services. We can use this systemctl status sub-command to view the status of our Apache service as below:
On Ubuntu/Debian
You can use below command to get Apache2 uptime on an Ubuntu/Debian server.
# systemctl status apache2 | grep -i active Active: active (running) since Sun 2018-03-04 14:45:59 UTC; 19min ago
On CentOS /RHEL
You can use the same "systemctl" command to find httpd status
# systemctl status httpd | grep -i active Active: active (running) since Fri 2018-03-02 08:47:46 UTC; 2 days ago
Apachectl Utility
Apachectl is a front-end control interface for Apache HyperText Transfer Protocol (HTTP) server. It is designed to assist the administrators to control the functioning of the Apache daemon. This method requires the mod_status module to be installed and enabled in the server to make it function as required. An HTML page is presented on browser that gives the current server statistics in an easily readable form. It is enabled in all servers by default. In order to check the Apache status using this utility from the command line, we need to enable the command line Web browser such as lynx or elinks. Or else, it will report as below:
# apachectl status /usr/sbin/apachectl: 101: /usr/sbin/apachectl: www-browser: not found 'www-browser -dump http://localhost:80/server-status' failed. Maybe you need to install a package providing www-browser or you need to adjust the APACHE_LYNX variable in /etc/apache2/envvars
Hence, I installed this command line web browsers to make it work from the server terminal.
On Ubuntu/Debian
We can install Lynx command line browser to enable apachectl status here.
# apt install lynx # apachectl status Apache Server Status for localhost (via ::1) Server Version: Apache/2.4.18 (Ubuntu) Server MPM: event Server Built: 2017-09-18T15:09:02 __________________________________________________________________
Current Time: Sunday, 04-Mar-2018 15:24:38 UTC Restart Time: Sunday, 04-Mar-2018 14:45:58 UTC Parent Server Config. Generation: 1 Parent Server MPM Generation: 0 Server uptime: 38 minutes 39 seconds Server load: 0.00 0.00 0.00 Total accesses: 0 - Total Traffic: 0 kB CPU Usage: u0 s0 cu0 cs0 0 requests/sec - 0 B/second - 1 requests currently being processed, 49 idle workers PID Connections Threads Async connections total accepting busy idle writing keep-alive closing 18424 0 yes 1 24 0 0 0 18425 0 yes 0 25 0 0 0 Sum 0 1 49 0 0 0 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
On CentOS/RHEL
We can install elinks command line browser to enable apachectl status here.
# yum install elinks # apachectl status * httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since Sun 2018-03-04 15:28:20 UTC; 6min ago Docs: man:httpd(8) man:apachectl(8) Process: 21280 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS) Process: 14448 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS) Main PID: 21286 (httpd) Status: "Total requests: 1; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service |-21286 /usr/sbin/httpd -DFOREGROUND |-21288 /usr/sbin/httpd -DFOREGROUND |-21289 /usr/sbin/httpd -DFOREGROUND |-21290 /usr/sbin/httpd -DFOREGROUND |-21291 /usr/sbin/httpd -DFOREGROUND |-21292 /usr/sbin/httpd -DFOREGROUND `-21293 /usr/sbin/httpd -DFOREGROUND Mar 04 15:28:20 li694-77.members.linode.com systemd[1]: Starting The Apache HTTP Server... Mar 04 15:28:20 li694-77.members.linode.com systemd[1]: Started The Apache HTTP Server.
Enabling Mod-Status Module
Alternatively, to view the Apache web server status information from a graphical web browser, you need to enable the server-status module in the Apache configuration.
On CentOS/RHEL
To enable the server-status module, you need to create a file named /etc/httpd/conf.d/server-status.conf
in our server with the following contents and restart Apache to make the changes effective.
# cat /etc/httpd/conf.d/server-status.conf <Location "/server-status"> SetHandler server-status #Require host localhost #uncomment to only allow requests from localhost </Location>
Now you can browse the URL http://server-IP/server-status
to view the status.
On Ubuntu /Debian
Similarly, you can comment the following entries in the /etc/apache2/mods-enabled/status.conf
on our Debian/Ubuntu servers and reload the Apache2 configuration to make these changes effective.
# cat /etc/apache2/mods-enabled/status.conf <IfModule mod_status.c> # Allow server status reports generated by mod_status, # with the URL of http://servername/server-status # Uncomment and change the "192.0.2.0/24" to allow access from other hosts. <Location /server-status> SetHandler server-status #Require local #uncomment to only allow requests from localhost #Require ip 192.0.2.0/24 #uncomment and change the “192.0.2.0/24” to allow access from other hosts. </Location> # Keep track of extended status information for each request ExtendedStatus On # Determine if mod_status displays the first 63 characters of a request or # the last 63, assuming the request itself is greater than 63 chars. # Default: Off #SeeRequestTail On <IfModule mod_proxy.c> # Show Proxy LoadBalancer status in mod_status ProxyStatus On </IfModule> </IfModule> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Now you can browse the URL http://server-IP/server-status
to view the status. Alternatively, you can run the command using text-mode browser like elinks or lynx to view the Apache uptime as
#elinks http://localhost/server-status or #lynx http://localhost/server-status
Tracking Uptime from the Apache logs
On Ubuntu/Debian servers, you can view the Apache logs located at /var/log/apache2/error.log
to identify the latest Apache restart attempts using this command below:
# tail -f /var/log/apache2/error.log | grep resuming [Sun Mar 04 06:25:02.611615 2018] [mpm_event:notice] [pid 15230:tid 140159687124864] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations [Sun Mar 04 14:45:58.950825 2018] [mpm_event:notice] [pid 18421:tid 139913481500544] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations [Sun Mar 04 15:42:25.768467 2018] [mpm_event:notice] [pid 18421:tid 139913481500544] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations
Likewise, on CentOS/RHEL servers you can view the Apache logs located at /var/log/httpd/error_log
to identify the recent Apache restart attempt using this command below:
# tail -f /var/log/httpd/error_log | grep resuming [Sun Mar 04 15:28:20.579455 2018] [mpm_prefork:notice] [pid 21286] AH00163: Apache/2.4.6 (CentOS) configured -- resuming normal operations
Tracking Uptime from Webhosting Control Panels
We are familiar with various web hosting control panels like WHM, DirectAdmin, Plesk, InterWorx, Webmin, Kloxo etc. I'll walk you through the steps on viewing the Apache uptime on two of the widely used Web hosting Panels like WHM and Interworx below:
WHM
In a WHM server, we can view the Apache Status, by navigating through the path WHM HOME >> Server Status >> Apache Status
after logging to your WHM Panel at the URL >>https://serverIP or hostname:2087
as shown in the screenshot.
Interworx
The InterWorx Web Control Panel is a Linux based web hosting control panel for both dedicated and VPS hosting. It can be used by both system administrators and website administrator with ease. In this Panel, we can check the Apache uptime by navigating through the steps below:
Login to your Nodeworx Panel at >> https://hostname or ServerIP:2443
Navigate through the Path Nodeworx Home >> System Services >> Web Server
In those Panels which don't have a user-friendly interface for checking the Web server Status, we can enable the mod_status module to view its uptime from the browser.
All these methods allow a server administrator to find out how well their server is performing. In addition, it can also be used for troubleshooting the domain downtimes. I hope this article is useful for you all. Please let me know your suggestions and thoughts to share on this.
Hi,
another tool for analyzing the server-status is the Pimped apache status
https://github.com/axelhahn/pimped-apache-status/tree/master
It generates several views for most requested content, ip addresses with the most requests.
It even can merge the data of several servers for loadbalanced websites.
Regards,
Axel
Thanks Axel