Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load_module "/usr/lib/nginx/modules/ngx_stream_module.so";
load_module "/usr/lib/nginx/modules/ngx_lua_module.so";

worker_processes 1;

Expand Down Expand Up @@ -26,6 +27,13 @@ http {
return 404;
}

location /metrics {
content_by_lua_block {
local prometheus = require "resty.prometheus"
prometheus:collect()
}
}

location /healthz {
default_type text/plain;
return 200 "OK\n";
Expand All @@ -34,6 +42,7 @@ http {
}

stream {
lua_shared_dict prometheus_metrics 10M;
map_hash_bucket_size 128;
map_hash_max_size 4096;

Expand All @@ -47,10 +56,20 @@ stream {
resolver kube-dns.kube-system.svc.cluster.local valid=30s;
resolver_timeout 5s;

init_by_lua_block {
local prom = require "docker.nginx.prometheus"
prom.init()
}

server {
listen 127.0.0.1:8443 proxy_protocol;
ssl_preread on;
proxy_pass $ssl_preread_server_name:443;
proxy_protocol off;

log_by_lua_block {
local prom = require "docker.nginx.prometheus"
prom.log_connect_time()
}
}
}
24 changes: 24 additions & 0 deletions docker/nginx/prometheus.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
local prometheus = require "resty.prometheus"
local metric_connections, metric_connect_time

local function init()
prometheus = prometheus.init("prometheus_metrics")
metric_connections = prometheus:counter("nginx_stream_connections_total", "Total connections", {"upstream"})
metric_connect_time = prometheus:histogram("nginx_stream_upstream_connect_seconds", "Upstream connect time",
{"upstream"})
end

local function log_connect_time()
local connect_time = tonumber(ngx.var.upstream_connect_time)
local upstream = ngx.var.upstream_addr or "unknown"

if connect_time then
metric_connect_time:observe(connect_time / 1000, {upstream}) -- Convert ms to seconds
metric_connections:inc(1, {upstream})
end
end

return {
init = init,
log_connect_time = log_connect_time
}
2 changes: 2 additions & 0 deletions melange/ggbridge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package:
runtime:
- nginx
- nginx-mod-stream
- lua-resty-core
- wstunnel
target-architecture:
- aarch64
Expand Down Expand Up @@ -39,4 +40,5 @@ pipeline:
install -dm755 "${{targets.destdir}}"/etc/ggbridge/tls
install -m755 docker/scripts/run.sh "${{targets.destdir}}"/opt/ggbridge/run.sh
install -m644 docker/nginx/nginx.conf "${{targets.destdir}}"/etc/ggbridge/nginx.conf
install -m644 docker/nginx/prometheus.lua "${{targets.destdir}}"/etc/ggbridge/prometheus.lua
- uses: strip