diff options
author | Anton Evangelatov <anton.evangelatov@gmail.com> | 2018-02-23 21:19:59 +0800 |
---|---|---|
committer | Balint Gabor <balint.g@gmail.com> | 2018-02-23 21:19:59 +0800 |
commit | dcca613a0b4c6ce56e52f4607cf71f4f1338db8f (patch) | |
tree | 298e858e042df9d515aa091a79902ee9bf6d9f7b /swarm/swarm.go | |
parent | b677a07d36c957c4221bae952189559ac0c70537 (diff) | |
download | dexon-dcca613a0b4c6ce56e52f4607cf71f4f1338db8f.tar.gz dexon-dcca613a0b4c6ce56e52f4607cf71f4f1338db8f.tar.zst dexon-dcca613a0b4c6ce56e52f4607cf71f4f1338db8f.zip |
swarm: initial instrumentation (#15969)
* swarm: initial instrumentation with go-metrics
* swarm: initialise metrics collection and add ResettingTimer to HTTP requests
* swarm: update metrics flags names. remove redundant Timer.
* swarm: rename method for periodically updating gauges
* swarm: finalise metrics after feedback
* swarm/network: always init kad metrics containers
* swarm/network: off-by-one index in metrics containers
* swarm, metrics: resolved conflicts
Diffstat (limited to 'swarm/swarm.go')
-rw-r--r-- | swarm/swarm.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/swarm/swarm.go b/swarm/swarm.go index 3c77d6eab..0a120db1f 100644 --- a/swarm/swarm.go +++ b/swarm/swarm.go @@ -34,6 +34,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/discover" @@ -46,6 +47,16 @@ import ( "github.com/ethereum/go-ethereum/swarm/storage" ) +var ( + startTime time.Time + updateGaugesPeriod = 5 * time.Second + startCounter = metrics.NewRegisteredCounter("stack,start", nil) + stopCounter = metrics.NewRegisteredCounter("stack,stop", nil) + uptimeGauge = metrics.NewRegisteredGauge("stack.uptime", nil) + dbSizeGauge = metrics.NewRegisteredGauge("storage.db.chunks.size", nil) + cacheSizeGauge = metrics.NewRegisteredGauge("storage.db.cache.size", nil) +) + // the swarm stack type Swarm struct { config *api.Config // swarm configuration @@ -262,6 +273,7 @@ Start is called when the stack is started */ // implements the node.Service interface func (self *Swarm) Start(srv *p2p.Server) error { + startTime = time.Now() connectPeer := func(url string) error { node, err := discover.ParseNode(url) if err != nil { @@ -307,9 +319,28 @@ func (self *Swarm) Start(srv *p2p.Server) error { } } + self.periodicallyUpdateGauges() + + startCounter.Inc(1) return nil } +func (self *Swarm) periodicallyUpdateGauges() { + ticker := time.NewTicker(updateGaugesPeriod) + + go func() { + for range ticker.C { + self.updateGauges() + } + }() +} + +func (self *Swarm) updateGauges() { + dbSizeGauge.Update(int64(self.lstore.DbCounter())) + cacheSizeGauge.Update(int64(self.lstore.CacheCounter())) + uptimeGauge.Update(time.Since(startTime).Nanoseconds()) +} + // implements the node.Service interface // stops all component services. func (self *Swarm) Stop() error { @@ -324,6 +355,7 @@ func (self *Swarm) Stop() error { self.lstore.DbStore.Close() } self.sfs.Stop() + stopCounter.Inc(1) return err } |