net pool metrics
This commit is contained in:
parent
332d8bb373
commit
0317a4fbe2
@ -6,6 +6,9 @@ func WithPrometheus(reg *prometheus.Registry, namespace, subsystem string) Optio
|
|||||||
if subsystem == "" {
|
if subsystem == "" {
|
||||||
subsystem = "cache"
|
subsystem = "cache"
|
||||||
}
|
}
|
||||||
|
if reg == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return func(cache *oCache) {
|
return func(cache *oCache) {
|
||||||
cache.metrics = &metrics{
|
cache.metrics = &metrics{
|
||||||
hit: prometheus.NewCounter(prometheus.CounterOpts{
|
hit: prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
|||||||
@ -61,7 +61,9 @@ func New(loadFunc LoadFunc, opts ...Option) OCache {
|
|||||||
log: log.Sugar(),
|
log: log.Sugar(),
|
||||||
}
|
}
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(c)
|
if o != nil {
|
||||||
|
o(c)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if c.ttl != 0 && c.gc != 0 {
|
if c.ttl != 0 && c.gc != 0 {
|
||||||
go c.ticker()
|
go c.ticker()
|
||||||
|
|||||||
@ -6,8 +6,10 @@ import (
|
|||||||
"github.com/anytypeio/any-sync/app"
|
"github.com/anytypeio/any-sync/app"
|
||||||
"github.com/anytypeio/any-sync/app/logger"
|
"github.com/anytypeio/any-sync/app/logger"
|
||||||
"github.com/anytypeio/any-sync/app/ocache"
|
"github.com/anytypeio/any-sync/app/ocache"
|
||||||
|
"github.com/anytypeio/any-sync/metric"
|
||||||
"github.com/anytypeio/any-sync/net/dialer"
|
"github.com/anytypeio/any-sync/net/dialer"
|
||||||
"github.com/anytypeio/any-sync/net/peer"
|
"github.com/anytypeio/any-sync/net/peer"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -47,6 +49,10 @@ type pool struct {
|
|||||||
|
|
||||||
func (p *pool) Init(a *app.App) (err error) {
|
func (p *pool) Init(a *app.App) (err error) {
|
||||||
p.dialer = a.MustComponent(dialer.CName).(dialer.Dialer)
|
p.dialer = a.MustComponent(dialer.CName).(dialer.Dialer)
|
||||||
|
var reg *prometheus.Registry
|
||||||
|
if m := a.Component(metric.CName); m != nil {
|
||||||
|
reg = m.(metric.Metric).Registry()
|
||||||
|
}
|
||||||
p.cache = ocache.New(
|
p.cache = ocache.New(
|
||||||
func(ctx context.Context, id string) (value ocache.Object, err error) {
|
func(ctx context.Context, id string) (value ocache.Object, err error) {
|
||||||
return p.dialer.Dial(ctx, id)
|
return p.dialer.Dial(ctx, id)
|
||||||
@ -54,6 +60,7 @@ func (p *pool) Init(a *app.App) (err error) {
|
|||||||
ocache.WithLogger(log.Sugar()),
|
ocache.WithLogger(log.Sugar()),
|
||||||
ocache.WithGCPeriod(time.Minute),
|
ocache.WithGCPeriod(time.Minute),
|
||||||
ocache.WithTTL(time.Minute*5),
|
ocache.WithTTL(time.Minute*5),
|
||||||
|
ocache.WithPrometheus(reg, "netpool", "cache"),
|
||||||
)
|
)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user