forked from TrueCloudLab/neoneo-go
Merge pull request #2750 from nspcc-dev/network-prometheus-metrics
network: add prometheus histogram with cmd processing time
This commit is contained in:
commit
903beeb5df
2 changed files with 29 additions and 0 deletions
|
@ -1,6 +1,9 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
|
@ -46,6 +49,7 @@ var (
|
|||
Namespace: "neogo",
|
||||
},
|
||||
)
|
||||
p2pCmds = make(map[CommandType]prometheus.Histogram)
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -56,6 +60,21 @@ func init() {
|
|||
poolCount,
|
||||
blockQueueLength,
|
||||
)
|
||||
for _, cmd := range []CommandType{CMDVersion, CMDVerack, CMDGetAddr,
|
||||
CMDAddr, CMDPing, CMDPong, CMDGetHeaders, CMDHeaders, CMDGetBlocks,
|
||||
CMDMempool, CMDInv, CMDGetData, CMDGetBlockByIndex, CMDNotFound,
|
||||
CMDTX, CMDBlock, CMDExtensible, CMDP2PNotaryRequest, CMDGetMPTData,
|
||||
CMDMPTData, CMDReject, CMDFilterLoad, CMDFilterAdd, CMDFilterClear,
|
||||
CMDMerkleBlock, CMDAlert} {
|
||||
p2pCmds[cmd] = prometheus.NewHistogram(
|
||||
prometheus.HistogramOpts{
|
||||
Help: "P2P " + cmd.String() + " handling time",
|
||||
Name: "p2p_" + strings.ToLower(cmd.String()) + "_time",
|
||||
Namespace: "neogo",
|
||||
},
|
||||
)
|
||||
prometheus.MustRegister(p2pCmds[cmd])
|
||||
}
|
||||
}
|
||||
|
||||
func updateNetworkSizeMetric(sz int) {
|
||||
|
@ -77,3 +96,10 @@ func setServerAndNodeVersions(nodeVer string, serverID string) {
|
|||
servAndNodeVersion.WithLabelValues("Node version: ", nodeVer).Add(0)
|
||||
servAndNodeVersion.WithLabelValues("Server id: ", serverID).Add(0)
|
||||
}
|
||||
func addCmdTimeMetric(cmd CommandType, t time.Duration) {
|
||||
// Shouldn't happen, message decoder checks the type, but better safe than sorry.
|
||||
if p2pCmds[cmd] == nil {
|
||||
return
|
||||
}
|
||||
p2pCmds[cmd].Observe(t.Seconds())
|
||||
}
|
||||
|
|
|
@ -1198,6 +1198,9 @@ func (s *Server) handleMessage(peer Peer, msg *Message) error {
|
|||
zap.Stringer("addr", peer.RemoteAddr()),
|
||||
zap.String("type", msg.Command.String()))
|
||||
|
||||
start := time.Now()
|
||||
defer func() { addCmdTimeMetric(msg.Command, time.Since(start)) }()
|
||||
|
||||
if peer.Handshaked() {
|
||||
if inv, ok := msg.Payload.(*payload.Inventory); ok {
|
||||
if !inv.Type.Valid(s.chain.P2PSigExtensionsEnabled()) || len(inv.Hashes) == 0 {
|
||||
|
|
Loading…
Reference in a new issue