mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
0b4e03f5fc
With go 1.17 a change to the build flags was implemented: https://go.googlesource.com/proposal/+/master/design/draft-gobuild.md The formatter now automatically adds the forward-compatible build tag format and the linter checks for them, so we need to include them in our code.
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
//go:build monitoring
|
|
// +build monitoring
|
|
|
|
package monitoring
|
|
|
|
import (
|
|
"net/http"
|
|
"sync"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
|
"github.com/lightningnetwork/lnd/lncfg"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
)
|
|
|
|
var started sync.Once
|
|
|
|
// GetPromInterceptors returns the set of interceptors for Prometheus
|
|
// monitoring.
|
|
func GetPromInterceptors() ([]grpc.UnaryServerInterceptor, []grpc.StreamServerInterceptor) {
|
|
unaryInterceptors := []grpc.UnaryServerInterceptor{
|
|
grpc_prometheus.UnaryServerInterceptor,
|
|
}
|
|
streamInterceptors := []grpc.StreamServerInterceptor{
|
|
grpc_prometheus.StreamServerInterceptor,
|
|
}
|
|
return unaryInterceptors, streamInterceptors
|
|
}
|
|
|
|
// ExportPrometheusMetrics sets server options, registers gRPC metrics and
|
|
// launches the Prometheus exporter on the specified address.
|
|
func ExportPrometheusMetrics(grpcServer *grpc.Server, cfg lncfg.Prometheus) error {
|
|
started.Do(func() {
|
|
log.Infof("Prometheus exporter started on %v/metrics", cfg.Listen)
|
|
|
|
grpc_prometheus.Register(grpcServer)
|
|
|
|
http.Handle("/metrics", promhttp.Handler())
|
|
go func() {
|
|
http.ListenAndServe(cfg.Listen, nil)
|
|
}()
|
|
})
|
|
|
|
return nil
|
|
}
|