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 1
1
load_module "/usr/lib/nginx/modules/ngx_stream_module.so" ;
2
+ load_module "/usr/lib/nginx/modules/ngx_lua_module.so" ;
2
3
3
4
worker_processes 1;
4
5
@@ -26,6 +27,13 @@ http {
26
27
return 404 ;
27
28
}
28
29
30
+ location /metrics {
31
+ content_by_lua_block {
32
+ local prometheus = require "resty.prometheus"
33
+ prometheus:collect()
34
+ }
35
+ }
36
+
29
37
location /healthz {
30
38
default_type text/plain;
31
39
return 200 "OK\n " ;
34
42
}
35
43
36
44
stream {
45
+ lua_shared_dict prometheus_metrics 10M ;
37
46
map_hash_bucket_size 128 ;
38
47
map_hash_max_size 4096 ;
39
48
@@ -47,10 +56,20 @@ stream {
47
56
resolver kube-dns.kube-system.svc.cluster.local valid=30s ;
48
57
resolver_timeout 5s ;
49
58
59
+ init_by_lua_block {
60
+ local prom = require "docker.nginx.prometheus"
61
+ prom.init()
62
+ }
63
+
50
64
server {
51
65
listen 127.0.0.1:8443 proxy_protocol ;
52
66
ssl_preread on;
53
67
proxy_pass $ssl_preread_server_name :443 ;
54
68
proxy_protocol off;
69
+
70
+ log_by_lua_block {
71
+ local prom = require "docker.nginx.prometheus"
72
+ prom.log_connect_time()
73
+ }
55
74
}
56
75
}
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:
10
10
runtime :
11
11
- nginx
12
12
- nginx-mod-stream
13
+ - nginx-mod-lua
14
+ - lua5.1-resty-core
13
15
- wstunnel
14
16
target-architecture :
15
17
- aarch64
@@ -39,4 +41,5 @@ pipeline:
39
41
install -dm755 "${{targets.destdir}}"/etc/ggbridge/tls
40
42
install -m755 docker/scripts/run.sh "${{targets.destdir}}"/opt/ggbridge/run.sh
41
43
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
42
45
- uses : strip
You can’t perform that action at this time.
0 commit comments