Monitoring Apache Logs using Zabbix

Apart from monitoring server hardware and software key variable like CPU/Memory/Disk/Process, We also require monitoring of apache logs using Zabbix to monitor all from a single monitoring platform

Monitoring Apache Logs

If we are talking about monitoring, it covers the aspect

  • Either we want to get some logs like 404 requests or 500 requests
  • Or we want to get the number

Add/Create an Item in Zabbix

For this, You can create custom items

  • Login on Zabbix Server Frontend URL
  • Configuration > Template > Create Template
  • After creating a template, click on the newly created template, and under that click on Items
  • Click on create Item
  • Most of the elements are self-explanatory like Name, type, update interval, History period, Application group [optional]
  • The Key contains multiple methods, for now, we are using these two
    • logrt : used for getting logs with regular expression as here we trying to get logs for only 404 requests searching all files that end access_log
    • logrt.count : used for getting count with regular expression
logrt[/var/log/apache2/.*access.log, 404 ,,,skip] 
  • .*access.log is a regex pattern
  • second parameter is also a regex : <space>404<space>, searching status code
    • 41.90.12.31 – – [22/Feb/2022:05:01:43 +0000] “GET /apple-touch-icon-precomposed.png HTTP/1.1” 404 230
  • You can add more items, it is just required log file path, aggregator method, and regex
  • And you will get this Data under the Host graph along with other data

Check if Zabbix-Agent can access log file

Make sure, the Zabbix agent is able to read the log file, this can be ensured by executing the following command

su zabbix -s /bin/bash -c "tail /var/log/httpd/access_log"

if you are getting permission denied, please provide the permission to Zabbix user to read this directory

In case you are not getting data, Please cross-check for zabbix.log on the host, if there is any issue.

tail -f /var/log/zabbix/zabbix_agentd.log

Monitoring Web Scenario

Along with the apache logs, you can also any specific URL on a time interval validating the response and raising the alarm. It is like uptime robot where you add your URL and it pings to the URL and trigger an email in case URL is down.

  • Create a Web Scenario
  • Add basic detail like name, agent[zabbix/chorme], proxy if any
  • Add URL, params, and response validation under steps

Leave a Reply

Your email address will not be published. Required fields are marked *