Add sync/p2p metric for number of messages received by topic (#3341)

* Add going msg metric

* fmt

* rename
This commit is contained in:
Preston Van Loon
2019-08-28 11:14:22 -04:00
committed by Raul Jordan
parent 7bb5ac0dde
commit 2ee4f00b81
3 changed files with 21 additions and 2 deletions

View File

@@ -48,6 +48,8 @@ go_library(
"@com_github_libp2p_go_libp2p_core//:go_default_library",
"@com_github_libp2p_go_libp2p_core//network:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],

View File

@@ -1,3 +1,18 @@
package sync
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
// TODO(3147): Add metrics for RPC & subscription success/error.
var (
messageReceivedCounter = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "p2p_message_recieved_total",
Help: "Count of messages received.",
},
[]string{"topic"},
)
)

View File

@@ -12,10 +12,10 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
)
var oneYear = 365 * 24 * time.Hour
const oneYear = 365 * 24 * time.Hour
// prefix to add to keys, so that we can represent invalid objects
var invalid = "invalidObject"
const invalid = "invalidObject"
// subHandler represents handler for a given subscription.
type subHandler func(context.Context, proto.Message) error
@@ -132,6 +132,8 @@ func (r *RegularSync) subscribe(topic string, validate validator, handle subHand
continue
}
messageReceivedCounter.WithLabelValues(topic + r.p2p.Encoding().ProtocolSuffix()).Inc()
go pipeline(msg.Data)
}
}