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.
36 lines
773 B
36 lines
773 B
4 years ago
|
package prometheus
|
||
4 years ago
|
|
||
|
import (
|
||
4 years ago
|
"fmt"
|
||
4 years ago
|
"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
|
||
4 years ago
|
func PromPusher(config PrometheusConfig) *push.Pusher {
|
||
4 years ago
|
onceForPusher.Do(func() {
|
||
|
if registry == nil {
|
||
|
registry = prometheus.NewRegistry()
|
||
|
}
|
||
4 years ago
|
pusher = push.New(config.Gateway, fmt.Sprintf("%s/%d", config.Network, config.Shard)).
|
||
4 years ago
|
Gatherer(registry).
|
||
4 years ago
|
Grouping("instance", config.Instance)
|
||
4 years ago
|
})
|
||
|
return pusher
|
||
|
}
|
||
|
|
||
|
func PromRegistry() *prometheus.Registry {
|
||
|
if registry == nil {
|
||
|
registry = prometheus.NewRegistry()
|
||
|
}
|
||
|
return registry
|
||
|
}
|