add metrics to mailserver (#999)

* add metrics to mailserver

* sentEnvelopesSize existing sentEnvelopesSize
This commit is contained in:
Andrea Franz 2018-05-30 14:31:47 +02:00 committed by GitHub
parent 5323af7da2
commit 4b938be856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions

View File

@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rlp"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
"github.com/status-im/status-go/geth/params"
@ -40,6 +41,13 @@ const (
var (
errDirectoryNotProvided = errors.New("data directory not provided")
errPasswordNotProvided = errors.New("password is not specified")
// By default go-ethereum/metrics creates dummy metrics that don't register anything.
// Real metrics are collected only if -metrics flag is set
requestProcessTimer = metrics.NewRegisteredTimer("mailserver/processTime", nil)
requestsCounter = metrics.NewRegisteredCounter("mailserver/requests", nil)
requestErrorsCounter = metrics.NewRegisteredCounter("mailserver/requestErrors", nil)
sentEnvelopesMeter = metrics.NewRegisteredMeter("mailserver/envelopes", nil)
sentEnvelopesSizeMeter = metrics.NewRegisteredMeter("mailserver/envelopesSize", nil)
)
// WMailServer whisper mailserver.
@ -160,11 +168,14 @@ func (s *WMailServer) Archive(env *whisper.Envelope) {
// DeliverMail sends mail to specified whisper peer.
func (s *WMailServer) DeliverMail(peer *whisper.Peer, request *whisper.Envelope) {
requestsCounter.Inc(1)
if peer == nil {
requestErrorsCounter.Inc(1)
log.Error("Whisper peer is nil")
return
}
if s.exceedsPeerRequests(peer.ID()) {
requestErrorsCounter.Inc(1)
return
}
@ -198,6 +209,13 @@ func (s *WMailServer) processRequest(peer *whisper.Peer, lower, upper uint32, bl
i := s.db.NewIterator(&util.Range{Start: kl.raw, Limit: ku.raw}, nil)
defer i.Release()
var (
sentEnvelopes int64
sentEnvelopesSize int64
)
start := time.Now()
for i.Next() {
var envelope whisper.Envelope
err = rlp.DecodeBytes(i.Value(), &envelope)
@ -216,9 +234,15 @@ func (s *WMailServer) processRequest(peer *whisper.Peer, lower, upper uint32, bl
return nil
}
}
sentEnvelopes++
sentEnvelopesSize += whisper.EnvelopeHeaderLength + int64(len(envelope.Data))
}
}
requestProcessTimer.UpdateSince(start)
sentEnvelopesMeter.Mark(sentEnvelopes)
sentEnvelopesSizeMeter.Mark(sentEnvelopesSize)
err = i.Error()
if err != nil {
log.Error(fmt.Sprintf("Level DB iterator error: %s", err))