Skip to main content

Zabbix Apache 2 Monitor

Guangzhou, China

Update: I had a couple of issues below. In the end switching the template from HTTP to Zabbix Agent solved it.

Apache Module mod_status

Activate the Server Status module:

sudo a2enmod status

And add the configuration to:

nano /etc/apache2/mods-available/status.conf

Enabling Status Support for the host you want to monitor:

<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

##Allow all IPs to access for testing
#Allow from all

##Allow only localhost and local server IP
Order deny,allow
Deny from all
Allow from 127.0.0.1 ::1
Allow from Your.Server.IP.Address.Here

##Limit access from other hosts
#Require local
#Require ip 192.0.2.0/24
#Require host example.com
</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>

Check config integrity and restart:

apachectl configtest
apache2 -t # or httpd -t
systemctl restart apache2 # or httpd

Or all in one line:

apache2ctl -t && apache2ctl graceful

Test the status output by:

curl http://127.0.0.1/server-status?auto
127.0.0.1
ServerVersion: Apache/2.4.25 (Debian) OpenSSL/1.0.2q
ServerMPM: prefork
Server Built: 2018-11-03T18:46:19
CurrentTime: Tuesday, 09-Nov-2021 07:24:39 CET
RestartTime: Tuesday, 09-Nov-2021 06:44:31 CET
ParentServerConfigGeneration: 1
ParentServerMPMGeneration: 0
ServerUptimeSeconds: 2408
ServerUptime: 40 minutes 8 seconds
Load1: 0.07
Load5: 0.24
Load15: 0.53
Total Accesses: 319
Total kBytes: 1554
CPUUser: 5.52
CPUSystem: 2.06
CPUChildrenUser: 0
CPUChildrenSystem: 0
CPULoad: .314784
Uptime: 2408
ReqPerSec: .132475
BytesPerSec: 660.837
BytesPerReq: 4988.39
BusyWorkers: 2
IdleWorkers: 8
Scoreboard: _W____W___............................................................................................................................................
TLSSessionCacheStatus
CacheType: SHMCB
CacheSharedMemory: 512000
CacheCurrentEntries: 35
CacheSubcaches: 32
CacheIndexesPerSubcaches: 88
CacheTimeLeftOldestAvg: 123
CacheTimeLeftOldestMin: 0
CacheTimeLeftOldestMax: 262
CacheIndexUsage: 1%
CacheUsage: 1%
CacheStoreCount: 279
CacheReplaceCount: 0
CacheExpireCount: 244
CacheDiscardCount: 0
CacheRetrieveHitCount: 0
CacheRetrieveMissCount: 38
CacheRemoveHitCount: 0
CacheRemoveMissCount: 0

Configure Zabbix Agent

Stat by adding the Apache by HTML template:

Zabbix Apache Monitor

Currently I am only getting the Uptime and Ping:

Zabbix Apache Monitor

Those are the only passively collected items of Apache template. All other depend on the queried status from our Apache server. I found that the host address was not set to localhost:

Zabbix Apache Monitor

So I added the macro and set:

{$APACHE.STATUS.HOST} 127.0.0.1

to make sure that the agent is querying from there and is not blocked (on the server IP address I am forcing an HTTPS upgrade of the connection - so using localhost instead allows me to get around that.):

Zabbix Apache Monitor

But this did not solve the issue :( Initially I though it might be because of an outdated Apache Version - but this is fairly up-2-date for Debian standards (I have seen the template work with Apache/2.4.37):

apache2 -version
Server version: Apache/2.4.25 (Debian)

One more try - I edited the URL that is used by the Apache template:

{$APACHE.STATUS.SCHEME}://{HOST.CONN}:{$APACHE.STATUS.PORT}/{\$APACHE.STATUS.PATH}

And hardcoded it:

http://127.0.0.1/server-status?auto

Zabbix Apache Monitor

Solution

For some reasons the template Template App Apache by HTTP is not working for me. Switching to Template App Apache by Zabbix agent solved it:

Zabbix Apache Monitor

I kept all changes I made above in place and all items started populating once I made the switch to the Agent template:

Zabbix Apache Monitor