2019-12-04 06:48:32 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
2019-12-30 07:43:05 +00:00
|
|
|
"go.uber.org/zap"
|
2019-12-04 06:48:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// PrometheusService https://prometheus.io/docs/guides/go-application.
|
|
|
|
type PrometheusService Service
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// NewPrometheusService creates a new service for gathering prometheus metrics.
|
2019-12-30 07:43:05 +00:00
|
|
|
func NewPrometheusService(cfg Config, log *zap.Logger) *Service {
|
|
|
|
if log == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-12-04 06:48:32 +00:00
|
|
|
return &Service{
|
2019-12-30 07:43:05 +00:00
|
|
|
Server: &http.Server{
|
2019-12-04 06:48:32 +00:00
|
|
|
Addr: cfg.Address + ":" + cfg.Port,
|
|
|
|
Handler: promhttp.Handler(),
|
2019-12-30 07:43:05 +00:00
|
|
|
},
|
|
|
|
config: cfg,
|
|
|
|
serviceType: "Prometheus",
|
|
|
|
log: log.With(zap.String("service", "Prometheus")),
|
2019-12-04 06:48:32 +00:00
|
|
|
}
|
|
|
|
}
|