whisper: instrument whisperv6 with basic metrics required for traffic profile

Added 4 metrics to whisper:
- number of newly received envelopes
- number of total envelopes received
- size of all received envelopes
- number of whisper peers
This commit is contained in:
Dmitry Shulyak 2018-02-18 10:21:59 +02:00
parent 4e61ed02e2
commit 869c2c957f
2 changed files with 32 additions and 2 deletions

View file

@ -0,0 +1,26 @@
// Copyright 2018 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package whisperv6
import "github.com/ethereum/go-ethereum/metrics"
var (
newEnvelopes = metrics.NewMeter("whisper/NewEnvelopes")
totalEnvelopes = metrics.NewMeter("whisper/TotalEnvelopes")
envelopesSize = metrics.NewMeter("whisper/EnvelopesSize")
metricsPeers = metrics.NewCounter("whisper/Peers")
)

View file

@ -624,15 +624,15 @@ func (whisper *Whisper) Stop() error {
func (whisper *Whisper) HandlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
// Create the new peer and start tracking it
whisperPeer := newPeer(whisper, peer, rw)
whisper.peerMu.Lock()
whisper.peers[whisperPeer] = struct{}{}
whisper.peerMu.Unlock()
metricsPeers.Inc(1)
defer func() {
whisper.peerMu.Lock()
delete(whisper.peers, whisperPeer)
whisper.peerMu.Unlock()
metricsPeers.Dec(1)
}()
// Run the peer handshake and state updates
@ -747,6 +747,9 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
// whisper network. It also inserts the envelope into the expiration pool at the
// appropriate time-stamp. In case of error, connection should be dropped.
func (whisper *Whisper) add(envelope *Envelope) (bool, error) {
totalEnvelopes.Mark(1)
envelopesSize.Mark(int64(envelope.size()))
now := uint32(time.Now().Unix())
sent := envelope.Expiry - envelope.TTL
@ -794,6 +797,7 @@ func (whisper *Whisper) add(envelope *Envelope) (bool, error) {
whisper.poolMu.Lock()
_, alreadyCached := whisper.envelopes[hash]
if !alreadyCached {
newEnvelopes.Mark(1)
whisper.envelopes[hash] = envelope
if whisper.expirations[envelope.Expiry] == nil {
whisper.expirations[envelope.Expiry] = set.NewNonTS()