toni-moreno / collectd-apachelog-plugin

A plugin for collectd which efficiently parses apache log files to get global and extended ( per HTTP CODE) hits count and response time it also supports the rotatelogs tools
GNU Lesser General Public License v3.0
8 stars 0 forks source link

collectd-apachelog-plugin

Description

A plugin for collectd which efficiently parses apache log files to get global and extended ( per HTTP CODE) metrics. It defines a http_perf ( performance ) new type, which defines the new metrics.

hit_rate ( hits /second) hit_x_interval ( #hits in the collectd interval time=> will be used to count hits across time ) rt_avg ( average response time in the elapsed interval time in "ms" ) rt_max ( max response time in the elapsed interval time in "ms") rt_min ( min response time in the elapsed interval time in "ms")

In extended mode gather performance statistics for :

It can parse apache logs and supports for rotatelogs tool ( by checking the last created file with a pattern)

Build the new plugin

You can add to collectd main project by only patching it ( until official pull will be accepted https://github.com/collectd/collectd/pull/576)

# git clone https://github.com/toni-moreno/collectd-apachelog-plugin.git
# git clone https://github.com/collectd/collectd.git
# cd collectd

# cp ~/collectd-apachelog-plugin/apache_log_plugin_v0.1.patch .
# patch -p0 < apache_log_plugin_v0.1.patch
# cp ~/collectd-apachelog-plugin/apache-log.c ./src/

You can now rebuild collecd project.

# ./build.sh
# ./configure  --enable-apachelog [other_configure_options]
# ./make
# ./make install

Configure The Plugin

LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" %D" combined
  LoadPlugin apachelog
  <Plugin apachelog>

    <File "/var/log/apache2/access.log*">  
      Instance "www_misite_com"
      RenamePluginAs "apache"
      UseApacheRotatedLogs "false"
      ExtendedMetrics "true"
      SetRespTimeField 0 
      SetHTTPCodeField  9  
    </File>

    <File "/var/log/apache2/access.log">  //filename Name on a fixed log name
      Instance "www_misite_com"
      RenamePluginAs "apache"
      UseApacheRotatedLogs "false"
    </File>

  </Plugin>

Customized configuration for Graphite/Collectd users

Add these storage-aggregation rules the (/opt/graphite/conf/storage-aggregation.conf) file.

[http_perf_hits]
pattern = \.hit_x_interval$
xFilesFactor = 0.5
aggregationMethod = sum

[http_perf_rt_avg]
pattern = \.rt_avg$
xFilesFactor = 0
aggregationMethod = avg

[http_perf_rt_min]
pattern = \.rt_min$
xFilesFactor = 0
aggregationMethod = min

[http_perf_rt_max]
pattern = \.rt_max$
xFilesFactor = 0
aggregationMethod = max