ipld-eth-db-validator/pkg/prom/prom.go
prathamesh0 acf8e6f96a
Make writeStateDiffAt call on missing block and add metrics (#20)
* Add chainID flag and make chainConfig optional

* Add prometheus metrics to monitor validation progress

* Make writeStateDiffAt calls on missing blocks

* Update docs and config improvements

* Use standard logger

* Add copyright to files

* Upgrade dependencies
2022-08-23 13:05:50 +05:30

60 lines
1.6 KiB
Go

// VulcanizeDB
// Copyright © 2022 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package prom
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
const (
namespace = "ipld_eth_state_snapshot"
connSubsystem = "connections"
statsSubsystem = "stats"
)
var (
metrics bool
lastValidatedBlock prometheus.Gauge
)
func Init() {
metrics = true
lastValidatedBlock = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: statsSubsystem,
Name: "last_validated_block",
Help: "Last validated block number",
})
}
// RegisterDBCollector create metric collector for given connection
func RegisterDBCollector(name string, db DBStatsGetter) {
if metrics {
prometheus.Register(NewDBStatsCollector(name, db))
}
}
// SetLastValidatedBlock sets the last validated block number
func SetLastValidatedBlock(blockNumber float64) {
if metrics {
lastValidatedBlock.Set(blockNumber)
}
}