removed the init method in prometheuis.go

This commit is contained in:
Erik Brakkee 2024-08-12 22:06:20 +02:00
parent dfdea81c20
commit 8ef0785165

View File

@ -159,12 +159,35 @@ func clientActive(client models.Client) {
}
func setupPrometheus(mux *http.ServeMux, notifications chan *models.State) {
// go routine that handles incoming events so we don't need to serialize access in some
// other way.
go func() {
for task := range prometheusChannel {
task()
}
}()
// send an event periodically to update the agent and client durations so
// prometheus gets accurate values.
go func() {
timer := time.NewTicker(1 * time.Second)
for {
select {
case <-timer.C:
prometheusChannel <- updateDurations
}
}
}()
// process incoming notifications from converge to update metrics.
go func() {
for {
state := <-notifications
updateMetrics(state)
}
}()
// expose prometheus on a separate port.
mux.Handle("/metrics", promhttp.Handler())
}
@ -191,24 +214,6 @@ func updateDurations() {
}
}
func init() {
go func() {
timer := time.NewTicker(1 * time.Second)
for {
select {
case <-timer.C:
prometheusChannel <- updateDurations
}
}
}()
go func() {
for task := range prometheusChannel {
task()
}
}()
}
func updateMetricsImpl(state *models.State) {
// This implemnetation has a small probability that the metric will be in a partially
// initialized state. This is however unlikely. It would lead to in incorrect determination