- commit
- c04b5fd
- parent
- cf7db11
- author
- Antonio Mika
- date
- 2025-03-07 16:11:55 -0500 EST
Merge pull request #191 from picosh/am/web-metrics Am/web metrics
14 files changed,
+90,
-151
+2,
-0
1@@ -21,6 +21,7 @@ import (
2 "github.com/picosh/pico/shared"
3 "github.com/picosh/utils"
4 "github.com/picosh/utils/pipe/metrics"
5+ "github.com/prometheus/client_golang/prometheus/promhttp"
6 )
7
8 //go:embed html/* public/*
9@@ -750,6 +751,7 @@ func authMux(apiConfig *shared.ApiConfig) *http.ServeMux {
10 mux.HandleFunc("GET /apple-touch-icon.png", fileServer.ServeHTTP)
11 mux.HandleFunc("GET /favicon.ico", fileServer.ServeHTTP)
12 mux.HandleFunc("GET /robots.txt", fileServer.ServeHTTP)
13+ mux.HandleFunc("GET /_metrics", promhttp.Handler().ServeHTTP)
14
15 if apiConfig.Cfg.Debug {
16 shared.CreatePProfRoutesMux(mux)
+13,
-3
1@@ -50,15 +50,25 @@
2 disable_openmetrics
3 }
4
5- @appmetrics {
6+ @sshmetrics {
7 host {$APP_DOMAIN}
8- path /_app/metrics
9+ path /_ssh/metrics
10 }
11
12- handle @appmetrics {
13+ handle @sshmetrics {
14 rewrite * /metrics
15 reverse_proxy ssh:9222
16 }
17+
18+ @webmetrics {
19+ host {$APP_DOMAIN}
20+ path /_web/metrics
21+ }
22+
23+ handle @webmetrics {
24+ rewrite * /_metrics
25+ reverse_proxy web:3000
26+ }
27 }
28
29 :443 {
+11,
-0
1@@ -24,6 +24,7 @@
2 respond @options 204
3
4 @caddymetrics {
5+ host auth.pico.sh
6 path /_caddy/metrics
7 }
8
9@@ -31,6 +32,16 @@
10 disable_openmetrics
11 }
12
13+ @webmetrics {
14+ host auth.pico.sh
15+ path /_web/metrics
16+ }
17+
18+ handle @webmetrics {
19+ rewrite * /_metrics
20+ reverse_proxy auth-web:3000
21+ }
22+
23 reverse_proxy @auth auth-web:3000
24
25 reverse_proxy @irc https://bouncer:8080 {
+13,
-3
1@@ -65,15 +65,25 @@
2 disable_openmetrics
3 }
4
5- @appmetrics {
6+ @sshmetrics {
7 host {$APP_DOMAIN}
8- path /_app/metrics
9+ path /_ssh/metrics
10 }
11
12- handle @appmetrics {
13+ handle @sshmetrics {
14 rewrite * /metrics
15 reverse_proxy ssh:9222
16 }
17+
18+ @webmetrics {
19+ host {$APP_DOMAIN}
20+ path /_web/metrics
21+ }
22+
23+ handle @webmetrics {
24+ rewrite * /_metrics
25+ reverse_proxy web:3000
26+ }
27 }
28
29 monitoring.{$MONITORING_APP_DOMAIN}, prometheus.{$MONITORING_APP_DOMAIN}, grafana.{$MONITORING_APP_DOMAIN} {
+29,
-4
1@@ -1,10 +1,35 @@
2+{
3+ servers {
4+ metrics
5+ }
6+}
7+
8 {$APP_DOMAIN} {
9- reverse_proxy https://pico-docs-prod.pgs.sh {
10- header_up Host pico.sh
11- }
12+ reverse_proxy https://pico-docs-prod.pgs.sh {
13+ header_up Host pico.sh
14+ }
15
16- tls {$APP_EMAIL} {
17+ tls {$APP_EMAIL} {
18 dns cloudflare {$CF_API_TOKEN}
19 resolvers 1.1.1.1
20 }
21+
22+ @caddymetrics {
23+ host {$APP_DOMAIN}
24+ path /_caddy/metrics
25+ }
26+
27+ metrics @caddymetrics {
28+ disable_openmetrics
29+ }
30+
31+ @sshmetrics {
32+ host {$APP_DOMAIN}
33+ path /_ssh/metrics
34+ }
35+
36+ handle @sshmetrics {
37+ rewrite * /metrics
38+ reverse_proxy ssh:9222
39+ }
40 }
+0,
-52
1@@ -1,52 +0,0 @@
2-{
3- servers {
4- metrics
5- }
6-}
7-
8-*.{$APP_DOMAIN}, {$APP_DOMAIN} {
9- reverse_proxy web:3000
10- tls {$APP_EMAIL} {
11- dns cloudflare {$CF_API_TOKEN}
12- resolvers 1.1.1.1
13- }
14- encode zstd gzip
15-
16- header {
17- # disable FLoC tracking
18- Permissions-Policy interest-cohort=()
19-
20- # enable HSTS
21- Strict-Transport-Security max-age=31536000;
22-
23- # disable clients from sniffing the media type
24- X-Content-Type-Options nosniff
25-
26- # clickjacking protection
27- X-Frame-Options DENY
28-
29- # keep referrer data off of HTTP connections
30- Referrer-Policy no-referrer-when-downgrade
31-
32- X-XSS-Protection "1; mode=block"
33- }
34-
35- @caddymetrics {
36- host {$APP_DOMAIN}
37- path /_caddy/metrics
38- }
39-
40- metrics @caddymetrics {
41- disable_openmetrics
42- }
43-
44- @appmetrics {
45- host {$APP_DOMAIN}
46- path /_app/metrics
47- }
48-
49- handle @appmetrics {
50- rewrite * /metrics
51- reverse_proxy ssh:9222
52- }
53-}
+0,
-84
1@@ -1,84 +0,0 @@
2-{
3- on_demand_tls {
4- ask http://web:3000/check
5- }
6- servers {
7- metrics
8- }
9-}
10-
11-*.{$APP_DOMAIN}, {$APP_DOMAIN} {
12- reverse_proxy web:3000
13- tls {$APP_EMAIL} {
14- dns cloudflare {$CF_API_TOKEN}
15- resolvers 1.1.1.1
16- }
17- encode zstd gzip
18-
19- header {
20- # disable FLoC tracking
21- Permissions-Policy interest-cohort=()
22-
23- # enable HSTS
24- Strict-Transport-Security max-age=31536000;
25-
26- # disable clients from sniffing the media type
27- X-Content-Type-Options nosniff
28-
29- # clickjacking protection
30- X-Frame-Options DENY
31-
32- # keep referrer data off of HTTP connections
33- Referrer-Policy no-referrer-when-downgrade
34-
35- Content-Security-Policy "default-src 'self'; img-src * 'unsafe-inline'; style-src * 'unsafe-inline'"
36-
37- X-XSS-Protection "1; mode=block"
38- }
39-
40- @caddymetrics {
41- host {$APP_DOMAIN}
42- path /_caddy/metrics
43- }
44-
45- metrics @caddymetrics {
46- disable_openmetrics
47- }
48-
49- @appmetrics {
50- host {$APP_DOMAIN}
51- path /_app/metrics
52- }
53-
54- handle @appmetrics {
55- rewrite * /metrics
56- reverse_proxy ssh:9222
57- }
58-}
59-
60-*.{$TUNS_DOMAIN}, {$TUNS_DOMAIN} {
61- reverse_proxy {$TUNS_V4}:2080
62- tls {$MONITORING_APP_EMAIL} {
63- dns cloudflare {$CF_API_TOKEN}
64- resolvers 1.1.1.1
65- }
66-
67- encode zstd gzip
68-
69- @caddymetrics {
70- host {$TUNS_DOMAIN}
71- path /_caddy/metrics
72- }
73-
74- metrics @caddymetrics {
75- disable_openmetrics
76- }
77-}
78-
79-:443 {
80- reverse_proxy web:3000
81- tls {$APP_EMAIL} {
82- on_demand
83- }
84- encode zstd gzip
85-}
+8,
-4
1@@ -17,6 +17,10 @@ services:
2 - "${AUTH_V4:-0.0.0.0}:80:80"
3 - "[${AUTH_V6:-::1}]:443:443"
4 - "[${AUTH_V6:-::1}]:80:80"
5+ - "${BOUNCER_V4:-0.0.0.0}:443:443"
6+ - "${BOUNCER_V4:-0.0.0.0}:80:80"
7+ - "[${BOUNCER_V6:-::1}]:443:443"
8+ - "[${BOUNCER_V6:-::1}]:80:80"
9 auth-web:
10 volumes:
11 - ./data/auth-web/data:/app/ssh_data
12@@ -39,10 +43,10 @@ services:
13 env_file:
14 - .env.prod
15 ports:
16- - "${AUTH_IRCS_V4:-6697}:6697"
17- - "${AUTH_IRCS_V6:-[::1]:6697}:6697"
18- - "${AUTH_IDENTD_V4:-113}:113"
19- - "${AUTH_IDENTD_V6:-[::1]:113}:113"
20+ - "${BOUNCER_IRCS_V4:-6697}:6697"
21+ - "${BOUNCER_IRCS_V6:-[::1]:6697}:6697"
22+ - "${BOUNCER_IDENTD_V4:-113}:113"
23+ - "${BOUNCER_IDENTD_V6:-[::1]:113}:113"
24 volumes:
25 - ./data/run:/run/soju
26 - ./data/bouncer:/app/db
+3,
-0
1@@ -65,6 +65,7 @@ services:
2 - caddy
3 - all
4 pastes-web:
5+ dns: 1.1.1.1
6 networks:
7 pastes:
8 aliases:
9@@ -159,6 +160,7 @@ services:
10 - caddy
11 - all
12 prose-web:
13+ dns: 1.1.1.1
14 networks:
15 prose:
16 aliases:
17@@ -209,6 +211,7 @@ services:
18 - caddy
19 - all
20 pgs-web:
21+ dns: 1.1.1.1
22 networks:
23 pgs:
24 aliases:
+2,
-0
1@@ -8,6 +8,7 @@ import (
2
3 "github.com/picosh/pico/db/postgres"
4 "github.com/picosh/pico/shared"
5+ "github.com/prometheus/client_golang/prometheus/promhttp"
6 )
7
8 func keepAliveHandler(w http.ResponseWriter, r *http.Request) {
9@@ -100,6 +101,7 @@ func createMainRoutes(staticRoutes []shared.Route) []shared.Route {
10 shared.NewRoute("GET", "/", shared.CreatePageHandler("html/marketing.page.tmpl")),
11 shared.NewRoute("GET", "/keep-alive/(.+)", keepAliveHandler),
12 shared.NewRoute("GET", "/unsub/(.+)", unsubHandler),
13+ shared.NewRoute("GET", "/_metrics", promhttp.Handler().ServeHTTP),
14 }
15
16 routes = append(
+2,
-0
1@@ -12,6 +12,7 @@ import (
2 "github.com/picosh/pico/db/postgres"
3 "github.com/picosh/pico/shared"
4 "github.com/picosh/utils"
5+ "github.com/prometheus/client_golang/prometheus/promhttp"
6 )
7
8 type PageData struct {
9@@ -332,6 +333,7 @@ func createMainRoutes(staticRoutes []shared.Route) []shared.Route {
10 routes := []shared.Route{
11 shared.NewRoute("GET", "/", shared.CreatePageHandler("html/marketing.page.tmpl")),
12 shared.NewRoute("GET", "/check", shared.CheckHandler),
13+ shared.NewRoute("GET", "/_metrics", promhttp.Handler().ServeHTTP),
14 }
15
16 routes = append(
+3,
-1
1@@ -24,6 +24,7 @@ import (
2 "github.com/picosh/pico/shared"
3 "github.com/picosh/pico/shared/storage"
4 sst "github.com/picosh/pobj/storage"
5+ "github.com/prometheus/client_golang/prometheus/promhttp"
6 "google.golang.org/protobuf/proto"
7 )
8
9@@ -58,7 +59,7 @@ func StartApiServer(cfg *PgsConfig) {
10 Configuration: map[string]interface{}{},
11 },
12 Regex: configurationtypes.Regex{
13- Exclude: "/check",
14+ Exclude: "/check|/_metrics",
15 },
16 MaxBodyBytes: uint64(cfg.MaxAssetSize),
17 DefaultCacheControl: cfg.CacheControl,
18@@ -111,6 +112,7 @@ func (web *WebRouter) initRouters() {
19 // root domain
20 rootRouter := http.NewServeMux()
21 rootRouter.HandleFunc("GET /check", web.checkHandler)
22+ rootRouter.HandleFunc("GET /_metrics", promhttp.Handler().ServeHTTP)
23 rootRouter.Handle("GET /main.css", web.serveFile("main.css", "text/css"))
24 rootRouter.Handle("GET /favicon-16x16.png", web.serveFile("favicon-16x16.png", "image/png"))
25 rootRouter.Handle("GET /favicon.ico", web.serveFile("favicon.ico", "image/x-icon"))
+2,
-0
1@@ -19,6 +19,7 @@ import (
2 "github.com/picosh/pico/db/postgres"
3 "github.com/picosh/pico/shared"
4 "github.com/picosh/utils/pipe"
5+ "github.com/prometheus/client_golang/prometheus/promhttp"
6 )
7
8 var (
9@@ -387,6 +388,7 @@ func createMainRoutes(staticRoutes []shared.Route) []shared.Route {
10 routes := []shared.Route{
11 shared.NewRoute("GET", "/", shared.CreatePageHandler("html/marketing.page.tmpl")),
12 shared.NewRoute("GET", "/check", shared.CheckHandler),
13+ shared.NewRoute("GET", "/_metrics", promhttp.Handler().ServeHTTP),
14 }
15
16 pipeRoutes := []shared.Route{
+2,
-0
1@@ -20,6 +20,7 @@ import (
2 "github.com/picosh/pico/shared"
3 "github.com/picosh/pico/shared/storage"
4 "github.com/picosh/utils"
5+ "github.com/prometheus/client_golang/prometheus/promhttp"
6 )
7
8 type PageData struct {
9@@ -836,6 +837,7 @@ func createMainRoutes(staticRoutes []shared.Route) []shared.Route {
10 shared.NewRoute("GET", "/read", readHandler),
11 shared.NewRoute("GET", "/check", shared.CheckHandler),
12 shared.NewRoute("GET", "/rss", rssHandler),
13+ shared.NewRoute("GET", "/_metrics", promhttp.Handler().ServeHTTP),
14 }
15
16 routes = append(