-
Notifications
You must be signed in to change notification settings - Fork 0
/
lua-init.conf
49 lines (42 loc) · 1.63 KB
/
lua-init.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
lua_shared_dict prometheus_metrics 10M;
lua_package_path "/lua-modules/?.lua;;";
init_by_lua_block {
function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
-- Load Prometheus module
prometheus = require("prometheus").init("prometheus_metrics")
metric_requests = prometheus:counter(
"nginx_http_requests_total", "Number of HTTP requests", {"host", "status"})
metric_latency = prometheus:histogram(
"nginx_http_request_duration_seconds", "HTTP request latency", {"host"})
metric_bytes = prometheus:counter(
"nginx_http_request_size_bytes", "Total size of incoming requests")
metric_response_sizes = prometheus:counter(
"nginx_http_response_size_bytes", "Total size of outgoing reponses")
metric_connections = prometheus:gauge(
"nginx_http_connections", "Number of HTTP connections", {"state"})
-- Load HTTP2 Push list
local filePath = "/usr/share/nginx/www/http2-push-map.txt"
local fileContent = io.open(filePath, "r");
httpPushList = {}
if fileContent then
for line in fileContent:lines() do
local url, assets = line:match("([^|]+)|(.+)")
httpPushList[url] = assets
end
io.close(fileContent)
else
print("File "..filePath.." doesn\'t exist")
end
healthCheckPath = os.getenv("HEALT_CHECK_PATH")
}
log_by_lua_block {
if ngx.var.request_uri ~= healthCheckPath then
local host = ngx.var.host
metric_requests:inc(1, {host, ngx.var.status})
metric_latency:observe(ngx.now() - ngx.req.start_time(), {host})
metric_bytes:inc(tonumber(ngx.var.request_length))
metric_response_sizes:inc(tonumber(ngx.var.bytes_sent))
end
}