Skip to content

Commit

Permalink
(NOBIDS) consolidate exposing metrics (#2925)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybrush committed Jul 31, 2024
1 parent f5521cb commit a146164
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 77 deletions.
9 changes: 9 additions & 0 deletions cmd/blobindexer/blobindexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions cmd/eth1indexer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions cmd/ethstore-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions cmd/frontend-data-updater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 9 additions & 11 deletions cmd/node-jobs-processor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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,
Expand All @@ -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 …")
}
Expand Down
38 changes: 9 additions & 29 deletions cmd/notification-collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"strings"
"sync"

"github.com/gobitfly/eth2-beaconchain-explorer/cache"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 9 additions & 29 deletions cmd/notification-sender/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"strings"
"sync"

"github.com/gobitfly/eth2-beaconchain-explorer/cache"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions cmd/rewards-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions cmd/signatures/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions cmd/statistics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions cmd/user-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a146164

Please sign in to comment.