Lua StatsD client for openresty
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 24 commits ahead, 2 commits behind lonelyplanet:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
lib
spec
.gitignore
.travis.yml
README.md
TODO.md

README.md

openresty-statsd

Build Status

A Lua module for openresty to send metrics to StatsD

Features

  • increments!
  • counts!
  • timers!
  • cosocket frolics
  • batchin'

Installation

  1. Install openresty configured --with-luajit
  2. Copy lib/statsd.lua somewhere that openresty nginx can find (you may need to adjust your LUA_PATH or use lua_package_path directive
  3. Configure nginx:
    # an nginx conf
    http {
      # optionally set relative lua_package_path
      lua_package_path "${prefix}lua/*.lua";

      # create a shared dictionary to for statsd. The default name is STATSD
      lua_shared_dict STATSD 20k;

      location /some_location {
        content_by_lua '
          -- this is the phase where metrics are registered
          local statsd = require 'statsd'
          local s = statsd:new()
          s:incr("test.status." .. ngx.var.status)
          s:time("test.req_time", ngx.now() - ngx.req.start_time())

        ';

        log_by_lua '
          -- this is the phase where metrics are sent
          -- batch metrics into packets of 50 metrics by default
          local statsd = require 'statsd'
          local s = statsd:new()
          s:flush()
        ';
      }
    }

The request-response lifecycle in nginx has eight phases. The data you are likely to want to report (HTTP status, request time) is available in the last phase, log, but the socket API is not available. That's why stats are registered in log_by_lua and sent via flush in content_by_lua.

Changelog

  • 0.0.1: Works. Tested.
  • 0.0.2: Uses a dictionary

Development

Prerequisites for dev and testing

  • luarocks

Build

  1. Clone the repo
  2. luarocks install md5 [--local]
  3. luarocks install mime [--local]
  4. luarocks install busted [--local]

Then on the project folder console just run:

busted

Related projects

Author

Dave Nolan / lonelyplanet.com Enrique García