Server tools - htop and apache server status
By Mike Street
When starting to debug server performance, a good place to start is the tools built into the server. Before you start installing extra utilities, it is worth checking to see if anything obvious sticks out.
Below we walk through using a htop
command line tool along with setting up a server status page.
(h)top
top
and the better looking htop
are great applications to see if there any processes hogging your system. I believe top
is installed by default but htop
can be installed with any good linux package manager.
I prefer htop
as you can filter by process name, sort the CPU/RAM columns and customise the output. You can change the top display too, to show CPU and RAM usage at a quick glance.
Use the F[0-10]
keys to navigate the interface (what to press is listed along the bottom).
A good one to use is press F6
to Sort By and then use the arrow keys to select PERCENT_CPU
or PERCENT_MEM
to see what is blocking your server. Once you've pressed enter, you can use the arrow keys to navigate up and down and list and potentially kill (F9
-> 9
-> Enter
) and processes you want to get rid of.
Leave the app open and do the action which seems to be slow - does anything jump out at you as a resource hog?
To leave top
, ctrl + c
will get you out. htop
can be quit by pressing F10
.
There are a lot more Linux tools available for DevOps monitoring - I tried a few to see if I could spot my problem, but nothing here really helped.
Apache server status
Apache has a server status page you can enable with some config.
It is worth noting that you probably want to restrict this to your IP so potential attackers or data thieves can't easily discover information about your server.
To enable the server status page, you need to enable the Apache module
sudo a2enmod status
Once enabled (but before you restart apache), edit the status.conf
file and uncomment out the IP address line and update to yours
The file can be found at
/etc/apache2/mods-available/status.conf
Look for the line starting Require ip
that is commented out by default
<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
#Require ip 192.0.2.0/24
</Location>
</IfModule>
Restart apache and this will then give you a quick snapshot of the server by navigating to /server-status
. You can add ?refresh=n
to the end of the URL, where n
is a number of seconds the page will automatically refresh.
E.g. (where 1.1.1.1 is your server IP) http://1.1.1.1/server-status?refresh=2