Created
September 22, 2016 12:28
-
-
Save zevarito/698bbd189d3ec7f0551bff0b578aafde to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Lua Prometheus collecter and exporter | |
lua_shared_dict prometheus_metrics 200M; | |
lua_package_path "{{nginx_lua_prometheus_path}}/?.lua"; | |
init_by_lua ' | |
prometheus = require("prometheus").init("prometheus_metrics") | |
metric_requests = prometheus:counter( | |
"nginx_http_requests_total", "Number of HTTP requests", {"host", "app","status", "uri", "method"}) | |
metric_latency = prometheus:histogram( | |
"nginx_http_request_duration_seconds", "HTTP request latency", {"host", "app","status", "uri", "method"}) | |
'; | |
log_by_lua ' | |
local host = ngx.var.host:gsub("^www.", "") | |
metric_requests:inc(1, {host, ngx.var.app, ngx.var.status, ngx.var.uri, ngx.var.request_method}) | |
metric_latency:observe(ngx.now() - ngx.req.start_time(), {host, ngx.var.app, ngx.var.status, ngx.var.uri, ngx.var.request_method}) | |
'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment