add feature for live-reload when configuration changed

Signed-off-by: x893675 <x893675@icloud.com>
This commit is contained in:
x893675
2022-02-07 16:47:43 +08:00
parent b8e1261989
commit 2a521bb157
20 changed files with 189 additions and 60 deletions

View File

@@ -19,6 +19,7 @@ package metrics
import (
"net/http"
"sync"
"github.com/emicklei/go-restful"
"github.com/prometheus/client_golang/prometheus"
@@ -30,6 +31,8 @@ import (
)
var (
registerOnce sync.Once
Defaults DefaultMetrics
defaultRegistry compbasemetrics.KubeRegistry
// MustRegister registers registerable metrics but uses the defaultRegistry, panic upon the first registration that causes an error
@@ -54,10 +57,13 @@ type DefaultMetrics struct{}
// Install adds the DefaultMetrics handler
func (m DefaultMetrics) Install(c *restful.Container) {
registerOnce.Do(m.registerMetrics)
c.Handle("/kapis/metrics", Handler())
}
func (m DefaultMetrics) registerMetrics() {
RawMustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
RawMustRegister(prometheus.NewGoCollector())
c.Handle("/kapis/metrics", Handler())
}
//Overwrite version.Get