The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
woop/api/service/prometheus/pushgateway.go

35 lines
773 B

package prometheus
import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/push"
"sync"
)
var (
// Prometheus Pusher
onceForPusher sync.Once
pusher *push.Pusher
registry *prometheus.Registry
)
// Pusher returns the pusher, initialized once only
func PromPusher(config PrometheusConfig) *push.Pusher {
onceForPusher.Do(func() {
if registry == nil {
registry = prometheus.NewRegistry()
}
pusher = push.New(config.Gateway, fmt.Sprintf("%s/%d", config.Network, config.Shard)).
Gatherer(registry).
Grouping("instance", config.Instance)
})
return pusher
}
func PromRegistry() *prometheus.Registry {
if registry == nil {
registry = prometheus.NewRegistry()
}
return registry
}