lua script to emit metrics info to tsdb server
从nginx中发送nginx metrics信息到tsdb。主要依赖: 1、ngx_lua: http://wiki.nginx.org/HttpLuaModule 2、cmsgpack: https://github.com/antirez/lua-cmsgpack 3、luasocket: http://w3.impa.br/~diego/software/luasocket/
使用方法: 1、安装依赖 2、nginx配置: lua_package_path "/some/path/to/ngx_lua_metrics/?.lua;;"; lua_package_cpath "/some/path/to/ngx_lua_metrics/?.so;;";
init_by_lua "
metrics = require 'metrics'
local conf = {}
conf.metrics_namespace_prefix = 'prefix.name'
conf.host = '127.0.0.1'
conf.port = 5005
metrics.init(conf)
";
log_by_lua " local tagkv = {} tagkv.host = ngx.var.hostname tagkv.client = ngx.var.remote_addr metrics.emit_counter(tostring(ngx.var.status), 1, nil, tagkv) metrics.emit_timer('latency', ngx.var.request_time, nil, tagkv) ";
因为ngx.socket.udp不能在log_by_lua这个context下使用,所以使用了luasocket。