lua-resty-influx
用于 OpenResty/LuaJIT 的 Lua influx 指标模块
$ opm get toruneko/lua-resty-influx
名称
lua-resty-influx - 用于 OpenResty/LuaJIT 的 Lua influx 指标模块
状态
此库被认为已准备好用于生产环境。
构建状态: [!Travis](https://travis-ci.org/toruneko/lua-resty-influx)
描述
此库需要使用带有 ngx_lua 模块 的 nginx 构建,以及 LuaJIT 2.0。
概要
# nginx.conf:
lua_package_path "/path/to/lua-resty-influx/lib/?.lua;;";
lua_shared_dict metrics 1m;
init_worker_by_lua_block {
local resty_reporter = require "resty.influx.db.reporter"
local reporter = resty_reporter.new("http://127.0.0.1:12354", "user", "pass", "nginx", {
tags = {
host = "127.0.0.1"
},
async = true -- auto flush reported data to influx
})
local resty_registry = require "resty.influx.registry"
_G.registry = resty_registry.new{reporter}
local func_reporter
func_reporter = function(registry)
registry:report()
local ok, err = ngx.timer.at(10, func_reporter, registry)
if not ok then
error(err)
end
end
local ok, err = ngx.timer.at(10, func_reporter, _G.registry)
if not ok then
error(err)
end
}
server {
location = /t {
content_by_lua_block {
local registry = _G.registry
local measurement = registry:measurement("request", {tag_key = tag_val})
local context = measurement:timer("rt"):time()
pcall(function()
for i = 1, 3 do
measurement:counter("tps"):mark(i)
measurement:averager("size"):update(i)
measurement:histogram("value"):update(i)
end
ngx.sleep(0.01)
ngx.update_time()
end)
context:stop()
-- do report
registry:report()
}
}
}
方法
要加载此库,
您需要在 ngx_lua 的 lua_package_path 指令中指定此库的路径。例如,
lua_package_path "/path/to/lua-resty-influx/lib/?.lua;;";
。您可以使用
require
将库加载到本地 Lua 变量中。
local resty_registry = require "resty.influx.registry"
new
语法: registry = resty_registry.new(reporters)
创建一个新的注册表对象实例。
-- creates a registry object
local resty_registry = require "resty.influx.registry"
local registry = resty_registry.new()
将指标报告到 influxdb。
local resty_reporter = require "resty.influx.db.reporter"
local reporter = resty_reporter.new("http://127.0.0.1:12354", "user", "pass", "nginx")
local resty_registry = require "resty.influx.registry"
local registry = resty_registry.new{ reporter }
measurement
语法: measurement = registry:measurement(key, {tag1= value1, tag2= value2, ... })
创建一个测量对象实例。
local measurement = registry:measurement("request")
report
语法: registry:report()
将测量结果报告给报告程序。
作者
戴建豪 (toruneko) <toruneko@outlook.com>
版权和许可证
此模块根据 MIT 许可证授权。
版权所有 (C) 2018,戴建豪 (toruneko) <toruneko@outlook.com>
保留所有权利。
在满足以下条件的情况下,允许以源代码和二进制形式重新分发和使用,无论是否修改:
源代码的重新分发必须保留上述版权声明、此条件列表和以下免责声明。
二进制形式的重新分发必须在随分发提供的文档和/或其他材料中复制上述版权声明、此条件列表和以下免责声明。
本软件由版权持有人和贡献者“按原样”提供,并且不提供任何明示或暗示的担保,包括但不限于适销性和特定用途适用性的暗示担保。在任何情况下,版权持有人或贡献者均不对任何直接的、间接的、附带的、特殊的、惩罚性的或后果性的损害(包括但不限于替代商品或服务的采购;使用、数据或利润损失;或业务中断)负责,无论这些损害是如何引起的以及基于何种责任理论,无论是基于合同、严格责任还是侵权行为(包括疏忽或其他原因),即使已被告知可能发生此类损害。
另请参阅
ngx_lua 模块:https://github.com/openresty/lua-nginx-module
作者
戴建豪(toruneko)
许可证
mit
依赖项
版本
-
用于 OpenResty/LuaJIT 的 Lua influx 指标模块 2019-02-14 05:29:35
-
用于 OpenResty/LuaJIT 的 Lua influx 指标模块 2018-10-31 08:26:22
-
用于 OpenResty/LuaJIT 的 Lua influx 指标模块 2018-10-31 08:05:57
-
用于 OpenResty/LuaJIT 的 Lua influx 指标模块 2018-10-31 06:05:02
-
用于 OpenResty/LuaJIT 的 Lua influx 指标模块 2018-08-31 02:14:37