Server tools - htop and apache server status

A post from the future!

You may have noticed this post is dated in the future. I do this to keep myself on a regular writing schedule and to mask the flurries of activity I'm prone to. You can see all of my upcoming posts if you want a sneak peak

Please feel free to read and share as you normally would.

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.

Note: This post is part of a mini-series exploring debugging and monitoring server performance. All the posts can be found under the Server Tools - Introduction post.

(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

This website is currently having a full content audit - apologies if some of the code or content looks a bit funky!

View this post on Gitlab

You might also enjoy…

Mike Street

Written by Mike Street

Mike is a front-end developer from Brighton, UK. He spends his time writing, cycling and coding. You can find Mike on Twitter.