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
This commit is contained in:
committed by
Balint Gabor
parent
b677a07d36
commit
dcca613a0b
@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user