aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/swarm.go
diff options
context:
space:
mode:
Diffstat (limited to 'swarm/swarm.go')
-rw-r--r--swarm/swarm.go32
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
}