2020-05-19 23:13:01 +02:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2020-05-19 23:24:16 +02:00
|
|
|
"regexp"
|
2020-05-19 23:13:01 +02:00
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
2020-05-19 23:24:16 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
2020-05-19 23:13:01 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
Durations = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
|
|
|
Namespace: "ytsync",
|
|
|
|
Subsystem: getHostname(),
|
|
|
|
Name: "duration",
|
|
|
|
Help: "The durations of the individual modules",
|
|
|
|
}, []string{"path"})
|
|
|
|
)
|
|
|
|
|
|
|
|
func getHostname() string {
|
|
|
|
hostname, err := os.Hostname()
|
|
|
|
if err != nil {
|
2020-05-19 23:24:16 +02:00
|
|
|
hostname = "ytsync_unknown"
|
2020-05-19 23:13:01 +02:00
|
|
|
}
|
2020-05-19 23:24:16 +02:00
|
|
|
reg, err := regexp.Compile("[^a-zA-Z0-9_]+")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
return reg.ReplaceAllString(hostname, "_")
|
2020-05-19 23:13:01 +02:00
|
|
|
}
|