2019-12-04 06:48:32 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2022-07-08 16:10:46 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
2019-12-04 06:48:32 +00:00
|
|
|
"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.
|
2022-07-08 16:10:46 +00:00
|
|
|
func NewPrometheusService(cfg config.BasicService, log *zap.Logger) *Service {
|
2019-12-30 07:43:05 +00:00
|
|
|
if log == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-09 20:02:15 +00:00
|
|
|
addrs := cfg.Addresses
|
2022-11-25 10:20:53 +00:00
|
|
|
srvs := make([]*http.Server, len(addrs))
|
|
|
|
for i, addr := range addrs {
|
|
|
|
srvs[i] = &http.Server{
|
|
|
|
Addr: addr,
|
|
|
|
Handler: promhttp.Handler(), // share metrics between multiple prometheus handlers
|
|
|
|
}
|
2019-12-04 06:48:32 +00:00
|
|
|
}
|
2022-11-25 10:20:53 +00:00
|
|
|
return NewService("Prometheus", srvs, cfg, log)
|
2019-12-04 06:48:32 +00:00
|
|
|
}
|