Merge pull request #44 from vulcanize/stats
make DB stats collector registration optional
This commit is contained in:
commit
84fff0aa03
@ -44,6 +44,7 @@ const (
|
|||||||
PROM_HTTP = "PROM_HTTP"
|
PROM_HTTP = "PROM_HTTP"
|
||||||
PROM_HTTP_ADDR = "PROM_HTTP_ADDR"
|
PROM_HTTP_ADDR = "PROM_HTTP_ADDR"
|
||||||
PROM_HTTP_PORT = "PROM_HTTP_PORT"
|
PROM_HTTP_PORT = "PROM_HTTP_PORT"
|
||||||
|
PROM_DB_STATS = "PROM_DB_STATS"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Bind env vars for eth node and DB configuration
|
// Bind env vars for eth node and DB configuration
|
||||||
@ -76,6 +77,7 @@ func init() {
|
|||||||
viper.BindEnv("prom.http", PROM_HTTP)
|
viper.BindEnv("prom.http", PROM_HTTP)
|
||||||
viper.BindEnv("prom.httpAddr", PROM_HTTP_ADDR)
|
viper.BindEnv("prom.httpAddr", PROM_HTTP_ADDR)
|
||||||
viper.BindEnv("prom.httpPort", PROM_HTTP_PORT)
|
viper.BindEnv("prom.httpPort", PROM_HTTP_PORT)
|
||||||
|
viper.BindEnv("prom.dbStats", PROM_DB_STATS)
|
||||||
|
|
||||||
viper.BindEnv("statediff.serviceWorkers", STATEDIFF_SERVICE_WORKERS)
|
viper.BindEnv("statediff.serviceWorkers", STATEDIFF_SERVICE_WORKERS)
|
||||||
viper.BindEnv("statediff.trieWorkers", STATEDIFF_TRIE_WORKERS)
|
viper.BindEnv("statediff.trieWorkers", STATEDIFF_TRIE_WORKERS)
|
||||||
|
@ -136,8 +136,8 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().Bool("prom-http", false, "enable prometheus http service")
|
rootCmd.PersistentFlags().Bool("prom-http", false, "enable prometheus http service")
|
||||||
rootCmd.PersistentFlags().String("prom-http-addr", "127.0.0.1", "prometheus http host")
|
rootCmd.PersistentFlags().String("prom-http-addr", "127.0.0.1", "prometheus http host")
|
||||||
rootCmd.PersistentFlags().String("prom-http-port", "8080", "prometheus http port")
|
rootCmd.PersistentFlags().String("prom-http-port", "8080", "prometheus http port")
|
||||||
|
rootCmd.PersistentFlags().Bool("prom-db-stats", false, "enables prometheus db stats")
|
||||||
rootCmd.PersistentFlags().Bool("metrics", false, "enable metrics")
|
rootCmd.PersistentFlags().Bool("prom-metrics", false, "enable prometheus metrics")
|
||||||
|
|
||||||
viper.BindPFlag("server.httpPath", rootCmd.PersistentFlags().Lookup("http-path"))
|
viper.BindPFlag("server.httpPath", rootCmd.PersistentFlags().Lookup("http-path"))
|
||||||
viper.BindPFlag("server.ipcPath", rootCmd.PersistentFlags().Lookup("ipc-path"))
|
viper.BindPFlag("server.ipcPath", rootCmd.PersistentFlags().Lookup("ipc-path"))
|
||||||
@ -164,7 +164,8 @@ func init() {
|
|||||||
viper.BindPFlag("prom.http", rootCmd.PersistentFlags().Lookup("prom-http"))
|
viper.BindPFlag("prom.http", rootCmd.PersistentFlags().Lookup("prom-http"))
|
||||||
viper.BindPFlag("prom.httpAddr", rootCmd.PersistentFlags().Lookup("prom-http-addr"))
|
viper.BindPFlag("prom.httpAddr", rootCmd.PersistentFlags().Lookup("prom-http-addr"))
|
||||||
viper.BindPFlag("prom.httpPort", rootCmd.PersistentFlags().Lookup("prom-http-port"))
|
viper.BindPFlag("prom.httpPort", rootCmd.PersistentFlags().Lookup("prom-http-port"))
|
||||||
viper.BindPFlag("prom.metrics", rootCmd.PersistentFlags().Lookup("metrics"))
|
viper.BindPFlag("prom.dbStats", rootCmd.PersistentFlags().Lookup("prom-db-stats"))
|
||||||
|
viper.BindPFlag("prom.metrics", rootCmd.PersistentFlags().Lookup("prom-metrics"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func initConfig() {
|
func initConfig() {
|
||||||
|
14
cmd/util.go
14
cmd/util.go
@ -52,15 +52,17 @@ func createStateDiffService() (sd.StateDiffService, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create statediff service
|
// create statediff service
|
||||||
logWithCommand.Info("Creating statediff service")
|
logWithCommand.Info("Setting up Postgres DB")
|
||||||
db, err := setupPostgres(nodeInfo)
|
db, err := setupPostgres(nodeInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
logWithCommand.Info("Creating statediff indexer")
|
||||||
indexer, err := ind.NewStateDiffIndexer(chainConf, db)
|
indexer, err := ind.NewStateDiffIndexer(chainConf, db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
logWithCommand.Info("Creating statediff service")
|
||||||
sdConf := sd.Config{
|
sdConf := sd.Config{
|
||||||
ServiceWorkers: viper.GetUint("statediff.serviceWorkers"),
|
ServiceWorkers: viper.GetUint("statediff.serviceWorkers"),
|
||||||
TrieWorkers: viper.GetUint("statediff.trieWorkers"),
|
TrieWorkers: viper.GetUint("statediff.trieWorkers"),
|
||||||
@ -71,12 +73,16 @@ func createStateDiffService() (sd.StateDiffService, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupPostgres(nodeInfo node.Info) (*postgres.DB, error) {
|
func setupPostgres(nodeInfo node.Info) (*postgres.DB, error) {
|
||||||
params := GetDBParams()
|
p := GetDBParams()
|
||||||
db, err := postgres.NewDB(postgres.DbConnectionString(params), GetDBConfig(), nodeInfo)
|
logWithCommand.Info("initializing DB connection pool")
|
||||||
|
db, err := postgres.NewDB(postgres.DbConnectionString(p), GetDBConfig(), nodeInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
prom.RegisterDBCollector(params.Name, db.DB)
|
if viper.GetBool("prom.dbStats") {
|
||||||
|
logWithCommand.Info("registering DB collector")
|
||||||
|
prom.RegisterDBCollector(p.Name, db.DB)
|
||||||
|
}
|
||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
trie = 1024
|
trie = 1024
|
||||||
|
|
||||||
[prom]
|
[prom]
|
||||||
|
dbStats = false
|
||||||
metrics = true
|
metrics = true
|
||||||
http = true
|
http = true
|
||||||
httpAddr = "localhost"
|
httpAddr = "localhost"
|
||||||
|
Loading…
Reference in New Issue
Block a user