Process Resource Logging Module using JSON format into file or piped program
C Makefile Shell Ruby Other
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.clang-format
.gitignore
.travis.yml
MITL
Makefile
README.md
mod_resource_checker.c

README.md

mod_resource_checker Build Status

Process Resource Logging Module using JSON format into file or piped program.

Supported apache2.2.x and apache2.4.x with prefork mpm.

rcheck-analyze is analyze tool for mod_resource_checker log.  

  • setup conf.d/mod_resource_checker.conf
LoadModule resource_checker_module modules/mod_resource_checker.so

RCheckLogPath /var/log/httpd/resoruce.log
RCheckRealServerName www.matsumoto-r.jp

<Location />
  RCheckALL On
</Location>
  • check log file
tail -n 1 /var/log/httpd/resoruce.log | jq .
  • output logs
{
  "result": {
    "RCheckMEM": 31.289062,
    "RCheckSCPU": 0.06999,
    "RCheckUCPU": 0.360945
  },
  "bytes_sent": 59278,
  "size": 418,
  "response_time": 0,
  "threshold": null,
  "pid": 13990,
  "scheme": "http",
  "filename": "/usr/local/apache/htdocs/blog/index.php",
  "remote_ip": "127.0.0.1",
  "location": "/",
  "unit": null,
  "type": "RCheckALL",
  "date": "Fri Oct 23 21:24:23 2015",
  "module": "mod_resource_checker",
  "method": "GET",
  "hostname": "blog.matsumoto-r.jp",
  "server_ip": "127.0.0.1",
  "uri": "/?m=200901",
  "handler": "application/x-httpd-php",
  "real_server_name": "www.matsumoto-r.jp",
  "uid": 500,
  "status": 200
}

How To Compile

  • Build
(optional) yum install json-c json-c-devel
make
sudo make install
  • Add to httpd.conf
LoadModule resource_checker_module modules/mod_resource_checker.so

How To Use

Server Config

  • log file name (default /tmp/mod_resource_checker.log if no setting)

    RCheckLogPath "/usr/local/apache/logs/resoruce.log"
    

    or

  • if enable JSON Format RCheckJSONFormat On, for exmaple,

    RCheckLogPath "| mongoimport -d apache -c resource_check"
    

    It's very cool.

  • logging real server name

RCheckRealServerName www.matsumoto-r.jp

Directive Config

  • Logging all status and resources log
<Location />
  RCheckALL On
</Location>
{
  "result": {
    "RCheckMEM": 39.023438,
    "RCheckSCPU": 0.055992,
    "RCheckUCPU": 0.481926
  },
  "response_time": 0,
  "threshold": null,
  "pid": 22533,
  "status": 200,
  "scheme": "http",
  "filename": "/usr/local/apache244/htdocs/blog/index.php",
  "remote_ip": "127.0.0.1",
  "location": "/",
  "unit": null,
  "type": "RCheckALL",
  "date": "Sun Oct 11 18:08:12 2015",
  "module": "mod_resource_checker",
  "method": "GET",
  "hostname": "blog.matsumoto-r.jp",
  "server_ip": "127.0.0.1",
  "uri": "/index.php",
  "real_server_name": "www.matsumoto-r.jp",
  "uid": 2,
  "size": 418,
  "content_length": 2498
}
  • Logging all request which don't include resouces data
<Location />
  RCheckSTATUS On
</Location>
{
  "result": 0,
  "response_time": 0,
  "threshold": null,
  "pid": 22533,
  "status": 200,
  "scheme": "http",
  "filename": "/usr/local/apache244/htdocs/blog/index.php",
  "remote_ip": "127.0.0.1",
  "location": "/",
  "unit": null,
  "type": "RCheckSTATUS",
  "date": "Sun Oct 11 18:08:12 2015",
  "module": "mod_resource_checker",
  "method": "GET",
  "hostname": "blog.matsumoto-r.jp",
  "server_ip": "127.0.0.1",
  "uri": "/index.php",
  "real_server_name": "www.matsumoto-r.jp",
  "uid": 2,
  "size": 418,
  "content_length": 2498
}
  • Logging CPUUserTime
RCheckUCPU <threashould> <type>
  • Logging CPUSystemTime
RCheckSCPU <threashould> <type>
  • Logging UsedMemory
RCheckMEM <threashould> <type>

    <threashould>    digit(non-zero)

    <type>           ALL
                     SELF
                     CHILD
  • Directory Access Control
<Directory "/var/www/html">
     RCheckUCPU 0.0001 ALL
</Directory>
  • File Access Control
<Files "ag.cgi">
     RCheckUCPU 0.003 SELF
     RCheckSCPU 0.004 CHILD
     RCheckJSONFormat On
</Files>
  • Files Regex Access Control
<FilesMatch ".*\.cgi$">
     RCheckUCPU 0.005 ALL
     RCheckMEM 1 ALL
</FilesMatch>

License

under the MIT License: