Category: General

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

Pagespeed module for webservers for performance improvement by Google

Pagespeed module for webservers for performance improvement are available for various platform, which provides a caching layer at webserver level to improve the overall delivery of the request.

About Pagespeed Module

Google pagespeed Insights are available in google chrome developer console or from this page

https://pagespeed.web.dev/?utm_source=psi&utm_medium=redirect

It is commonly used to check insight of the page speed among devices with a percentage score, here is the example

It also provoides the pointers to improve the page performance.

Apart from this, Google also provides pagespeed module for different webservers like apache, nginx

Implementing Module at webserver

one can download the binary and install the module. Instructions for most of OS are available here

https://www.modpagespeed.com/doc/download

  • The module config can be setup at server level or vhost level, following is the vhost level
<IfModule mod_ssl.c>
<IfModule pagespeed_module>
  ModPagespeedInheritVHostConfig on
  ModPagespeedEnableFilters add_instrumentation
  ModPagespeedStatistics on
  ModPagespeedStatisticsLogging on
  ModPagespeedLogDir /var/log/pagespeed
</IfModule>
</IfModule>

Monitoring Statistics

There are different handler available which provides statistics of pagespede module

  • pagespeed_global_admin
  • pagespeed_admin
  • mod_pagespeed_statistics
  • mod_pagespeed_console
<IfModule pagespeed_module>
  <Location /mod_pagespeed_console>
      <IfModule mod_rewrite.c>
          RewriteEngine Off
      </IfModule>
       Order allow,deny
      Allow from localhost
      SetHandler mod_pagespeed_console
  </Location>
 
 <Location /mod_pagespeed_statistics>
    <IfModule mod_rewrite.c>
        RewriteEngine Off
    </IfModule>
    Order allow,deny
    Allow from localhost
    SetHandler mod_pagespeed_statistics
  </Location>
 
  <Location /pagespeed_admin>
    <IfModule mod_rewrite.c>
        RewriteEngine Off
    </IfModule>
    Order allow,deny
    Allow from localhost
    SetHandler pagespeed_admin
  </Location>
 
  <Location /pagespeed_global_admin>
    <IfModule mod_rewrite.c>
        RewriteEngine Off
    </IfModule>
    Order allow,deny
    Allow from localhost
    SetHandler pagespeed_global_admin
  </Location>
</IfModule>

when you type the url in browser from localhost as it is only allwoed from localhost “Allow from localhost” or you can put your ip to allow the request like “Allow from <ip>” for the vhost like,

<vhost url> / <handler>

like <vhsot url>/pagespeed_admin

output is like,

courtesy : https://developers.google.com/speed