Skip to content

Commit

Permalink
les/vflux/server: fix metrics (#22946)
Browse files Browse the repository at this point in the history
* les/vflux/server: fix metrics

* les/vflux/server: fix metrics
  • Loading branch information
rjl493456442 authored Oct 11, 2021
1 parent 53b1420 commit 088bc34
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
6 changes: 4 additions & 2 deletions les/vflux/server/clientpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ func NewClientPool(balanceDb ethdb.KeyValueStore, minCap uint64, connectedBias t
if oldState.HasAll(cp.setup.activeFlag) && oldState.HasNone(cp.setup.activeFlag) {
clientDeactivatedMeter.Mark(1)
}
_, connected := cp.Active()
totalConnectedGauge.Update(int64(connected))
activeCount, activeCap := cp.Active()
totalActiveCountGauge.Update(int64(activeCount))
totalActiveCapacityGauge.Update(int64(activeCap))
totalInactiveCountGauge.Update(int64(cp.Inactive()))
})
return cp
}
Expand Down
4 changes: 3 additions & 1 deletion les/vflux/server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
)

var (
totalConnectedGauge = metrics.NewRegisteredGauge("vflux/server/totalConnected", nil)
totalActiveCapacityGauge = metrics.NewRegisteredGauge("vflux/server/active/capacity", nil)
totalActiveCountGauge = metrics.NewRegisteredGauge("vflux/server/active/count", nil)
totalInactiveCountGauge = metrics.NewRegisteredGauge("vflux/server/inactive/count", nil)

clientConnectedMeter = metrics.NewRegisteredMeter("vflux/server/clientEvent/connected", nil)
clientActivatedMeter = metrics.NewRegisteredMeter("vflux/server/clientEvent/activated", nil)
Expand Down
22 changes: 15 additions & 7 deletions les/vflux/server/prioritypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func newPriorityPool(ns *nodestate.NodeStateMachine, setup *serverSetup, clock m
} else {
ns.SetStateSub(node, nodestate.Flags{}, pp.setup.activeFlag.Or(pp.setup.inactiveFlag), 0)
if n, _ := pp.ns.GetField(node, pp.setup.queueField).(*ppNodeInfo); n != nil {
pp.disconnectedNode(n)
pp.disconnectNode(n)
}
ns.SetFieldSub(node, pp.setup.capacityField, nil)
ns.SetFieldSub(node, pp.setup.queueField, nil)
Expand All @@ -137,10 +137,10 @@ func newPriorityPool(ns *nodestate.NodeStateMachine, setup *serverSetup, clock m
ns.SubscribeState(pp.setup.activeFlag.Or(pp.setup.inactiveFlag), func(node *enode.Node, oldState, newState nodestate.Flags) {
if c, _ := pp.ns.GetField(node, pp.setup.queueField).(*ppNodeInfo); c != nil {
if oldState.IsEmpty() {
pp.connectedNode(c)
pp.connectNode(c)
}
if newState.IsEmpty() {
pp.disconnectedNode(c)
pp.disconnectNode(c)
}
}
})
Expand Down Expand Up @@ -233,6 +233,14 @@ func (pp *priorityPool) Active() (uint64, uint64) {
return pp.activeCount, pp.activeCap
}

// Inactive returns the number of currently inactive nodes
func (pp *priorityPool) Inactive() int {
pp.lock.Lock()
defer pp.lock.Unlock()

return pp.inactiveQueue.Size()
}

// Limits returns the maximum allowed number and total capacity of active nodes
func (pp *priorityPool) Limits() (uint64, uint64) {
pp.lock.Lock()
Expand Down Expand Up @@ -285,9 +293,9 @@ func (pp *priorityPool) inactivePriority(p *ppNodeInfo) int64 {
return p.nodePriority.priority(pp.minCap)
}

// connectedNode is called when a new node has been added to the pool (inactiveFlag set)
// connectNode is called when a new node has been added to the pool (inactiveFlag set)
// Note: this function should run inside a NodeStateMachine operation
func (pp *priorityPool) connectedNode(c *ppNodeInfo) {
func (pp *priorityPool) connectNode(c *ppNodeInfo) {
pp.lock.Lock()
pp.activeQueue.Refresh()
if c.connected {
Expand All @@ -301,10 +309,10 @@ func (pp *priorityPool) connectedNode(c *ppNodeInfo) {
pp.updateFlags(updates)
}

// disconnectedNode is called when a node has been removed from the pool (both inactiveFlag
// disconnectNode is called when a node has been removed from the pool (both inactiveFlag
// and activeFlag reset)
// Note: this function should run inside a NodeStateMachine operation
func (pp *priorityPool) disconnectedNode(c *ppNodeInfo) {
func (pp *priorityPool) disconnectNode(c *ppNodeInfo) {
pp.lock.Lock()
pp.activeQueue.Refresh()
if !c.connected {
Expand Down

0 comments on commit 088bc34

Please sign in to comment.