From fc58176e80800c206e61b720f2169b6b8c344e4e Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Thu, 11 Nov 2021 21:11:54 +0530 Subject: [PATCH 1/6] Added Prometheus flag on bor-cli --- command/server/config.go | 11 +++++++++++ command/server/server.go | 30 ++++++++++++++++++++++++++++++ go.mod | 7 +++++-- go.sum | 19 ++++++++++++------- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/command/server/config.go b/command/server/config.go index e25870a645..34fa13cf51 100644 --- a/command/server/config.go +++ b/command/server/config.go @@ -88,6 +88,9 @@ type Config struct { // GRPC has the grpc server related settings GRPC *GRPCConfig + + // Prometheus Server + Prometheus *PrometheusConfig `hcl:"prometheus,optional"` } type P2PConfig struct { @@ -236,6 +239,14 @@ type GRPCConfig struct { Addr string } +type PrometheusConfig struct { + // Enabled selects whether the api is enabled + Enabled bool `hcl:"enabled,optional"` + + // Host is the address to bind the api + address string `hcl:"host,optional"` +} + type APIConfig struct { // Enabled selects whether the api is enabled Enabled bool `hcl:"enabled,optional"` diff --git a/command/server/server.go b/command/server/server.go index 437a39b906..5981f0cf48 100644 --- a/command/server/server.go +++ b/command/server/server.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "net" + "net/http" "os" "strings" "time" @@ -17,13 +18,17 @@ import ( "github.com/ethereum/go-ethereum/graphql" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" + "github.com/ethereum/go-ethereum/metrics/exp" "github.com/ethereum/go-ethereum/metrics/influxdb" "github.com/ethereum/go-ethereum/node" + "github.com/fjl/memsize/memsizeui" "github.com/mattn/go-colorable" "github.com/mattn/go-isatty" "google.golang.org/grpc" ) +var Memsize memsizeui.Handler + type Server struct { proto.UnimplementedBorServer node *node.Node @@ -45,6 +50,11 @@ func NewServer(config *Config) (*Server, error) { return nil, err } + // start the Prometheus Server + if err := srv.StartPrometheus(config.Prometheus.address, config.Prometheus.Enabled); err != nil { + return nil, err + } + // create the node/stack nodeCfg, err := config.buildNode() if err != nil { @@ -171,6 +181,26 @@ func (s *Server) setupGRPCServer(addr string) error { return nil } +func (s *Server) StartPrometheus(address string, enabled bool) error { + // Hook go-metrics into expvar on any /debug/metrics request, load all vars + // from the registry into expvar, and execute regular expvar handler. + if enabled { + exp.Exp(metrics.DefaultRegistry) + } + + http.Handle("/memsize/", http.StripPrefix("/memsize", &Memsize)) + + log.Info("Starting pprof server", "addr", fmt.Sprintf("http://%s/debug/pprof", address)) + + go func() { + if err := http.ListenAndServe(address, nil); err != nil { + log.Error("Failure in running pprof server", "err", err) + } + }() + + return nil +} + func (s *Server) withLoggingUnaryInterceptor() grpc.ServerOption { return grpc.UnaryInterceptor(s.loggingServerInterceptor) } diff --git a/go.mod b/go.mod index ee79f9b222..c8bc297a8d 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,8 @@ require ( github.com/fatih/color v1.7.0 github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff + github.com/go-kit/kit v0.9.0 // indirect + github.com/go-logfmt/logfmt v0.5.0 // indirect github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-sourcemap/sourcemap v2.1.2+incompatible // indirect github.com/go-stack/stack v1.8.0 @@ -46,7 +48,7 @@ require ( github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 // indirect github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e - github.com/julienschmidt/httprouter v1.2.0 + github.com/julienschmidt/httprouter v1.3.0 github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356 github.com/kylelemons/godebug v1.1.0 // indirect github.com/mattn/go-colorable v0.1.8 @@ -75,7 +77,8 @@ require ( golang.org/x/text v0.3.6 golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba google.golang.org/grpc v1.37.0 - google.golang.org/protobuf v1.25.0 + google.golang.org/protobuf v1.26.0-rc.1 + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6 gopkg.in/urfave/cli.v1 v1.20.0 diff --git a/go.sum b/go.sum index a8b1df8e13..5cdca30374 100644 --- a/go.sum +++ b/go.sum @@ -167,11 +167,13 @@ github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1T github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0 h1:wDJmvq38kDhkVxi50ni9ykkdUr1PKgqKOoi01fa0Mdk= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4= +github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -222,8 +224,9 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64= github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= @@ -293,8 +296,9 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1 github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jsternberg/zap-logfmt v1.0.0/go.mod h1:uvPs/4X51zdkcm5jXl5SYoN+4RK21K8mysFmDaM/h+o= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/julienschmidt/httprouter v1.2.0 h1:TDTW5Yz1mjftljbcKqRcrYhd4XeOoI98t+9HbQbYf7g= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef/go.mod h1:Ct9fl0F6iIOGgxJ5npU/IUOhOhqlVrGjyIZc8/MagT0= github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356 h1:I/yrLt2WilKxlQKCM52clh5rGzTKpVctGT1lH4Dc8Jw= @@ -307,7 +311,6 @@ github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5/go.mod h1:Pj4uuM52 github.com/klauspost/crc32 v0.0.0-20161016154125-cb6bfca970f6/go.mod h1:+ZoRqAPRLkC4NPOvfYeR5KNOrY6TD+/sAC3HXPZgDYg= github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -696,12 +699,14 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1 h1:7QnIQpGRHE5RnLKnESfDoxm2dTapTZua5a0kS0A+VXQ= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= From f3a43f947261a0d7b96628c6c059b89e180acc5a Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 12 Nov 2021 13:13:28 +0530 Subject: [PATCH 2/6] Added Prometheus to New CLI: fixes --- command/server/config.go | 14 +++------- command/server/server.go | 57 ++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/command/server/config.go b/command/server/config.go index 34fa13cf51..dd3f5dce95 100644 --- a/command/server/config.go +++ b/command/server/config.go @@ -88,9 +88,6 @@ type Config struct { // GRPC has the grpc server related settings GRPC *GRPCConfig - - // Prometheus Server - Prometheus *PrometheusConfig `hcl:"prometheus,optional"` } type P2PConfig struct { @@ -239,14 +236,6 @@ type GRPCConfig struct { Addr string } -type PrometheusConfig struct { - // Enabled selects whether the api is enabled - Enabled bool `hcl:"enabled,optional"` - - // Host is the address to bind the api - address string `hcl:"host,optional"` -} - type APIConfig struct { // Enabled selects whether the api is enabled Enabled bool `hcl:"enabled,optional"` @@ -286,6 +275,9 @@ type TelemetryConfig struct { // InfluxDB has the influxdb related settings InfluxDB *InfluxDBConfig `hcl:"influx,block"` + + // Prometheus Address + PrometheusAddr string `hcl:"prometheus-addr,optional"` } type InfluxDBConfig struct { diff --git a/command/server/server.go b/command/server/server.go index 5981f0cf48..2c06804cc6 100644 --- a/command/server/server.go +++ b/command/server/server.go @@ -20,6 +20,7 @@ import ( "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/metrics/exp" "github.com/ethereum/go-ethereum/metrics/influxdb" + "github.com/ethereum/go-ethereum/metrics/prometheus" "github.com/ethereum/go-ethereum/node" "github.com/fjl/memsize/memsizeui" "github.com/mattn/go-colorable" @@ -50,11 +51,6 @@ func NewServer(config *Config) (*Server, error) { return nil, err } - // start the Prometheus Server - if err := srv.StartPrometheus(config.Prometheus.address, config.Prometheus.Enabled); err != nil { - return nil, err - } - // create the node/stack nodeCfg, err := config.buildNode() if err != nil { @@ -159,6 +155,42 @@ func (s *Server) setupMetrics(config *TelemetryConfig) error { // Start system runtime metrics collection go metrics.CollectProcessMetrics(3 * time.Second) + // Hook go-metrics into expvar on any /debug/metrics request, load all vars + // from the registry into expvar, and execute regular expvar handler. + + if len(config.PrometheusAddr) != 0 { + + prometheusMux := http.NewServeMux() + + // this would cause a panic: + // panic: http: multiple registrations for /debug/vars + // http.HandleFunc("/debug/vars", e.expHandler) + // haven't found an elegant way, so just use a different endpoint + + prometheusMux.HandleFunc("/debug/metrics", func(w http.ResponseWriter, r *http.Request) { + exp.ExpHandler(metrics.DefaultRegistry) + }) + + prometheusMux.HandleFunc("/debug/metrics/prometheus", func(w http.ResponseWriter, r *http.Request) { + prometheus.Handler(metrics.DefaultRegistry) + }) + + promServer := &http.Server{ + Addr: config.PrometheusAddr, + Handler: prometheusMux, + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + MaxHeaderBytes: 1 << 20, + } + + go func() { + if err := promServer.ListenAndServe(); err != nil { + log.Error("Failure in running Prometheus server", "err", err) + } + }() + + } + return nil } @@ -182,21 +214,6 @@ func (s *Server) setupGRPCServer(addr string) error { } func (s *Server) StartPrometheus(address string, enabled bool) error { - // Hook go-metrics into expvar on any /debug/metrics request, load all vars - // from the registry into expvar, and execute regular expvar handler. - if enabled { - exp.Exp(metrics.DefaultRegistry) - } - - http.Handle("/memsize/", http.StripPrefix("/memsize", &Memsize)) - - log.Info("Starting pprof server", "addr", fmt.Sprintf("http://%s/debug/pprof", address)) - - go func() { - if err := http.ListenAndServe(address, nil); err != nil { - log.Error("Failure in running pprof server", "err", err) - } - }() return nil } From c23cd5e3326a970fcf5714f4e8806c61d2934ac2 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 12 Nov 2021 13:18:08 +0530 Subject: [PATCH 3/6] minor Clean --- command/server/server.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/command/server/server.go b/command/server/server.go index 2c06804cc6..09f33d4c80 100644 --- a/command/server/server.go +++ b/command/server/server.go @@ -213,11 +213,6 @@ func (s *Server) setupGRPCServer(addr string) error { return nil } -func (s *Server) StartPrometheus(address string, enabled bool) error { - - return nil -} - func (s *Server) withLoggingUnaryInterceptor() grpc.ServerOption { return grpc.UnaryInterceptor(s.loggingServerInterceptor) } From a5bcab1c658a008446bf6b1895be72fe4016b872 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 12 Nov 2021 14:24:21 +0530 Subject: [PATCH 4/6] Minor Clean-up --- command/server/server.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/command/server/server.go b/command/server/server.go index 09f33d4c80..c19f7af713 100644 --- a/command/server/server.go +++ b/command/server/server.go @@ -18,7 +18,6 @@ import ( "github.com/ethereum/go-ethereum/graphql" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" - "github.com/ethereum/go-ethereum/metrics/exp" "github.com/ethereum/go-ethereum/metrics/influxdb" "github.com/ethereum/go-ethereum/metrics/prometheus" "github.com/ethereum/go-ethereum/node" @@ -158,7 +157,7 @@ func (s *Server) setupMetrics(config *TelemetryConfig) error { // Hook go-metrics into expvar on any /debug/metrics request, load all vars // from the registry into expvar, and execute regular expvar handler. - if len(config.PrometheusAddr) != 0 { + if config.PrometheusAddr != "" { prometheusMux := http.NewServeMux() @@ -167,20 +166,13 @@ func (s *Server) setupMetrics(config *TelemetryConfig) error { // http.HandleFunc("/debug/vars", e.expHandler) // haven't found an elegant way, so just use a different endpoint - prometheusMux.HandleFunc("/debug/metrics", func(w http.ResponseWriter, r *http.Request) { - exp.ExpHandler(metrics.DefaultRegistry) - }) - - prometheusMux.HandleFunc("/debug/metrics/prometheus", func(w http.ResponseWriter, r *http.Request) { + prometheusMux.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) { prometheus.Handler(metrics.DefaultRegistry) }) promServer := &http.Server{ - Addr: config.PrometheusAddr, - Handler: prometheusMux, - ReadTimeout: 10 * time.Second, - WriteTimeout: 10 * time.Second, - MaxHeaderBytes: 1 << 20, + Addr: config.PrometheusAddr, + Handler: prometheusMux, } go func() { From cd6a1633917002b9ef42499cb5768de74ad4fff5 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 12 Nov 2021 14:51:18 +0530 Subject: [PATCH 5/6] minor cleanup --- command/server/server.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/command/server/server.go b/command/server/server.go index c19f7af713..be745ecce2 100644 --- a/command/server/server.go +++ b/command/server/server.go @@ -21,14 +21,11 @@ import ( "github.com/ethereum/go-ethereum/metrics/influxdb" "github.com/ethereum/go-ethereum/metrics/prometheus" "github.com/ethereum/go-ethereum/node" - "github.com/fjl/memsize/memsizeui" "github.com/mattn/go-colorable" "github.com/mattn/go-isatty" "google.golang.org/grpc" ) -var Memsize memsizeui.Handler - type Server struct { proto.UnimplementedBorServer node *node.Node @@ -154,18 +151,10 @@ func (s *Server) setupMetrics(config *TelemetryConfig) error { // Start system runtime metrics collection go metrics.CollectProcessMetrics(3 * time.Second) - // Hook go-metrics into expvar on any /debug/metrics request, load all vars - // from the registry into expvar, and execute regular expvar handler. - if config.PrometheusAddr != "" { prometheusMux := http.NewServeMux() - // this would cause a panic: - // panic: http: multiple registrations for /debug/vars - // http.HandleFunc("/debug/vars", e.expHandler) - // haven't found an elegant way, so just use a different endpoint - prometheusMux.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) { prometheus.Handler(metrics.DefaultRegistry) }) From 358e68364fa507955c5adc0c3438d65616d7b1a3 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 12 Nov 2021 18:54:04 +0530 Subject: [PATCH 6/6] Added Prometheus Flag and Default --- command/server/config.go | 5 +++-- command/server/flags.go | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/command/server/config.go b/command/server/config.go index dd3f5dce95..7f07015a54 100644 --- a/command/server/config.go +++ b/command/server/config.go @@ -441,8 +441,9 @@ func DefaultConfig() *Config { }, Ethstats: "", Telemetry: &TelemetryConfig{ - Enabled: false, - Expensive: false, + Enabled: false, + Expensive: false, + PrometheusAddr: "", InfluxDB: &InfluxDBConfig{ V1Enabled: false, Endpoint: "", diff --git a/command/server/flags.go b/command/server/flags.go index 303e5e9818..9b13cc44bc 100644 --- a/command/server/flags.go +++ b/command/server/flags.go @@ -396,6 +396,11 @@ func (c *Command) Flags() *flagset.Flagset { Usage: "Comma-separated InfluxDB tags (key/values) attached to all measurements", Value: &c.cliConfig.Telemetry.InfluxDB.Tags, }) + f.StringFlag(&flagset.StringFlag{ + Name: "metrics.prometheus-addr", + Usage: "Address for Prometheus Server", + Value: &c.cliConfig.Telemetry.PrometheusAddr, + }) // influx db v2 f.BoolFlag(&flagset.BoolFlag{ Name: "metrics.influxdbv2",