mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 15:58:37 +00:00
Ensure container metrics are registered with prometheus even without
cadvisor http server Fixes #13200
This commit is contained in:
parent
b87077c270
commit
3a6701c85f
@ -64,13 +64,10 @@ func New(port uint) (Interface, error) {
|
||||
Manager: m,
|
||||
}
|
||||
|
||||
// Export the HTTP endpoint if a port was specified.
|
||||
if port > 0 {
|
||||
err = cadvisorClient.exportHTTP(port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return cadvisorClient, nil
|
||||
}
|
||||
|
||||
@ -79,12 +76,16 @@ func (cc *cadvisorClient) Start() error {
|
||||
}
|
||||
|
||||
func (cc *cadvisorClient) exportHTTP(port uint) error {
|
||||
// Register the handlers regardless as this registers the prometheus
|
||||
// collector properly.
|
||||
mux := http.NewServeMux()
|
||||
err := cadvisorHttp.RegisterHandlers(mux, cc, "", "", "", "", "/metrics")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Only start the http server if port > 0
|
||||
if port > 0 {
|
||||
serv := &http.Server{
|
||||
Addr: fmt.Sprintf(":%d", port),
|
||||
Handler: mux,
|
||||
@ -103,6 +104,7 @@ func (cc *cadvisorClient) exportHTTP(port uint) error {
|
||||
err = serv.ListenAndServe()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user