Skip to content

Commit af3bbdf

Browse files
author
auxten
committed
Add service:DHT:NodeCount to metric web
1 parent bd38908 commit af3bbdf

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

cmd/cql-minerd/integration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ func TestFullProcess(t *testing.T) {
424424
t.Fatalf("wait for chain service failed: %v", err)
425425
}
426426

427+
time.Sleep(time.Hour)
427428
_, dsn, err := client.Create(meta)
428429
So(err, ShouldBeNil)
429430
dsnCfg, err := client.ParseDSN(dsn)

consistent/consistent.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ package consistent
3434

3535
import (
3636
"errors"
37+
"expvar"
3738
"sort"
3839
"strconv"
3940
"sync"
4041

42+
mw "github.com/zserge/metric"
43+
4144
"github.com/CovenantSQL/CovenantSQL/conf"
4245
"github.com/CovenantSQL/CovenantSQL/crypto/hash"
4346
"github.com/CovenantSQL/CovenantSQL/proto"
@@ -63,6 +66,14 @@ var (
6366
ErrKeyNotFound = errors.New("node key not found")
6467
)
6568

69+
const (
70+
mwKeyDHTNodeCount = "service:DHT:NodeCount"
71+
)
72+
73+
func init() {
74+
expvar.Publish(mwKeyDHTNodeCount, mw.NewGauge("1M1d"))
75+
}
76+
6677
// Consistent holds the information about the members of the consistent hash circle.
6778
type Consistent struct {
6879
// TODO(auxten): do not store node info on circle, just put node id as value
@@ -180,7 +191,6 @@ func (c *Consistent) add(node proto.Node) (err error) {
180191
log.WithField("node", node).WithError(err).Error("set node info failed")
181192
return
182193
}
183-
184194
c.AddCache(node)
185195
return
186196
}
@@ -195,6 +205,7 @@ func (c *Consistent) AddCache(node proto.Node) {
195205
}
196206
c.updateSortedHashes()
197207
c.count++
208+
expvar.Get(mwKeyDHTNodeCount).(mw.Metric).Add(float64(c.count))
198209
return
199210
}
200211

0 commit comments

Comments
 (0)