diff --git a/whisper/whisperv6/metrics.go b/whisper/whisperv6/metrics.go new file mode 100644 index 0000000000..500969a9c1 --- /dev/null +++ b/whisper/whisperv6/metrics.go @@ -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 . + +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") +) diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go index 600f9cb286..6f4125c138 100644 --- a/whisper/whisperv6/whisper.go +++ b/whisper/whisperv6/whisper.go @@ -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()