Expose database stats in metrics
This commit is contained in:
parent
52c7f84432
commit
85896f91b7
@ -109,6 +109,7 @@ An example config file:
|
|||||||
http = true # PROM_HTTP
|
http = true # PROM_HTTP
|
||||||
httpAddr = "localhost" # PROM_HTTP_ADDR
|
httpAddr = "localhost" # PROM_HTTP_ADDR
|
||||||
httpPort = "8889" # PROM_HTTP_PORT
|
httpPort = "8889" # PROM_HTTP_PORT
|
||||||
|
dbStats = true # PROM_DB_STATS
|
||||||
|
|
||||||
[ethereum]
|
[ethereum]
|
||||||
# node info
|
# node info
|
||||||
@ -155,7 +156,7 @@ An example config file:
|
|||||||
|
|
||||||
### `serve`
|
### `serve`
|
||||||
|
|
||||||
* To serve state diffs over RPC:
|
* To serve the statediff RPC API:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./eth-statediff-service serve --config=<config path>
|
./eth-statediff-service serve --config=<config path>
|
||||||
@ -167,7 +168,7 @@ An example config file:
|
|||||||
./eth-statediff-service serve --config environments/config.toml
|
./eth-statediff-service serve --config environments/config.toml
|
||||||
```
|
```
|
||||||
|
|
||||||
* Available RPC methods are:
|
* Available RPC methods:
|
||||||
* `statediff_stateTrieAt()`
|
* `statediff_stateTrieAt()`
|
||||||
* `statediff_streamCodeAndCodeHash()`
|
* `statediff_streamCodeAndCodeHash()`
|
||||||
* `statediff_stateDiffAt()`
|
* `statediff_stateDiffAt()`
|
||||||
@ -185,7 +186,8 @@ An example config file:
|
|||||||
* This is done by turning "prerun" on in the config (`statediff.prerun = true`) and defining ranges and params in the
|
* This is done by turning "prerun" on in the config (`statediff.prerun = true`) and defining ranges and params in the
|
||||||
`prerun` section of the config.
|
`prerun` section of the config.
|
||||||
* Set the range using `prerun.start` and `prerun.stop`. Use `prerun.ranges` if prerun on more than one range is required.
|
* Set the range using `prerun.start` and `prerun.stop`. Use `prerun.ranges` if prerun on more than one range is required.
|
||||||
* Currently, `prerun.params.includeTD` must be set to `true`.
|
|
||||||
|
* NOTE: Currently, `params.includeTD` must be set to / passed as `true`.
|
||||||
|
|
||||||
## Monitoring
|
## Monitoring
|
||||||
|
|
||||||
|
12
cmd/util.go
12
cmd/util.go
@ -6,12 +6,13 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/statediff"
|
"github.com/ethereum/go-ethereum/statediff"
|
||||||
gethsd "github.com/ethereum/go-ethereum/statediff"
|
|
||||||
ind "github.com/ethereum/go-ethereum/statediff/indexer"
|
ind "github.com/ethereum/go-ethereum/statediff/indexer"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/indexer/shared"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
sd "github.com/vulcanize/eth-statediff-service/pkg"
|
sd "github.com/vulcanize/eth-statediff-service/pkg"
|
||||||
|
"github.com/vulcanize/eth-statediff-service/pkg/prom"
|
||||||
)
|
)
|
||||||
|
|
||||||
type blockRange [2]uint64
|
type blockRange [2]uint64
|
||||||
@ -78,11 +79,16 @@ func createStateDiffService() (sd.StateDiffService, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logWithCommand.Info("Creating statediff indexer")
|
logWithCommand.Info("Creating statediff indexer")
|
||||||
_, indexer, err := ind.NewStateDiffIndexer(context.Background(), chainConf, nodeInfo, conf)
|
db, indexer, err := ind.NewStateDiffIndexer(context.Background(), chainConf, nodeInfo, conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if conf.Type() == shared.POSTGRES && viper.GetBool("prom.dbStats") {
|
||||||
|
prom.RegisterDBCollector(viper.GetString("database.name"), db)
|
||||||
|
}
|
||||||
|
|
||||||
logWithCommand.Info("Creating statediff service")
|
logWithCommand.Info("Creating statediff service")
|
||||||
sdConf := sd.Config{
|
sdConf := sd.Config{
|
||||||
ServiceWorkers: viper.GetUint("statediff.serviceWorkers"),
|
ServiceWorkers: viper.GetUint("statediff.serviceWorkers"),
|
||||||
@ -97,7 +103,7 @@ func setupPreRunRanges() []sd.RangeRequest {
|
|||||||
if !viper.GetBool("statediff.prerun") {
|
if !viper.GetBool("statediff.prerun") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
preRunParams := gethsd.Params{
|
preRunParams := statediff.Params{
|
||||||
IntermediateStateNodes: viper.GetBool("prerun.params.intermediateStateNodes"),
|
IntermediateStateNodes: viper.GetBool("prerun.params.intermediateStateNodes"),
|
||||||
IntermediateStorageNodes: viper.GetBool("prerun.params.intermediateStorageNodes"),
|
IntermediateStorageNodes: viper.GetBool("prerun.params.intermediateStorageNodes"),
|
||||||
IncludeBlock: viper.GetBool("prerun.params.includeBlock"),
|
IncludeBlock: viper.GetBool("prerun.params.includeBlock"),
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
http = true
|
http = true
|
||||||
httpAddr = "0.0.0.0"
|
httpAddr = "0.0.0.0"
|
||||||
httpPort = 9100
|
httpPort = 9100
|
||||||
|
dbStats = false
|
||||||
|
|
||||||
[ethereum]
|
[ethereum]
|
||||||
nodeID = ""
|
nodeID = ""
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
package prom
|
package prom
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -29,7 +29,7 @@ const (
|
|||||||
|
|
||||||
// DBStatsGetter is an interface that gets sql.DBStats.
|
// DBStatsGetter is an interface that gets sql.DBStats.
|
||||||
type DBStatsGetter interface {
|
type DBStatsGetter interface {
|
||||||
Stats() sql.DBStats
|
Stats() sql.Stats
|
||||||
}
|
}
|
||||||
|
|
||||||
// DBStatsCollector implements the prometheus.Collector interface.
|
// DBStatsCollector implements the prometheus.Collector interface.
|
||||||
@ -122,41 +122,41 @@ func (c DBStatsCollector) Collect(ch chan<- prometheus.Metric) {
|
|||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.maxOpenDesc,
|
c.maxOpenDesc,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(stats.MaxOpenConnections),
|
float64(stats.MaxOpen()),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.openDesc,
|
c.openDesc,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(stats.OpenConnections),
|
float64(stats.Open()),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.inUseDesc,
|
c.inUseDesc,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(stats.InUse),
|
float64(stats.InUse()),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.idleDesc,
|
c.idleDesc,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(stats.Idle),
|
float64(stats.Idle()),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.waitedForDesc,
|
c.waitedForDesc,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(stats.WaitCount),
|
float64(stats.WaitCount()),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.blockedSecondsDesc,
|
c.blockedSecondsDesc,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
stats.WaitDuration.Seconds(),
|
stats.WaitDuration().Seconds(),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.closedMaxIdleDesc,
|
c.closedMaxIdleDesc,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(stats.MaxIdleClosed),
|
float64(stats.MaxIdleClosed()),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.closedMaxLifetimeDesc,
|
c.closedMaxLifetimeDesc,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(stats.MaxLifetimeClosed),
|
float64(stats.MaxLifetimeClosed()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package prom
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
)
|
)
|
||||||
@ -123,7 +122,7 @@ func Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RegisterDBCollector create metric collector for given connection
|
// RegisterDBCollector create metric collector for given connection
|
||||||
func RegisterDBCollector(name string, db *sqlx.DB) {
|
func RegisterDBCollector(name string, db DBStatsGetter) {
|
||||||
if metrics {
|
if metrics {
|
||||||
prometheus.Register(NewDBStatsCollector(name, db))
|
prometheus.Register(NewDBStatsCollector(name, db))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user