Skip to content

Commit

Permalink
rpcserver+monitoring/config: enable Prometheus monitoring.
Browse files Browse the repository at this point in the history
Start the Prometheus exporter in rpcserver.go if monitoring is enabled through the
build tag. Also allow users to specify what address they want the Prometheus
exporter to be listening on.
  • Loading branch information
valentinewallace committed May 31, 2019
1 parent 1b6b94b commit 0c2ca1b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
2 changes: 2 additions & 0 deletions config.go
Expand Up @@ -307,6 +307,8 @@ type config struct {
Workers *lncfg.Workers `group:"workers" namespace:"workers"`

Caches *lncfg.Caches `group:"caches" namespace:"caches"`

Prometheus *lncfg.PrometheusConfig `group:"prometheus" namespace:"prometheus"`
}

// loadConfig initializes and parses the config using a config file and command
Expand Down
7 changes: 7 additions & 0 deletions lncfg/monitoring_off.go
@@ -0,0 +1,7 @@
// !build monitoring

package lncfg

type PrometheusConfig struct {
ListenAddr string `long:"listenaddr" description:"the interface we should listen on for prometheus"`
}
11 changes: 11 additions & 0 deletions lncfg/monitoring_on.go
@@ -0,0 +1,11 @@
// +build monitoring

package lncfg

// PrometheusConfig is the set of configuration data that specifies
// the listening address of the Prometheus exporter.
type PrometheusConfig struct {
// ListenAddr is the listening address that we should use to allow the
// main Prometheus server to scrape our metrics.
ListenAddr string `long:"listenaddr" description:"the interface we should listen on for prometheus"`
}
25 changes: 9 additions & 16 deletions rpcserver.go
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/monitoring"
"github.com/lightningnetwork/lnd/routing"
"github.com/lightningnetwork/lnd/signal"
"github.com/lightningnetwork/lnd/sweep"
Expand Down Expand Up @@ -529,24 +530,9 @@ func newRPCServer(s *server, macService *macaroons.Service,
}
}

// If macaroons aren't disabled (a non-nil service), then we'll set up
// our set of interceptors which will allow us handle the macaroon
// authentication in a single location .
if macService != nil {
unaryInterceptor := grpc.UnaryInterceptor(
macService.UnaryServerInterceptor(permissions),
)
streamInterceptor := grpc.StreamInterceptor(
macService.StreamServerInterceptor(permissions),
)

serverOpts = append(serverOpts,
unaryInterceptor, streamInterceptor,
)
}

// Finally, with all the pre-set up complete, we can create the main
// gRPC server, and register the main lnrpc server along side.
serverOpts = monitoring.GetServerOpts(macService, permissions, serverOpts)
grpcServer := grpc.NewServer(serverOpts...)
rootRPCServer := &rpcServer{
restDialOpts: restDialOpts,
Expand Down Expand Up @@ -615,6 +601,13 @@ func (r *rpcServer) Start() error {
}()
}

// If monitoring is enabled, start the Prometheus exporter.
if monitoring.Enabled {
monitoring.ExportPrometheusMetrics(
r.grpcServer, cfg.Prometheus.ListenAddr,
)
}

// Finally, start the REST proxy for our gRPC server above. We'll ensure
// we direct LND to connect to its loopback address rather than a
// wildcard to prevent certificate issues when accessing the proxy
Expand Down

0 comments on commit 0c2ca1b

Please sign in to comment.