Initial commit
This commit is contained in:
27
metric/register.go
Normal file
27
metric/register.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package metric
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// Register Here, we must decide pusher/exporter which we use
|
||||
// it's very important, note: var/init/func init sort
|
||||
// keep, when a git rep, not only a service or job
|
||||
// collector will mixed with Push And Registered for pull
|
||||
// So register with pull and add for push collector must control in one place
|
||||
// then we can use conf to switch
|
||||
// avoid collector duplicate
|
||||
// we don't use must register, to avoid panic
|
||||
func Register(cs ...prometheus.Collector) {
|
||||
if defaultPusher == nil {
|
||||
// register by exporter
|
||||
for _, mv := range cs {
|
||||
prometheus.Register(mv)
|
||||
}
|
||||
} else {
|
||||
// register by pusher
|
||||
for _, mv := range cs {
|
||||
defaultPusher.Collector(mv).Add()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user