Skip to content

Commit 01635d5

Browse files
committed
feat: basic metrics
1 parent 0fab993 commit 01635d5

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/syncthing/apt-web
33
go 1.23.4
44

55
require (
6-
calmh.dev/proxy v0.0.0-20241220141533-76ceaea4b336
6+
calmh.dev/proxy v0.0.0-20250605162626-0ab1901de77d
77
github.com/prometheus/client_golang v1.22.0
88
github.com/syncthing/syncthing v1.29.7
99
github.com/thejerf/suture/v4 v4.0.6
@@ -18,15 +18,15 @@ require (
1818
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
1919
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
2020
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
21-
github.com/prometheus/client_model v0.6.1 // indirect
22-
github.com/prometheus/common v0.62.0 // indirect
23-
github.com/prometheus/procfs v0.15.1 // indirect
21+
github.com/prometheus/client_model v0.6.2 // indirect
22+
github.com/prometheus/common v0.64.0 // indirect
23+
github.com/prometheus/procfs v0.16.1 // indirect
2424
github.com/shirou/gopsutil/v4 v4.25.4 // indirect
2525
github.com/tklauser/go-sysconf v0.3.14 // indirect
2626
github.com/tklauser/numcpus v0.9.0 // indirect
2727
github.com/yusufpapurcu/wmi v1.2.4 // indirect
2828
golang.org/x/net v0.40.0 // indirect
29-
golang.org/x/sync v0.14.0 // indirect
29+
golang.org/x/sync v0.15.0 // indirect
3030
golang.org/x/sys v0.33.0 // indirect
3131
golang.org/x/text v0.25.0 // indirect
3232
google.golang.org/protobuf v1.36.6 // indirect

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
calmh.dev/proxy v0.0.0-20241220141533-76ceaea4b336 h1:WiMLnSrAYmsH4SITByG/8PfgTYQUlKr+nSS1UF7JrMk=
2-
calmh.dev/proxy v0.0.0-20241220141533-76ceaea4b336/go.mod h1:jlSCq6Yg3xwM6afXvjPtH4iWY1/b4kXpi0aOnsxxRuI=
1+
calmh.dev/proxy v0.0.0-20250605162626-0ab1901de77d h1:K3mkqetmZAfSIEVhHL8GISfoN7+7Z1K3j8XRSG4NcJ4=
2+
calmh.dev/proxy v0.0.0-20250605162626-0ab1901de77d/go.mod h1:6AAJhpuPPthXPB4nkWL6DO0NyAw4qn4Jk/QTw1sj/Ec=
33
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
44
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
55
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
@@ -30,12 +30,12 @@ github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt
3030
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
3131
github.com/prometheus/client_golang v1.22.0 h1:rb93p9lokFEsctTys46VnV1kLCDpVZ0a/Y92Vm0Zc6Q=
3232
github.com/prometheus/client_golang v1.22.0/go.mod h1:R7ljNsLXhuQXYZYtw6GAE9AZg8Y7vEW5scdCXrWRXC0=
33-
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
34-
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
35-
github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io=
36-
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
37-
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
38-
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
33+
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
34+
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
35+
github.com/prometheus/common v0.64.0 h1:pdZeA+g617P7oGv1CzdTzyeShxAGrTBsolKNOLQPGO4=
36+
github.com/prometheus/common v0.64.0/go.mod h1:0gZns+BLRQ3V6NdaerOhMbwwRbNh9hkGINtQAsP5GS8=
37+
github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg=
38+
github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is=
3939
github.com/shirou/gopsutil/v4 v4.25.4 h1:cdtFO363VEOOFrUCjZRh4XVJkb548lyF0q0uTeMqYPw=
4040
github.com/shirou/gopsutil/v4 v4.25.4/go.mod h1:xbuxyoZj+UsgnZrENu3lQivsngRR5BdjbJwf2fv4szA=
4141
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
@@ -52,8 +52,8 @@ github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo
5252
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
5353
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
5454
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
55-
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
56-
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
55+
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
56+
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
5757
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
5858
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
5959
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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"
@@ -30,6 +32,13 @@ var (
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

3544
func 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

123134
func (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

169186
func (r *githubRedirector) fetchGithubReleaseAssets(ctx context.Context, url string) (map[string]string, error) {

0 commit comments

Comments
 (0)