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 == "" {
|
||||
subsystem = "cache"
|
||||
}
|
||||
if reg == nil {
|
||||
return nil
|
||||
}
|
||||
return func(cache *oCache) {
|
||||
cache.metrics = &metrics{
|
||||
hit: prometheus.NewCounter(prometheus.CounterOpts{
|
||||
|
||||
@ -61,7 +61,9 @@ func New(loadFunc LoadFunc, opts ...Option) OCache {
|
||||
log: log.Sugar(),
|
||||
}
|
||||
for _, o := range opts {
|
||||
o(c)
|
||||
if o != nil {
|
||||
o(c)
|
||||
}
|
||||
}
|
||||
if c.ttl != 0 && c.gc != 0 {
|
||||
go c.ticker()
|
||||
|
||||
@ -6,8 +6,10 @@ import (
|
||||
"github.com/anytypeio/any-sync/app"
|
||||
"github.com/anytypeio/any-sync/app/logger"
|
||||
"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/peer"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
@ -47,6 +49,10 @@ type pool struct {
|
||||
|
||||
func (p *pool) Init(a *app.App) (err error) {
|
||||
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(
|
||||
func(ctx context.Context, id string) (value ocache.Object, err error) {
|
||||
return p.dialer.Dial(ctx, id)
|
||||
@ -54,6 +60,7 @@ func (p *pool) Init(a *app.App) (err error) {
|
||||
ocache.WithLogger(log.Sugar()),
|
||||
ocache.WithGCPeriod(time.Minute),
|
||||
ocache.WithTTL(time.Minute*5),
|
||||
ocache.WithPrometheus(reg, "netpool", "cache"),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user