-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separates debug and metrics server
* moves metrics to separate server
- Loading branch information
1 parent
a4982fc
commit 709729a
Showing
4 changed files
with
110 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package relayermetrics | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"net/http" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// StartMetricsServer starts a metrics server in a background goroutine, | ||
// accepting connections on the given listener. | ||
// Any HTTP logging will be written at info level to the given logger. | ||
// The server will be forcefully shut down when ctx finishes. | ||
func StartMetricsServer(ctx context.Context, log *zap.Logger, ln net.Listener, registry *prometheus.Registry) { | ||
// Set up new mux identical to the default mux configuration in net/http/pprof. | ||
mux := http.NewServeMux() | ||
|
||
// Serve default prometheus metrics | ||
mux.Handle("/metrics", promhttp.Handler()) | ||
|
||
// Serve relayer metrics | ||
mux.Handle("/relayer/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{})) | ||
|
||
srv := &http.Server{ | ||
Handler: mux, | ||
ErrorLog: zap.NewStdLog(log), | ||
BaseContext: func(net.Listener) context.Context { | ||
return ctx | ||
}, | ||
} | ||
|
||
go srv.Serve(ln) | ||
|
||
go func() { | ||
<-ctx.Done() | ||
srv.Close() | ||
}() | ||
} |