handle prom in thread
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 32s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 32s
This commit is contained in:
@@ -19,6 +19,10 @@ var (
|
|||||||
Name: "cart_pool_size",
|
Name: "cart_pool_size",
|
||||||
Help: "The total number of mutations",
|
Help: "The total number of mutations",
|
||||||
})
|
})
|
||||||
|
poolUsage = promauto.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Name: "cart_grain_pool_usage",
|
||||||
|
Help: "The current usage of the grain pool",
|
||||||
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
type GrainPool interface {
|
type GrainPool interface {
|
||||||
@@ -32,7 +36,6 @@ type Ttl struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GrainLocalPool struct {
|
type GrainLocalPool struct {
|
||||||
gauage prometheus.Gauge
|
|
||||||
grains map[CartId]*CartGrain
|
grains map[CartId]*CartGrain
|
||||||
expiry []Ttl
|
expiry []Ttl
|
||||||
spawn func(id CartId) (*CartGrain, error)
|
spawn func(id CartId) (*CartGrain, error)
|
||||||
@@ -41,12 +44,8 @@ type GrainLocalPool struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewGrainLocalPool(size int, ttl time.Duration, spawn func(id CartId) (*CartGrain, error)) *GrainLocalPool {
|
func NewGrainLocalPool(size int, ttl time.Duration, spawn func(id CartId) (*CartGrain, error)) *GrainLocalPool {
|
||||||
gauage := promauto.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Name: "cart_grain_pool_usage",
|
|
||||||
Help: "The current usage of the grain pool",
|
|
||||||
})
|
|
||||||
ret := &GrainLocalPool{
|
ret := &GrainLocalPool{
|
||||||
gauage: gauage,
|
|
||||||
spawn: spawn,
|
spawn: spawn,
|
||||||
grains: make(map[CartId]*CartGrain),
|
grains: make(map[CartId]*CartGrain),
|
||||||
expiry: make([]Ttl, 0),
|
expiry: make([]Ttl, 0),
|
||||||
@@ -116,11 +115,13 @@ func (p *GrainLocalPool) GetGrain(id CartId) (*CartGrain, error) {
|
|||||||
|
|
||||||
p.grains[id] = grain
|
p.grains[id] = grain
|
||||||
}
|
}
|
||||||
l := float64(len(p.grains))
|
go func() {
|
||||||
ps := float64(p.PoolSize)
|
l := float64(len(p.grains))
|
||||||
p.gauage.Set(l / ps)
|
ps := float64(p.PoolSize)
|
||||||
poolGrains.Set(l)
|
poolUsage.Set(l / ps)
|
||||||
poolSize.Set(ps)
|
poolGrains.Set(l)
|
||||||
|
poolSize.Set(ps)
|
||||||
|
}()
|
||||||
return grain, err
|
return grain, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user