@@ -18,6 +18,8 @@ import (
1818 "time"
1919
2020 "calmh.dev/proxy"
21+ "github.com/prometheus/client_golang/prometheus"
22+ "github.com/prometheus/client_golang/prometheus/promauto"
2123 "github.com/prometheus/client_golang/prometheus/promhttp"
2224 "github.com/syncthing/syncthing/lib/upgrade"
2325 "github.com/thejerf/suture/v4"
3032 listenAddr = cmp .Or (os .Getenv ("LISTEN_ADDRESS" ), ":8080" )
3133 metricsListenAddr = cmp .Or (os .Getenv ("LISTEN_ADDRESS" ), ":8081" )
3234 distsHost = cmp .Or (os .Getenv ("DISTS_HOST" ), "https://syncthing-apt.s3.fr-par.scw.cloud" )
35+
36+ metricFileRequests = promauto .NewCounterVec (prometheus.CounterOpts {
37+ Name : "aptweb_file_requests_total" ,
38+ }, []string {"source" })
39+ metricRedirectAssets = promauto .NewGauge (prometheus.GaugeOpts {
40+ Name : "aptweb_redirect_assets_loaded" ,
41+ })
3342)
3443
3544func main () {
@@ -74,10 +83,12 @@ func main() {
7483 http .Handle ("/dists/" , filtered )
7584
7685 main .Add (asService (func (_ context.Context ) error {
86+ slog .Info ("starting metrics listener" , "addr" , metricsListenAddr )
7787 return http .ListenAndServe (metricsListenAddr , promhttp .Handler ())
7888 }))
7989
8090 main .Add (asService (func (_ context.Context ) error {
91+ slog .Info ("starting service listener" , "addr" , listenAddr )
8192 return http .ListenAndServe (listenAddr , nil )
8293 }))
8394
@@ -121,6 +132,9 @@ type githubRedirector struct {
121132}
122133
123134func (r * githubRedirector ) Serve (ctx context.Context ) error {
135+ slog .Info ("starting GitHub redirector" )
136+ defer slog .Info ("stopping GitHub redirector" )
137+
124138 timer := time .NewTimer (0 )
125139 defer timer .Stop ()
126140 for {
@@ -137,6 +151,7 @@ func (r *githubRedirector) Serve(ctx context.Context) error {
137151 r .mut .Lock ()
138152 r .assets = newAssets
139153 r .mut .Unlock ()
154+ metricRedirectAssets .Set (float64 (len (newAssets )))
140155 timer .Reset (r .refreshInterval )
141156 case <- ctx .Done ():
142157 return ctx .Err ()
@@ -160,10 +175,12 @@ func (r *githubRedirector) ServeHTTP(w http.ResponseWriter, req *http.Request) {
160175
161176 if ok {
162177 http .Redirect (w , req , url , http .StatusTemporaryRedirect )
178+ metricFileRequests .WithLabelValues ("redirect" ).Inc ()
163179 return
164180 }
165181
166182 r .next .ServeHTTP (w , req )
183+ metricFileRequests .WithLabelValues ("proxy" ).Inc ()
167184}
168185
169186func (r * githubRedirector ) fetchGithubReleaseAssets (ctx context.Context , url string ) (map [string ]string , error ) {
0 commit comments