mirror of
https://github.com/status-im/whisper.git
synced 2025-02-08 00:45:48 +00:00
Apply whisper metrics patch
This commit is contained in:
parent
3dff91373a
commit
d441b04413
16
whisperv6/metrics.go
Normal file
16
whisperv6/metrics.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package whisperv6
|
||||||
|
|
||||||
|
import "github.com/ethereum/go-ethereum/metrics"
|
||||||
|
|
||||||
|
var (
|
||||||
|
envelopeAddedCounter = metrics.NewRegisteredCounter("whisper/envelopeAdded", nil)
|
||||||
|
envelopeNewAddedCounter = metrics.NewRegisteredCounter("whisper/envelopeNewAdded", nil)
|
||||||
|
envelopeClearedCounter = metrics.NewRegisteredCounter("whisper/envelopeCleared", nil)
|
||||||
|
envelopeErrFromFutureCounter = metrics.NewRegisteredCounter("whisper/envelopeErrFromFuture", nil)
|
||||||
|
envelopeErrVeryOldCounter = metrics.NewRegisteredCounter("whisper/envelopeErrVeryOld", nil)
|
||||||
|
envelopeErrExpiredCounter = metrics.NewRegisteredCounter("whisper/envelopeErrExpired", nil)
|
||||||
|
envelopeErrOversizedCounter = metrics.NewRegisteredCounter("whisper/envelopeErrOversized", nil)
|
||||||
|
envelopeErrLowPowCounter = metrics.NewRegisteredCounter("whisper/envelopeErrLowPow", nil)
|
||||||
|
envelopeErrNoBloomMatchCounter = metrics.NewRegisteredCounter("whisper/envelopeErrNoBloomMatch", nil)
|
||||||
|
envelopeSizeMeter = metrics.NewRegisteredMeter("whisper/envelopeSize", nil)
|
||||||
|
)
|
@ -925,8 +925,11 @@ func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
|
|||||||
now := uint32(whisper.timeSource().Unix())
|
now := uint32(whisper.timeSource().Unix())
|
||||||
sent := envelope.Expiry - envelope.TTL
|
sent := envelope.Expiry - envelope.TTL
|
||||||
|
|
||||||
|
envelopeAddedCounter.Inc(1)
|
||||||
|
|
||||||
if sent > now {
|
if sent > now {
|
||||||
if sent-DefaultSyncAllowance > now {
|
if sent-DefaultSyncAllowance > now {
|
||||||
|
envelopeErrFromFutureCounter.Inc(1)
|
||||||
return false, fmt.Errorf("envelope created in the future [%x]", envelope.Hash())
|
return false, fmt.Errorf("envelope created in the future [%x]", envelope.Hash())
|
||||||
}
|
}
|
||||||
// recalculate PoW, adjusted for the time difference, plus one second for latency
|
// recalculate PoW, adjusted for the time difference, plus one second for latency
|
||||||
@ -935,13 +938,16 @@ func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
|
|||||||
|
|
||||||
if envelope.Expiry < now {
|
if envelope.Expiry < now {
|
||||||
if envelope.Expiry+DefaultSyncAllowance*2 < now {
|
if envelope.Expiry+DefaultSyncAllowance*2 < now {
|
||||||
|
envelopeErrVeryOldCounter.Inc(1)
|
||||||
return false, fmt.Errorf("very old message")
|
return false, fmt.Errorf("very old message")
|
||||||
}
|
}
|
||||||
log.Debug("expired envelope dropped", "hash", envelope.Hash().Hex())
|
log.Debug("expired envelope dropped", "hash", envelope.Hash().Hex())
|
||||||
|
envelopeErrExpiredCounter.Inc(1)
|
||||||
return false, nil // drop envelope without error
|
return false, nil // drop envelope without error
|
||||||
}
|
}
|
||||||
|
|
||||||
if uint32(envelope.size()) > whisper.MaxMessageSize() {
|
if uint32(envelope.size()) > whisper.MaxMessageSize() {
|
||||||
|
envelopeErrOversizedCounter.Inc(1)
|
||||||
return false, fmt.Errorf("huge messages are not allowed [%x]", envelope.Hash())
|
return false, fmt.Errorf("huge messages are not allowed [%x]", envelope.Hash())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -950,6 +956,7 @@ func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
|
|||||||
// in this case the previous value is retrieved by MinPowTolerance()
|
// in this case the previous value is retrieved by MinPowTolerance()
|
||||||
// for a short period of peer synchronization.
|
// for a short period of peer synchronization.
|
||||||
if envelope.PoW() < whisper.MinPowTolerance() {
|
if envelope.PoW() < whisper.MinPowTolerance() {
|
||||||
|
envelopeErrLowPowCounter.Inc(1)
|
||||||
return false, fmt.Errorf("envelope with low PoW received: PoW=%f, hash=[%v]", envelope.PoW(), envelope.Hash().Hex())
|
return false, fmt.Errorf("envelope with low PoW received: PoW=%f, hash=[%v]", envelope.PoW(), envelope.Hash().Hex())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -959,6 +966,7 @@ func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
|
|||||||
// in this case the previous value is retrieved by BloomFilterTolerance()
|
// in this case the previous value is retrieved by BloomFilterTolerance()
|
||||||
// for a short period of peer synchronization.
|
// for a short period of peer synchronization.
|
||||||
if !BloomFilterMatch(whisper.BloomFilterTolerance(), envelope.Bloom()) {
|
if !BloomFilterMatch(whisper.BloomFilterTolerance(), envelope.Bloom()) {
|
||||||
|
envelopeErrNoBloomMatchCounter.Inc(1)
|
||||||
return false, fmt.Errorf("envelope does not match bloom filter, hash=[%v], bloom: \n%x \n%x \n%x",
|
return false, fmt.Errorf("envelope does not match bloom filter, hash=[%v], bloom: \n%x \n%x \n%x",
|
||||||
envelope.Hash().Hex(), whisper.BloomFilter(), envelope.Bloom(), envelope.Topic)
|
envelope.Hash().Hex(), whisper.BloomFilter(), envelope.Bloom(), envelope.Topic)
|
||||||
}
|
}
|
||||||
@ -983,6 +991,8 @@ func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
|
|||||||
log.Trace("whisper envelope already cached", "hash", envelope.Hash().Hex())
|
log.Trace("whisper envelope already cached", "hash", envelope.Hash().Hex())
|
||||||
} else {
|
} else {
|
||||||
log.Trace("cached whisper envelope", "hash", envelope.Hash().Hex())
|
log.Trace("cached whisper envelope", "hash", envelope.Hash().Hex())
|
||||||
|
envelopeNewAddedCounter.Inc(1)
|
||||||
|
envelopeSizeMeter.Mark(int64(envelope.size()))
|
||||||
whisper.statsMu.Lock()
|
whisper.statsMu.Lock()
|
||||||
whisper.stats.memoryUsed += envelope.size()
|
whisper.stats.memoryUsed += envelope.size()
|
||||||
whisper.statsMu.Unlock()
|
whisper.statsMu.Unlock()
|
||||||
@ -1084,6 +1094,7 @@ func (whisper *Whisper) expire() {
|
|||||||
hashSet.Each(func(v interface{}) bool {
|
hashSet.Each(func(v interface{}) bool {
|
||||||
sz := whisper.envelopes[v.(common.Hash)].size()
|
sz := whisper.envelopes[v.(common.Hash)].size()
|
||||||
delete(whisper.envelopes, v.(common.Hash))
|
delete(whisper.envelopes, v.(common.Hash))
|
||||||
|
envelopeClearedCounter.Inc(1)
|
||||||
whisper.envelopeFeed.Send(EnvelopeEvent{
|
whisper.envelopeFeed.Send(EnvelopeEvent{
|
||||||
Hash: v.(common.Hash),
|
Hash: v.(common.Hash),
|
||||||
Event: EventEnvelopeExpired,
|
Event: EventEnvelopeExpired,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user