2019-10-16 19:08:33 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2019-11-08 20:40:39 +00:00
|
|
|
"github.com/spacemonkeygo/monkit/v3"
|
2019-10-16 19:08:33 +01:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/sync2"
|
2021-07-01 15:48:07 +01:00
|
|
|
"storj.io/storj/satellite/metabase/segmentloop"
|
2019-10-16 19:08:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// Error defines the metrics chore errors class.
|
2021-04-28 09:06:17 +01:00
|
|
|
Error = errs.Class("metrics")
|
2019-10-16 19:08:33 +01:00
|
|
|
mon = monkit.Package()
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config contains configurable values for metrics collection.
|
|
|
|
type Config struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Chore implements the metrics chore.
|
|
|
|
//
|
|
|
|
// architecture: Chore
|
|
|
|
type Chore struct {
|
2021-07-01 15:48:07 +01:00
|
|
|
log *zap.Logger
|
|
|
|
config Config
|
|
|
|
Loop *sync2.Cycle
|
|
|
|
segmentLoop *segmentloop.Service
|
|
|
|
Counter *Counter
|
2019-10-16 19:08:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewChore creates a new instance of the metrics chore.
|
2021-07-01 15:48:07 +01:00
|
|
|
func NewChore(log *zap.Logger, config Config, loop *segmentloop.Service) *Chore {
|
2019-10-16 19:08:33 +01:00
|
|
|
return &Chore{
|
2021-04-10 10:34:22 +01:00
|
|
|
log: log,
|
|
|
|
config: config,
|
2021-07-30 16:31:20 +01:00
|
|
|
// This chore monitors segment loop, so it's fine to use very small cycle time.
|
2021-07-01 15:48:07 +01:00
|
|
|
Loop: sync2.NewCycle(time.Nanosecond),
|
|
|
|
segmentLoop: loop,
|
2019-10-16 19:08:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
|
2021-07-01 15:48:07 +01:00
|
|
|
err = chore.segmentLoop.Monitor(ctx, chore.Counter)
|
2019-10-16 19:08:33 +01:00
|
|
|
if err != nil {
|
2021-07-01 15:48:07 +01:00
|
|
|
chore.log.Error("error joining segment loop", zap.Error(err))
|
2019-10-16 19:08:33 +01:00
|
|
|
return nil
|
|
|
|
}
|
2021-07-01 15:48:07 +01:00
|
|
|
mon.IntVal("remote_dependent_object_count").Observe(chore.Counter.RemoteObjects)
|
|
|
|
mon.IntVal("inline_object_count").Observe(chore.Counter.InlineObjects)
|
|
|
|
|
2021-07-30 16:31:20 +01:00
|
|
|
mon.IntVal("total_inline_bytes").Observe(chore.Counter.TotalInlineBytes) //mon:locked
|
|
|
|
mon.IntVal("total_remote_bytes").Observe(chore.Counter.TotalRemoteBytes) //mon:locked
|
|
|
|
|
|
|
|
mon.IntVal("total_inline_segments").Observe(chore.Counter.TotalInlineSegments) //mon:locked
|
|
|
|
mon.IntVal("total_remote_segments").Observe(chore.Counter.TotalRemoteSegments) //mon:locked
|
|
|
|
|
2021-07-01 15:48:07 +01:00
|
|
|
// TODO move this metric to a place where objects are iterated e.g. tally
|
|
|
|
// or drop it completely as we can easily get this value with redash
|
|
|
|
// mon.IntVal("total_object_count").Observe(chore.Counter.ObjectCount)
|
2019-10-16 19:08:33 +01:00
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close closes metrics chore.
|
|
|
|
func (chore *Chore) Close() error {
|
|
|
|
chore.Loop.Close()
|
|
|
|
return nil
|
|
|
|
}
|