GithubHelp home page GithubHelp logo

openresty-statsd's Introduction

openresty-statsd travis-ci

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";
      
      -- make the statsd variable available in each phase
      init_by_lua 'statsd = require("statsd")';

      location /some_location {
        content_by_lua '
          -- this is the phase where metrics are sent
          -- batch metrics into packets of at least 50
          if table.getn(statsd.buffer) > 50 then statsd.flush(ngx.socket.udp, "127.0.0.1", 8125) end
        ';
        
        log_by_lua '
          -- this is the phase where metrics are registered
          statsd.incr("test.status." .. ngx.var.status)
          statsd.time("test.req_time", ngx.now() - ngx.req.start_time())
        ';
      }
    }

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.

Development

Prerequisites for dev and testing

Build

  1. Clone the repo
  2. bundle
  3. rake openresty:install
  4. rake statsd:install
  5. luarocks install busted [--local]
  6. Add lib/?.lua to your LUA_PATH

guard will run the unit tests.

foreman start will spin up nginx and statsd using dev configuration from ./config and ./examples.

Related projects

Author

Dave Nolan / lonelyplanet.com

openresty-statsd's People

Contributors

textgoeshere avatar spazm avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.