Skip to content

Instantly share code, notes, and snippets.

@zevarito
Created September 22, 2016 12:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zevarito/698bbd189d3ec7f0551bff0b578aafde to your computer and use it in GitHub Desktop.
Save zevarito/698bbd189d3ec7f0551bff0b578aafde to your computer and use it in GitHub Desktop.
# 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