metric

package
v0.24.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnitCountAverage        = types.StandardUnit("UnitCountAverage")
	UnitCountMaximum        = types.StandardUnit("UnitCountMaximum")
	UnitCountMinimum        = types.StandardUnit("UnitCountMinimum")
	UnitSecondsAverage      = types.StandardUnit("UnitSecondsAverage")
	UnitSecondsMaximum      = types.StandardUnit("UnitSecondsMaximum")
	UnitSecondsMinimum      = types.StandardUnit("UnitSecondsMinimum")
	UnitMillisecondsAverage = types.StandardUnit("UnitMillisecondsAverage")
	UnitMillisecondsMaximum = types.StandardUnit("UnitMillisecondsMaximum")
	UnitMillisecondsMinimum = types.StandardUnit("UnitMillisecondsMinimum")
)
View Source
const (
	PriorityLow  = 1
	PriorityHigh = 2

	UnitCount        = types.StandardUnitCount
	UnitSeconds      = types.StandardUnitSeconds
	UnitMilliseconds = types.StandardUnitMilliseconds
)
View Source
const (
	WriterTypeCw   = "cw"
	WriterTypeES   = "es"
	WriterTypeProm = "prom"
)

Variables

This section is empty.

Functions

func GetCloudWatchNamespace added in v0.22.0

func GetCloudWatchNamespace(config cfg.Config) string

func LoggerHandlerFactory

func LoggerHandlerFactory(_ cfg.Config, _ string) (log.Handler, error)

func NewCwWriterWithInterfaces

func NewCwWriterWithInterfaces(logger log.Logger, clock clock.Clock, cw gosoCloudwatch.Client, cwNamespace string) *cwWriter

func NewEsWriter

func NewEsWriter(config cfg.Config, logger log.Logger) (*esWriter, error)

func NewEsWriterWithInterfaces

func NewEsWriterWithInterfaces(logger log.Logger, client *es.ClientV7, clock clock.Clock, namespace string) *esWriter

func NewMetricModule

func NewMetricModule(ctx context.Context, config cfg.Config, logger log.Logger) (kernel.Module, error)

func NewMetricServer

func NewMetricServer(ctx context.Context, config cfg.Config, logger log.Logger) (kernel.Module, error)

func NewMetricServerWithInterfaces

func NewMetricServerWithInterfaces(
	logger log.Logger,
	registry *prometheus.Registry,
	channel *metricChannel,
	writer Writer,
	s *PromSettings,
) (*metricsServer, error)

func NewPromWriter

func NewPromWriter(ctx context.Context, config cfg.Config, logger log.Logger) (*promWriter, error)

func NewPromWriterWithInterfaces

func NewPromWriterWithInterfaces(logger log.Logger, registry *prometheus.Registry, namespace string, metricLimit int64) *promWriter

func ProvideRegistry

func ProvideRegistry(ctx context.Context, name string) (*prometheus.Registry, error)

func ProviderMetricChannel

func ProviderMetricChannel() *metricChannel

func RegisterCustomUnit

func RegisterCustomUnit(unit types.StandardUnit, standardUnit types.StandardUnit, reducer func(xs []float64) float64)

func WithPromNSNamingStrategy

func WithPromNSNamingStrategy(strategy NamingFactory)

Types

type BatchedMetricDatum

type BatchedMetricDatum struct {
	Priority   int
	Timestamp  time.Time
	MetricName string
	Dimensions Dimensions
	Values     []float64
	Unit       types.StandardUnit
}

type Cloudwatch

type Cloudwatch struct {
	Naming NamingSettings `cfg:"naming"`
}

type Daemon

type Daemon struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewDaemon

func NewDaemon(ctx context.Context, config cfg.Config, logger log.Logger) (*Daemon, error)

func NewMetricDaemonWithInterfaces

func NewMetricDaemonWithInterfaces(logger log.Logger, channel *metricChannel, writer Writer, settings *Settings) (*Daemon, error)

func (*Daemon) GetStage

func (d *Daemon) GetStage() int

func (*Daemon) IsBackground

func (d *Daemon) IsBackground() bool

func (*Daemon) IsEssential

func (d *Daemon) IsEssential() bool

func (*Daemon) Run

func (d *Daemon) Run(ctx context.Context) error

type Data

type Data []*Datum

type Datum

type Datum struct {
	Priority   int          `json:"-"`
	Timestamp  time.Time    `json:"timestamp"`
	MetricName string       `json:"metricName"`
	Dimensions Dimensions   `json:"dimensions"`
	Value      float64      `json:"value"`
	Unit       StandardUnit `json:"unit"`
}

func (*Datum) DimensionKey

func (d *Datum) DimensionKey() string

func (*Datum) Id

func (d *Datum) Id() string

func (*Datum) IsValid

func (d *Datum) IsValid() error

type Dimensions

type Dimensions map[string]string

type LoggerHandler

type LoggerHandler struct {
	// contains filtered or unexported fields
}

func NewLoggerHandler

func NewLoggerHandler() *LoggerHandler

func (LoggerHandler) Channels

func (h LoggerHandler) Channels() []string

func (LoggerHandler) Level

func (h LoggerHandler) Level() int

func (LoggerHandler) Log

func (h LoggerHandler) Log(_ time.Time, level int, _ string, _ []interface{}, _ error, _ log.Data) error

type NamingFactory

type NamingFactory func(modelId cfg.AppId) string

type NamingSettings

type NamingSettings struct {
	Pattern string `cfg:"pattern,nodecode" default:"{project}/{env}/{family}/{group}-{app}"`
}

type PromServerSettings

type PromServerSettings struct {
	Enabled bool            `cfg:"enabled" default:"true"`
	Port    int             `cfg:"port" default:"8092"`
	Path    string          `cfg:"path" default:"/metrics"`
	Timeout TimeoutSettings `cfg:"timeout"`
}

type PromSettings

type PromSettings struct {
	// MetricLimit is used to avoid having metrics for which the name is programmatically generated (or have large number
	// of possible dimensions) which could lead in a memory leak.
	MetricLimit int64              `cfg:"metric_limit" default:"10000"`
	Api         PromServerSettings `cfg:"api"`
}

type Settings

type Settings struct {
	cfg.AppId
	Enabled    bool          `cfg:"enabled" default:"false"`
	Interval   time.Duration `cfg:"interval" default:"60s"`
	Cloudwatch Cloudwatch    `cfg:"cloudwatch"`
	Writer     string        `cfg:"writer"`
}

type StandardUnit

type StandardUnit = types.StandardUnit
const (
	UnitPromCounter   StandardUnit = "prom-counter"
	UnitPromGauge     StandardUnit = "prom-gauge"
	UnitPromHistogram StandardUnit = "prom-histogram"
	UnitPromSummary   StandardUnit = "prom-summary"
)

type TimeoutSettings

type TimeoutSettings struct {
	// You need to give at least 1s as timeout.
	// Read timeout is the maximum duration for reading the entire request, including the body.
	Read time.Duration `cfg:"read" default:"60s" validate:"min=1000000000"`
	// Write timeout is the maximum duration before timing out writes of the response.
	Write time.Duration `cfg:"write" default:"60s" validate:"min=1000000000"`
	// Idle timeout is the maximum amount of time to wait for the next request when keep-alives are enabled
	Idle time.Duration `cfg:"idle" default:"60s" validate:"min=1000000000"`
}

TimeoutSettings configures IO timeouts.

type Writer

type Writer interface {
	GetPriority() int
	Write(batch Data)
	WriteOne(data *Datum)
}

func NewCwWriter

func NewCwWriter(ctx context.Context, config cfg.Config, logger log.Logger) (Writer, error)

func NewWriter

func NewWriter(defaults ...*Datum) Writer

func NewWriterWithInterfaces

func NewWriterWithInterfaces(clock clock.Clock, channel *metricChannel) Writer

func ProvideMetricWriterByType

func ProvideMetricWriterByType(ctx context.Context, config cfg.Config, logger log.Logger, typ string) (Writer, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL