Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite4fc41b

Browse files
committed
feat: expose DERP server debug metrics
1 parent53c5543 commite4fc41b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎coderd/coderd.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/tls"
66
"crypto/x509"
77
"database/sql"
8+
"expvar"
89
"flag"
910
"fmt"
1011
"io"
@@ -85,6 +86,8 @@ func init() {
8586
globalHTTPSwaggerHandler=httpSwagger.Handler(httpSwagger.URL("/swagger/doc.json"))
8687
}
8788

89+
varexpDERPOnce= sync.Once{}
90+
8891
// Options are requires parameters for Coder to start.
8992
typeOptionsstruct {
9093
AccessURL*url.URL
@@ -561,6 +564,16 @@ func New(options *Options) *API {
561564

562565
derpHandler:=derphttp.Handler(api.DERPServer)
563566
derpHandler,api.derpCloseFunc=tailnet.WithWebsocketSupport(api.DERPServer,derpHandler)
567+
// Register DERP on expvar HTTP handler, which we serve below in the router, c.f. expvar.Handler()
568+
// These are the metrics the DERP server exposes.
569+
// TODO: export via prometheus
570+
expDERPOnce.Do(func() {
571+
// We need to do this via a global Once because expvar registry is global and panics if we
572+
// register multiple times. In production there is only one Coderd and one DERP server per
573+
// process, but in testing, we create multiple of both, so the Once protects us from
574+
// panicking.
575+
expvar.Publish("derp",api.DERPServer.ExpVar())
576+
})
564577
cors:=httpmw.Cors(options.DeploymentValues.Dangerous.AllowAllCors.Value())
565578
prometheusMW:=httpmw.Prometheus(options.PrometheusRegistry)
566579

@@ -1038,6 +1051,10 @@ func New(options *Options) *API {
10381051
r.Use(httpmw.ExtractUserParam(options.Database))
10391052
r.Get("/debug-link",api.userDebugOIDC)
10401053
})
1054+
r.Route("/derp",func(r chi.Router) {
1055+
r.Get("/traffic",options.DERPServer.ServeDebugTraffic)
1056+
})
1057+
r.Mount("/expvar",expvar.Handler())// contains DERP metrics as well as cmdline and memstats
10411058
})
10421059
})
10431060

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp