ngx_http_datalog

My first nginx module — I wanted the ability to monitor data usage (received bytes and sent bytes) based on a specific URI. I wanted to store the data usage in a database, but nothing that would potentially block, hence why SQLite3 is an excellent choice.

This module does exactly that, and you can define a regular expression to filter on URL’s. This regular expression supports matching as well.

Nginx configuration looks like this:

server {
server_name .mydomain.com;
listen 80;
datalog on;
datalog_filter ^/api/foo/(.*)/bar$
datalog_db /var/db/nginx-datalog.sqlite;
}

Code is available on https://github.com/tk512/ngx_http_datalog for those interested.

To build into your own nginx, simply download the nginx source code and compile with

--add-module=../ngx_http_datalog

(Assuming the ngx_http_datalog directory is below your nginx source dir).