File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 11load_module "/usr/lib/nginx/modules/ngx_stream_module.so" ;
2+ load_module "/usr/lib/nginx/modules/ngx_lua_module.so" ;
23
34worker_processes 1;
45
@@ -26,6 +27,13 @@ http {
2627 return 404 ;
2728 }
2829
30+ location /metrics {
31+ content_by_lua_block {
32+ local prometheus = require "resty.prometheus"
33+ prometheus:collect()
34+ }
35+ }
36+
2937 location /healthz {
3038 default_type text/plain;
3139 return 200 "OK\n " ;
3442}
3543
3644stream {
45+ lua_shared_dict prometheus_metrics 10M ;
3746 map_hash_bucket_size 128 ;
3847 map_hash_max_size 4096 ;
3948
@@ -47,10 +56,20 @@ stream {
4756 resolver kube-dns.kube-system.svc.cluster.local valid=30s ;
4857 resolver_timeout 5s ;
4958
59+ init_by_lua_block {
60+ local prom = require "docker.nginx.prometheus"
61+ prom.init()
62+ }
63+
5064 server {
5165 listen 127.0.0.1:8443 proxy_protocol ;
5266 ssl_preread on;
5367 proxy_pass $ssl_preread_server_name :443 ;
5468 proxy_protocol off;
69+
70+ log_by_lua_block {
71+ local prom = require "docker.nginx.prometheus"
72+ prom.log_connect_time()
73+ }
5574 }
5675}
Original file line number Diff line number Diff line change 1+ local prometheus = require " resty.prometheus"
2+ local metric_connections , metric_connect_time
3+
4+ local function init ()
5+ prometheus = prometheus .init (" prometheus_metrics" )
6+ metric_connections = prometheus :counter (" nginx_stream_connections_total" , " Total connections" , {" upstream" })
7+ metric_connect_time = prometheus :histogram (" nginx_stream_upstream_connect_seconds" , " Upstream connect time" ,
8+ {" upstream" })
9+ end
10+
11+ local function log_connect_time ()
12+ local connect_time = tonumber (ngx .var .upstream_connect_time )
13+ local upstream = ngx .var .upstream_addr or " unknown"
14+
15+ if connect_time then
16+ metric_connect_time :observe (connect_time / 1000 , {upstream }) -- Convert ms to seconds
17+ metric_connections :inc (1 , {upstream })
18+ end
19+ end
20+
21+ return {
22+ init = init ,
23+ log_connect_time = log_connect_time
24+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ package:
1010 runtime :
1111 - nginx
1212 - nginx-mod-stream
13+ - nginx-mod-lua
14+ - lua5.1-resty-core
1315 - wstunnel
1416 target-architecture :
1517 - aarch64
@@ -39,4 +41,5 @@ pipeline:
3941 install -dm755 "${{targets.destdir}}"/etc/ggbridge/tls
4042 install -m755 docker/scripts/run.sh "${{targets.destdir}}"/opt/ggbridge/run.sh
4143 install -m644 docker/nginx/nginx.conf "${{targets.destdir}}"/etc/ggbridge/nginx.conf
44+ install -m644 docker/nginx/prometheus.lua "${{targets.destdir}}"/etc/ggbridge/prometheus.lua
4245 - uses : strip
You can’t perform that action at this time.
0 commit comments