@@ -15,6 +15,9 @@ import (
1515 "sync"
1616 "time"
1717
18+ grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
19+ "github.com/prometheus/client_golang/prometheus/promhttp"
20+
1821 gateway "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
1922 flags "github.com/jessevdk/go-flags"
2023 "github.com/lightninglabs/aperture/auth"
@@ -651,6 +654,15 @@ func createProxy(cfg *Config, challenger *LndChallenger,
651654 return nil , nil , err
652655 }
653656
657+ // Ensure we spin up the necessary HTTP server to allow
658+ // promtheus to scrape us.
659+ go func () {
660+ http .Handle ("/metrics" , promhttp .Handler ())
661+ fmt .Println (http .ListenAndServe (
662+ cfg .HashMail .PromListenAddr , nil ),
663+ )
664+ }()
665+
654666 localServices = append (localServices , hashMailServices ... )
655667 proxyCleanup = cleanup
656668 }
@@ -673,12 +685,26 @@ func createProxy(cfg *Config, challenger *LndChallenger,
673685func createHashMailServer (cfg * Config ) ([]proxy.LocalService , func (), error ) {
674686 var localServices []proxy.LocalService
675687
688+ // Before we register both servers, we'll also ensure that the
689+ // collector will export latency metrics for the histogram.
690+ grpc_prometheus .EnableHandlingTimeHistogram ()
691+
692+ var serverOpts []grpc.ServerOption
693+ serverOpts = []grpc.ServerOption {
694+ grpc .ChainUnaryInterceptor (
695+ grpc_prometheus .UnaryServerInterceptor ,
696+ ),
697+ grpc .ChainStreamInterceptor (
698+ grpc_prometheus .StreamServerInterceptor ,
699+ ),
700+ }
701+
676702 // Create a gRPC server for the hashmail server.
677703 hashMailServer := newHashMailServer (hashMailServerConfig {
678704 msgRate : cfg .HashMail .MessageRate ,
679705 msgBurstAllowance : cfg .HashMail .MessageBurstAllowance ,
680706 })
681- hashMailGRPC := grpc .NewServer ()
707+ hashMailGRPC := grpc .NewServer (serverOpts ... )
682708 hashmailrpc .RegisterHashMailServer (hashMailGRPC , hashMailServer )
683709 localServices = append (localServices , proxy .NewLocalService (
684710 hashMailGRPC , func (r * http.Request ) bool {
0 commit comments