metric

package
v0.34.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: MIT Imports: 33 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 (
	WriterTypeCloudwatch    = "cw"
	WriterTypeElasticsearch = "es"
	WriterTypePrometheus    = "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 NewCloudwatchWriterWithInterfaces added in v0.32.0

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

func NewDaemonModule added in v0.32.0

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

func NewMetricDaemonWithInterfaces

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

func NewMetricServerWithInterfaces

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

func NewPrometheusMetricServer added in v0.32.0

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

func NewPrometheusMetricsServerModule added in v0.32.0

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

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 (*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) DimensionKV added in v0.32.1

func (d *Datum) DimensionKV() 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 NewCloudwatchWriter added in v0.32.0

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

func NewElasticsearchWriter added in v0.32.0

func NewElasticsearchWriter(_ context.Context, config cfg.Config, logger log.Logger) (Writer, error)

func NewElasticsearchWriterWithInterfaces added in v0.32.0

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

func NewMetricWriter added in v0.32.0

func NewMetricWriter(ctx context.Context, config cfg.Config, logger log.Logger, types []string) (Writer, error)

func NewMultiWriterWithInterfaces added in v0.32.0

func NewMultiWriterWithInterfaces(writers []Writer) Writer

func NewPrometheusWriter added in v0.32.0

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

func NewPrometheusWriterWithInterfaces added in v0.32.0

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

func NewWriter

func NewWriter(defaults ...*Datum) Writer

func NewWriterWithInterfaces

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

func ProvideCloudwatchWriter added in v0.32.0

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

func ProvideElasticsearchWriter added in v0.32.0

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

func ProvidePrometheusWriter added in v0.32.0

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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