storj/satellite/metrics/chore.go
Jeff Wendling 7999d24f81 all: use monkit v3
this commit updates our monkit dependency to the v3 version where
it outputs in an influx style. this makes discovery much easier
as many tools are built to look at it this way.

graphite and rothko will suffer some due to no longer being a tree
based on dots. hopefully time will exist to update rothko to
index based on the new metric format.

it adds an influx output for the statreceiver so that we can
write to influxdb v1 or v2 directly.

Change-Id: Iae9f9494a6d29cfbd1f932a5e71a891b490415ff
2020-02-05 23:53:17 +00:00

77 lines
1.8 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package metrics
import (
"context"
"time"
"github.com/spacemonkeygo/monkit/v3"
"github.com/zeebo/errs"
"go.uber.org/zap"
"storj.io/common/sync2"
"storj.io/storj/satellite/metainfo"
)
var (
// Error defines the metrics chore errors class.
Error = errs.Class("metrics chore error")
mon = monkit.Package()
)
// Config contains configurable values for metrics collection.
type Config struct {
ChoreInterval time.Duration `help:"the time between each metrics chore run" releaseDefault:"15m" devDefault:"15m"`
}
// Chore implements the metrics chore.
//
// architecture: Chore
type Chore struct {
log *zap.Logger
config Config
Loop *sync2.Cycle
metainfoLoop *metainfo.Loop
Counter *Counter
}
// NewChore creates a new instance of the metrics chore.
func NewChore(log *zap.Logger, config Config, loop *metainfo.Loop) *Chore {
return &Chore{
log: log,
config: config,
Loop: sync2.NewCycle(config.ChoreInterval),
metainfoLoop: loop,
}
}
// Run starts the metrics chore.
func (chore *Chore) Run(ctx context.Context) (err error) {
defer mon.Task()(&ctx)(&err)
return chore.Loop.Run(ctx, func(ctx context.Context) (err error) {
defer mon.Task()(&ctx)(&err)
chore.Counter = NewCounter()
err = chore.metainfoLoop.Join(ctx, chore.Counter)
if err != nil {
chore.log.Error("error joining metainfoloop", zap.Error(err))
return nil
}
mon.IntVal("remote_dependent_object_count").Observe(chore.Counter.RemoteDependent)
mon.IntVal("inline_object_count").Observe(chore.Counter.Inline)
mon.IntVal("total_object_count").Observe(chore.Counter.Total)
return nil
})
}
// Close closes metrics chore.
func (chore *Chore) Close() error {
chore.Loop.Close()
return nil
}