Skip to content

Commit

Permalink
Feat: Add storage metrics
Browse files Browse the repository at this point in the history
Refactor: metrics register method
  • Loading branch information
Jose Luis Lucas committed Mar 29, 2019
1 parent cbc8d4b commit 90d56e5
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 32 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.8.0
github.com/prometheus/client_golang v0.9.2
github.com/prometheus/procfs v0.0.0-20190328153300-af7bedc223fb // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.3.1
github.com/stretchr/testify v1.2.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 h1:PnBWHBf+6L0jO
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nLJdBg+pBmGgkJlSaKC2KaQmTCk1XDtE=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190328153300-af7bedc223fb h1:LvNCMEj0FFZQYsxZb7o3xQPrtqOOB6lrTUOWshC+ZTs=
github.com/prometheus/procfs v0.0.0-20190328153300-af7bedc223fb/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
Expand Down
5 changes: 1 addition & 4 deletions gossip/auditor/auditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ func (a Auditor) RegisterMetrics(srv *metrics.Server) {
QedAuditorBatchesReceivedTotal,
QedAuditorGetMembershipProofErrTotal,
}

for _, m := range metrics {
srv.Register(m)
}
srv.Register(metrics)
}

func (a Auditor) runTaskDispatcher() {
Expand Down
5 changes: 1 addition & 4 deletions gossip/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ func (m Monitor) RegisterMetrics(srv *metrics.Server) {
QedMonitorBatchesProcessSeconds,
QedMonitorGetIncrementalProofErrTotal,
}

for _, m := range metrics {
srv.Register(m)
}
srv.Register(metrics)
}

func (m Monitor) Process(b *protocol.BatchSnapshots) {
Expand Down
8 changes: 2 additions & 6 deletions gossip/publisher/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ func (p Publisher) RegisterMetrics(srv *metrics.Server) {
QedPublisherBatchesReceivedTotal,
QedPublisherBatchesProcessSeconds,
}

for _, m := range metrics {
srv.Register(m)
}
srv.Register(metrics)
}

func (p *Publisher) Process(b *protocol.BatchSnapshots) {
Expand All @@ -127,7 +124,7 @@ func (p *Publisher) Process(b *protocol.BatchSnapshots) {
for _, signedSnap := range b.Snapshots {
_, err := p.processed.Get(signedSnap.Signature)
if err != nil {
p.processed.Set(signedSnap.Signature, []byte{0x0}, 0)
_ = p.processed.Set(signedSnap.Signature, []byte{0x0}, 0)
batch.Snapshots = append(batch.Snapshots, signedSnap)
}
}
Expand Down Expand Up @@ -214,4 +211,3 @@ func (t PublishTask) Do() {
log.Infof("Publisher had an error getting response from snapStore saving a batch: %v", err)
}
}

5 changes: 1 addition & 4 deletions gossip/sender/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ func (s Sender) RegisterMetrics(srv *metrics.Server) {
QedSenderInstancesCount,
QedSenderBatchesSentTotal,
}

for _, m := range metrics {
srv.Register(m)
}
srv.Register(metrics)
}

func (s Sender) newBatch() *protocol.BatchSnapshots {
Expand Down
13 changes: 7 additions & 6 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ func (m Server) Shutdown() {

// Register a prometheus collector in the prometheus registry used
// by the metrics server.
func (m Server) Register(metric prometheus.Collector) {
if err := m.registry.Register(metric); err != nil {
log.Infof("metric not registered:", err)
} else {
log.Infof("metric registered.")
func (m Server) Register(collectors []prometheus.Collector) {
for _, c := range collectors {
if err := m.registry.Register(c); err != nil {
log.Infof("metric not registered:", err)
} else {
log.Infof("metric registered.")
}
}
}

7 changes: 4 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ func NewServer(conf *Config) (*Server, error) {

// create metrics server and register default qed metrics
server.metricsServer = metrics.NewServer(conf.MetricsAddr)
for _, m := range metrics.DefaultMetrics {
server.metricsServer.Register(m)
}
server.metricsServer.Register(metrics.DefaultMetrics)
server.metricsServer.Register(rocks.PrometheusCollectors())
// server.metricsServer.Register(raft.PrometheusCollectors())
// server.metricsServer.Register(balloon.PrometheusCollectors())

// Create gossip agent
config := gossip.DefaultConfig()
Expand Down
10 changes: 5 additions & 5 deletions storage/rocks/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func PrometheusCollectors() []prometheus.Collector {
}

// namespace is the leading part of all published metrics for the Storage service.
const namespace = "storage"
const namespace = "qed_storage"

const blockCacheSubsystem = "" // sub-system associated with metrics for block cache.
const ioSubsystem = "io" // sub-system associated with metrics for I/O.
const blockCacheSubsystem = "block" // sub-system associated with metrics for block cache.
const ioSubsystem = "io" // sub-system associated with metrics for I/O.

type rocksDBMetrics struct {
*blockCacheMetrics
Expand All @@ -75,7 +75,7 @@ func newBlockCacheMetrics(stats *rocksdb.Statistics) *blockCacheMetrics {
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: blockCacheSubsystem,
Name: "block_cache_miss",
Name: "cache_miss",
Help: "Total block cache misses.",
},
extractMetric(stats, rocksdb.TickerBlockCacheMiss),
Expand All @@ -84,7 +84,7 @@ func newBlockCacheMetrics(stats *rocksdb.Statistics) *blockCacheMetrics {
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: blockCacheSubsystem,
Name: "block_cache_hit",
Name: "cache_hit",
Help: "Total block cache hits.",
},
extractMetric(stats, rocksdb.TickerBlockCacheHit),
Expand Down

0 comments on commit 90d56e5

Please sign in to comment.