diff --git a/cmd/blobindexer/blobindexer.go b/cmd/blobindexer/blobindexer.go index b026eb3419..4ccc0815fd 100644 --- a/cmd/blobindexer/blobindexer.go +++ b/cmd/blobindexer/blobindexer.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/gobitfly/eth2-beaconchain-explorer/exporter" + "github.com/gobitfly/eth2-beaconchain-explorer/metrics" "github.com/gobitfly/eth2-beaconchain-explorer/types" "github.com/gobitfly/eth2-beaconchain-explorer/utils" "github.com/gobitfly/eth2-beaconchain-explorer/version" @@ -25,6 +26,14 @@ func main() { if err != nil { logrus.Fatal(err) } + if utils.Config.Metrics.Enabled { + go func(addr string) { + logrus.Infof("serving metrics on %v", addr) + if err := metrics.Serve(addr); err != nil { + logrus.WithError(err).Fatal("Error serving metrics") + } + }(utils.Config.Metrics.Address) + } blobIndexer, err := exporter.NewBlobIndexer() if err != nil { logrus.Fatal(err) diff --git a/cmd/eth1indexer/main.go b/cmd/eth1indexer/main.go index 098a2e3086..1f435ec12b 100644 --- a/cmd/eth1indexer/main.go +++ b/cmd/eth1indexer/main.go @@ -73,8 +73,6 @@ func main() { enableEnsUpdater := flag.Bool("ens.enabled", false, "Enable ens update process") ensBatchSize := flag.Int64("ens.batch", 200, "Batch size for ens updates") - metricsAddr := flag.String("metrics.addr", "", "Metrics address to listen on (eg: :8080)") - flag.Parse() if *versionFlag { @@ -91,13 +89,13 @@ func main() { utils.Config = cfg logrus.WithField("config", *configPath).WithField("version", version.Version).WithField("chainName", utils.Config.Chain.ClConfig.ConfigName).Printf("starting") - if *metricsAddr != "" { + if utils.Config.Metrics.Enabled { go func(addr string) { logrus.Infof("serving metrics on %v", addr) if err := metrics.Serve(addr); err != nil { logrus.WithError(err).Fatal("Error serving metrics") } - }(*metricsAddr) + }(utils.Config.Metrics.Address) } // enable pprof endpoint if requested diff --git a/cmd/ethstore-exporter/main.go b/cmd/ethstore-exporter/main.go index 9a9ebd4a80..972fd76b30 100644 --- a/cmd/ethstore-exporter/main.go +++ b/cmd/ethstore-exporter/main.go @@ -8,6 +8,7 @@ import ( "github.com/gobitfly/eth2-beaconchain-explorer/db" "github.com/gobitfly/eth2-beaconchain-explorer/exporter" + "github.com/gobitfly/eth2-beaconchain-explorer/metrics" "github.com/gobitfly/eth2-beaconchain-explorer/types" "github.com/gobitfly/eth2-beaconchain-explorer/utils" "github.com/gobitfly/eth2-beaconchain-explorer/version" @@ -47,6 +48,15 @@ func main() { utils.Config = cfg logrus.WithField("config", *configPath).WithField("version", version.Version).WithField("chainName", utils.Config.Chain.ClConfig.ConfigName).Printf("starting") + if utils.Config.Metrics.Enabled { + go func(addr string) { + logrus.Infof("serving metrics on %v", addr) + if err := metrics.Serve(addr); err != nil { + logrus.WithError(err).Fatal("Error serving metrics") + } + }(utils.Config.Metrics.Address) + } + db.MustInitDB(&types.DatabaseConfig{ Username: cfg.WriterDatabase.Username, Password: cfg.WriterDatabase.Password, diff --git a/cmd/frontend-data-updater/main.go b/cmd/frontend-data-updater/main.go index 131f163df6..44ecddc8a8 100644 --- a/cmd/frontend-data-updater/main.go +++ b/cmd/frontend-data-updater/main.go @@ -7,6 +7,7 @@ import ( "github.com/gobitfly/eth2-beaconchain-explorer/cache" "github.com/gobitfly/eth2-beaconchain-explorer/db" + "github.com/gobitfly/eth2-beaconchain-explorer/metrics" "github.com/gobitfly/eth2-beaconchain-explorer/price" "github.com/gobitfly/eth2-beaconchain-explorer/rpc" "github.com/gobitfly/eth2-beaconchain-explorer/services" @@ -48,6 +49,15 @@ func main() { }() } + if utils.Config.Metrics.Enabled { + go func(addr string) { + logrus.Infof("serving metrics on %v", addr) + if err := metrics.Serve(addr); err != nil { + logrus.WithError(err).Fatal("Error serving metrics") + } + }(utils.Config.Metrics.Address) + } + _, err = db.InitBigtable(cfg.Bigtable.Project, cfg.Bigtable.Instance, fmt.Sprintf("%d", utils.Config.Chain.ClConfig.DepositChainID), utils.Config.RedisCacheEndpoint) if err != nil { logrus.Fatalf("error initializing bigtable %v", err) diff --git a/cmd/node-jobs-processor/main.go b/cmd/node-jobs-processor/main.go index 93bb767015..e83a35d2ea 100644 --- a/cmd/node-jobs-processor/main.go +++ b/cmd/node-jobs-processor/main.go @@ -18,8 +18,6 @@ import ( func main() { configPath := flag.String("config", "", "Path to the config file, if empty string defaults will be used") - metricsAddr := flag.String("metrics.address", "localhost:9090", "serve metrics on that addr") - metricsEnabled := flag.Bool("metrics.enabled", false, "enable serving metrics") versionFlag := flag.Bool("version", false, "Print version and exit") flag.Parse() @@ -37,6 +35,15 @@ func main() { utils.Config = cfg logrus.WithField("config", *configPath).WithField("version", version.Version).WithField("chainName", utils.Config.Chain.ClConfig.ConfigName).Printf("starting") + if utils.Config.Metrics.Enabled { + go func(addr string) { + logrus.Infof("serving metrics on %v", addr) + if err := metrics.Serve(addr); err != nil { + logrus.WithError(err).Fatal("Error serving metrics") + } + }(utils.Config.Metrics.Address) + } + db.MustInitDB(&types.DatabaseConfig{ Username: cfg.WriterDatabase.Username, Password: cfg.WriterDatabase.Password, @@ -62,15 +69,6 @@ func main() { nrp := NewNodeJobsProcessor(utils.Config.NodeJobsProcessor.ClEndpoint, utils.Config.NodeJobsProcessor.ElEndpoint) go nrp.Run() - if *metricsEnabled { - go func() { - logrus.WithFields(logrus.Fields{"addr": *metricsAddr}).Infof("Serving metrics") - if err := metrics.Serve(*metricsAddr); err != nil { - logrus.WithError(err).Fatal("Error serving metrics") - } - }() - } - utils.WaitForCtrlC() logrus.Println("exiting …") } diff --git a/cmd/notification-collector/main.go b/cmd/notification-collector/main.go index 53117ba590..c30e1bfc20 100644 --- a/cmd/notification-collector/main.go +++ b/cmd/notification-collector/main.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "strings" "sync" "github.com/gobitfly/eth2-beaconchain-explorer/cache" @@ -52,6 +51,15 @@ func main() { utils.LogFatal(err, "invalid chain configuration specified, you must specify the slots per epoch, seconds per slot and genesis timestamp in the config file", 0) } + if utils.Config.Metrics.Enabled { + go func(addr string) { + logrus.Infof("serving metrics on %v", addr) + if err := metrics.Serve(addr); err != nil { + logrus.WithError(err).Fatal("Error serving metrics") + } + }(utils.Config.Metrics.Address) + } + if utils.Config.Pprof.Enabled { go func() { logrus.Infof("starting pprof http server on port %s", utils.Config.Pprof.Port) @@ -143,34 +151,6 @@ func main() { defer db.FrontendWriterDB.Close() defer db.BigtableClient.Close() - if utils.Config.Metrics.Enabled { - go metrics.MonitorDB(db.WriterDb) - DBInfo := []string{ - cfg.WriterDatabase.Username, - cfg.WriterDatabase.Password, - cfg.WriterDatabase.Host, - cfg.WriterDatabase.Port, - cfg.WriterDatabase.Name} - DBStr := strings.Join(DBInfo, "-") - frontendDBInfo := []string{ - cfg.Frontend.WriterDatabase.Username, - cfg.Frontend.WriterDatabase.Password, - cfg.Frontend.WriterDatabase.Host, - cfg.Frontend.WriterDatabase.Port, - cfg.Frontend.WriterDatabase.Name} - frontendDBStr := strings.Join(frontendDBInfo, "-") - if DBStr != frontendDBStr { - go metrics.MonitorDB(db.FrontendWriterDB) - } - // serve prometheus metrics - go func(addr string) { - logrus.Infof("serving metrics on %v", addr) - if err := metrics.Serve(addr); err != nil { - logrus.WithError(err).Fatal("Error serving metrics") - } - }(utils.Config.Metrics.Address) - } - logrus.Infof("database connection established") services.InitNotificationCollector(utils.Config.Notifications.PubkeyCachePath) diff --git a/cmd/notification-sender/main.go b/cmd/notification-sender/main.go index 494dca7be9..f00b492caa 100644 --- a/cmd/notification-sender/main.go +++ b/cmd/notification-sender/main.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "strings" "sync" "github.com/gobitfly/eth2-beaconchain-explorer/cache" @@ -52,6 +51,15 @@ func main() { utils.LogFatal(err, "invalid chain configuration specified, you must specify the slots per epoch, seconds per slot and genesis timestamp in the config file", 0) } + if utils.Config.Metrics.Enabled { + go func(addr string) { + logrus.Infof("serving metrics on %v", addr) + if err := metrics.Serve(addr); err != nil { + logrus.WithError(err).Fatal("Error serving metrics") + } + }(utils.Config.Metrics.Address) + } + if utils.Config.Pprof.Enabled { go func() { logrus.Infof("starting pprof http server on port %s", utils.Config.Pprof.Port) @@ -140,34 +148,6 @@ func main() { defer db.FrontendWriterDB.Close() defer db.BigtableClient.Close() - if utils.Config.Metrics.Enabled { - go metrics.MonitorDB(db.WriterDb) - DBInfo := []string{ - cfg.WriterDatabase.Username, - cfg.WriterDatabase.Password, - cfg.WriterDatabase.Host, - cfg.WriterDatabase.Port, - cfg.WriterDatabase.Name} - DBStr := strings.Join(DBInfo, "-") - frontendDBInfo := []string{ - cfg.Frontend.WriterDatabase.Username, - cfg.Frontend.WriterDatabase.Password, - cfg.Frontend.WriterDatabase.Host, - cfg.Frontend.WriterDatabase.Port, - cfg.Frontend.WriterDatabase.Name} - frontendDBStr := strings.Join(frontendDBInfo, "-") - if DBStr != frontendDBStr { - go metrics.MonitorDB(db.FrontendWriterDB) - } - // serve prometheus metrics - go func(addr string) { - logrus.Infof("serving metrics on %v", addr) - if err := metrics.Serve(addr); err != nil { - logrus.WithError(err).Fatal("Error serving metrics") - } - }(utils.Config.Metrics.Address) - } - logrus.Infof("database connection established") services.InitNotificationSender() diff --git a/cmd/rewards-exporter/main.go b/cmd/rewards-exporter/main.go index 5cccff70c9..50076d5c67 100644 --- a/cmd/rewards-exporter/main.go +++ b/cmd/rewards-exporter/main.go @@ -8,6 +8,7 @@ import ( "github.com/gobitfly/eth2-beaconchain-explorer/cache" "github.com/gobitfly/eth2-beaconchain-explorer/db" + "github.com/gobitfly/eth2-beaconchain-explorer/metrics" "github.com/gobitfly/eth2-beaconchain-explorer/services" "github.com/gobitfly/eth2-beaconchain-explorer/types" "github.com/gobitfly/eth2-beaconchain-explorer/utils" @@ -48,6 +49,15 @@ func main() { utils.Config = cfg logrus.WithField("config", *configPath).WithField("version", version.Version).WithField("chainName", utils.Config.Chain.ClConfig.ConfigName).Printf("starting") + if utils.Config.Metrics.Enabled { + go func(addr string) { + logrus.Infof("serving metrics on %v", addr) + if err := metrics.Serve(addr); err != nil { + logrus.WithError(err).Fatal("Error serving metrics") + } + }(utils.Config.Metrics.Address) + } + db.MustInitDB(&types.DatabaseConfig{ Username: cfg.WriterDatabase.Username, Password: cfg.WriterDatabase.Password, diff --git a/cmd/signatures/main.go b/cmd/signatures/main.go index db3737886a..947138c576 100644 --- a/cmd/signatures/main.go +++ b/cmd/signatures/main.go @@ -47,6 +47,15 @@ func main() { utils.Config = cfg logrus.WithField("config", *configPath).WithField("chainName", utils.Config.Chain.ClConfig.ConfigName).Printf("starting") + if utils.Config.Metrics.Enabled { + go func(addr string) { + logrus.Infof("serving metrics on %v", addr) + if err := metrics.Serve(addr); err != nil { + logrus.WithError(err).Fatal("Error serving metrics") + } + }(utils.Config.Metrics.Address) + } + db.MustInitDB(&types.DatabaseConfig{ Username: cfg.WriterDatabase.Username, Password: cfg.WriterDatabase.Password, diff --git a/cmd/statistics/main.go b/cmd/statistics/main.go index 7e84bae18b..ac13f9dac2 100644 --- a/cmd/statistics/main.go +++ b/cmd/statistics/main.go @@ -10,6 +10,7 @@ import ( "github.com/gobitfly/eth2-beaconchain-explorer/cache" "github.com/gobitfly/eth2-beaconchain-explorer/db" + "github.com/gobitfly/eth2-beaconchain-explorer/metrics" "github.com/gobitfly/eth2-beaconchain-explorer/price" "github.com/gobitfly/eth2-beaconchain-explorer/rpc" "github.com/gobitfly/eth2-beaconchain-explorer/services" @@ -60,6 +61,15 @@ func main() { } utils.Config = cfg + if utils.Config.Metrics.Enabled { + go func(addr string) { + logrus.Infof("serving metrics on %v", addr) + if err := metrics.Serve(addr); err != nil { + logrus.WithError(err).Fatal("Error serving metrics") + } + }(utils.Config.Metrics.Address) + } + if utils.Config.Chain.ClConfig.SlotsPerEpoch == 0 || utils.Config.Chain.ClConfig.SecondsPerSlot == 0 { utils.LogFatal(fmt.Errorf("error ether SlotsPerEpoch [%v] or SecondsPerSlot [%v] are not set", utils.Config.Chain.ClConfig.SlotsPerEpoch, utils.Config.Chain.ClConfig.SecondsPerSlot), "", 0) return diff --git a/cmd/user-service/main.go b/cmd/user-service/main.go index e0afd26626..d3e1ae43ff 100644 --- a/cmd/user-service/main.go +++ b/cmd/user-service/main.go @@ -42,6 +42,15 @@ func main() { utils.LogFatal(err, "invalid chain configuration specified, you must specify the slots per epoch, seconds per slot and genesis timestamp in the config file", 0) } + if utils.Config.Metrics.Enabled { + go func(addr string) { + logrus.Infof("serving metrics on %v", addr) + if err := metrics.Serve(addr); err != nil { + logrus.WithError(err).Fatal("Error serving metrics") + } + }(utils.Config.Metrics.Address) + } + if utils.Config.Pprof.Enabled { go func() { logrus.Infof("starting pprof http server on port %s", utils.Config.Pprof.Port) @@ -82,10 +91,6 @@ func main() { defer db.FrontendReaderDB.Close() defer db.FrontendWriterDB.Close() - if utils.Config.Metrics.Enabled { - go metrics.MonitorDB(db.FrontendWriterDB) - } - logrus.Infof("database connection established") userService.Init()