add more metrics
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 31s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 31s
This commit is contained in:
@@ -5,6 +5,20 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
var (
|
||||
poolGrains = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "cart_grains_in_pool",
|
||||
Help: "The total number of grains in the pool",
|
||||
})
|
||||
poolSize = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "cart_pool_size",
|
||||
Help: "The total number of mutations",
|
||||
})
|
||||
)
|
||||
|
||||
type GrainPool interface {
|
||||
@@ -18,6 +32,7 @@ type Ttl struct {
|
||||
}
|
||||
|
||||
type GrainLocalPool struct {
|
||||
gauage prometheus.Gauge
|
||||
grains map[CartId]*CartGrain
|
||||
expiry []Ttl
|
||||
spawn func(id CartId) (*CartGrain, error)
|
||||
@@ -26,13 +41,19 @@ type GrainLocalPool struct {
|
||||
}
|
||||
|
||||
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{
|
||||
gauage: gauage,
|
||||
spawn: spawn,
|
||||
grains: make(map[CartId]*CartGrain),
|
||||
expiry: make([]Ttl, 0),
|
||||
Ttl: ttl,
|
||||
PoolSize: size,
|
||||
}
|
||||
|
||||
cartPurge := time.NewTicker(time.Minute)
|
||||
go func() {
|
||||
<-cartPurge.C
|
||||
@@ -95,6 +116,11 @@ func (p *GrainLocalPool) GetGrain(id CartId) (*CartGrain, error) {
|
||||
|
||||
p.grains[id] = grain
|
||||
}
|
||||
l := float64(len(p.grains))
|
||||
ps := float64(p.PoolSize)
|
||||
p.gauage.Set(l / ps)
|
||||
poolGrains.Set(l)
|
||||
poolSize.Set(ps)
|
||||
return grain, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user