models

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Default size of metrics batch size.
	DefaultMetricBatchSize = 1000

	// Default number of metrics kept. It should be a multiple of batch size.
	DefaultMetricBufferLimit = 10000
)

Variables

View Source
var (
	AgentMetricsWritten = selfstat.Register("agent", "metrics_written", map[string]string{})
	AgentMetricsDropped = selfstat.Register("agent", "metrics_dropped", map[string]string{})
)
View Source
var (
	GlobalMetricsGathered = selfstat.Register("agent", "metrics_gathered", map[string]string{})
	GlobalGatherErrors    = selfstat.Register("agent", "gather_errors", map[string]string{})
)

Functions

func SetLoggerOnPlugin

func SetLoggerOnPlugin(i interface{}, log cua.Logger)

Types

type AggregatorConfig

type AggregatorConfig struct {
	Tags              map[string]string
	Name              string
	Alias             string
	MeasurementSuffix string
	NameOverride      string
	MeasurementPrefix string
	Filter            Filter
	Grace             time.Duration
	Period            time.Duration
	Delay             time.Duration
	DropOriginal      bool
}

AggregatorConfig is the common config for all aggregators.

type Buffer

type Buffer struct {
	sync.Mutex
	BufferSize     selfstat.Stat
	MetricsDropped selfstat.Stat
	MetricsWritten selfstat.Stat
	MetricsAdded   selfstat.Stat
	BufferLimit    selfstat.Stat
	// contains filtered or unexported fields
}

Buffer stores metrics in a circular buffer.

func NewBuffer

func NewBuffer(name string, alias string, capacity int) *Buffer

NewBuffer returns a new empty Buffer with the given capacity.

func (*Buffer) Accept

func (b *Buffer) Accept(batch []cua.Metric)

Accept marks the batch, acquired from Batch(), as successfully written.

func (*Buffer) Add

func (b *Buffer) Add(metrics ...cua.Metric) int

Add adds metrics to the buffer and returns number of dropped metrics.

func (*Buffer) Batch

func (b *Buffer) Batch(batchSize int) []cua.Metric

Batch returns a slice containing up to batchSize of the oldest metrics not yet dropped. Metrics are ordered from oldest to newest in the batch. The batch must not be modified by the client.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of metrics currently in the buffer.

func (*Buffer) Reject

func (b *Buffer) Reject(batch []cua.Metric)

Reject returns the batch, acquired from Batch(), to the buffer and marks it as unsent.

type Filter

type Filter struct {
	NameDrop   []string
	FieldPass  []string
	TagDrop    []TagFilter
	TagPass    []TagFilter
	TagExclude []string
	FieldDrop  []string
	TagInclude []string
	NamePass   []string
	// contains filtered or unexported fields
}

Filter containing drop/pass and tagdrop/tagpass rules

func (*Filter) Compile

func (f *Filter) Compile() error

Compile all Filter lists into filter.Filter objects.

func (*Filter) IsActive

func (f *Filter) IsActive() bool

IsActive checking if filter is active

func (*Filter) Modify

func (f *Filter) Modify(metric cua.Metric)

Modify removes any tags and fields from the metric according to the fieldpass/fielddrop and taginclude/tagexclude filters.

func (*Filter) Select

func (f *Filter) Select(metric cua.Metric) bool

Select returns true if the metric matches according to the namepass/namedrop and tagpass/tagdrop filters. The metric is not modified.

type InputConfig

type InputConfig struct {
	Tags              map[string]string
	Name              string
	InstanceID        string
	Alias             string
	NameOverride      string
	MeasurementPrefix string
	MeasurementSuffix string
	CheckDisplayName  string
	CheckTarget       string
	CheckTags         map[string]string
	Filter            Filter
	Precision         time.Duration
	Interval          time.Duration
	CollectionJitter  time.Duration
}

InputConfig is the common config for all inputs.

type Logger

type Logger struct {
	Name   string // Name is the plugin name, will be printed in the `[]`.
	OnErrs []func()
}

Logger defines a logging structure for plugins.

func NewLogger

func NewLogger(pluginType, name, alias string) *Logger

NewLogger creates a new logger instance

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

Debug logs a debug message, patterned after log.Print.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Debugf logs a debug message, patterned after log.Printf.

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

Error logs an error message, patterned after log.Print.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf logs an error message, patterned after log.Printf.

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

Info logs an information message, patterned after log.Print.

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

Infof logs an information message, patterned after log.Printf.

func (*Logger) OnErr

func (l *Logger) OnErr(f func())

OnErr defines a callback that triggers only when errors are about to be written to the log

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

Warn logs a warning message, patterned after log.Print.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

Warnf logs a warning message, patterned after log.Printf.

type OutputConfig

type OutputConfig struct {
	Name              string
	Alias             string
	NamePrefix        string
	NameSuffix        string
	NameOverride      string
	Filter            Filter
	FlushJitter       time.Duration
	MetricBufferLimit int
	MetricBatchSize   int
	FlushInterval     time.Duration
}

OutputConfig containing name and filter

type ProcessorConfig

type ProcessorConfig struct {
	Name   string
	Alias  string
	Filter Filter
	Order  int64
}

FilterConfig containing a name and filter

type RunningAggregator

type RunningAggregator struct {
	sync.Mutex
	Aggregator cua.Aggregator
	Config     *AggregatorConfig

	MetricsPushed   selfstat.Stat
	MetricsFiltered selfstat.Stat
	MetricsDropped  selfstat.Stat
	PushTime        selfstat.Stat
	// contains filtered or unexported fields
}

func NewRunningAggregator

func NewRunningAggregator(aggregator cua.Aggregator, config *AggregatorConfig) *RunningAggregator

func (*RunningAggregator) Add

func (r *RunningAggregator) Add(m cua.Metric) bool

Add a metric to the aggregator and return true if the original metric should be dropped.

func (*RunningAggregator) EndPeriod

func (r *RunningAggregator) EndPeriod() time.Time

func (*RunningAggregator) Init

func (r *RunningAggregator) Init() error

func (*RunningAggregator) Log

func (r *RunningAggregator) Log() cua.Logger

func (*RunningAggregator) LogName

func (r *RunningAggregator) LogName() string

func (*RunningAggregator) MakeMetric

func (r *RunningAggregator) MakeMetric(metric cua.Metric) cua.Metric

func (*RunningAggregator) Period

func (r *RunningAggregator) Period() time.Duration

func (*RunningAggregator) Push

func (r *RunningAggregator) Push(acc cua.Accumulator)

func (*RunningAggregator) UpdateWindow

func (r *RunningAggregator) UpdateWindow(start, until time.Time)

type RunningInput

type RunningInput struct {
	Input  cua.Input
	Config *InputConfig

	MetricsGathered selfstat.Stat
	GatherTime      selfstat.Stat
	// contains filtered or unexported fields
}

func NewRunningInput

func NewRunningInput(input cua.Input, config *InputConfig) *RunningInput

func (*RunningInput) Gather

func (r *RunningInput) Gather(ctx context.Context, acc cua.Accumulator) error

func (*RunningInput) Init

func (r *RunningInput) Init() error

func (*RunningInput) Log

func (r *RunningInput) Log() cua.Logger

func (*RunningInput) LogName

func (r *RunningInput) LogName() string

func (*RunningInput) MakeMetric

func (r *RunningInput) MakeMetric(metric cua.Metric) cua.Metric

func (*RunningInput) SetDefaultTags

func (r *RunningInput) SetDefaultTags(tags map[string]string)

type RunningOutput

type RunningOutput struct {
	MetricsFiltered selfstat.Stat
	WriteTime       selfstat.Stat
	Output          cua.Output

	Config     *OutputConfig
	BatchReady chan time.Time

	MetricBufferLimit int
	MetricBatchSize   int
	// contains filtered or unexported fields
}

RunningOutput contains the output configuration

func NewRunningOutput

func NewRunningOutput(
	name string,
	output cua.Output,
	config *OutputConfig,
	batchSize int,
	bufferLimit int,
) *RunningOutput

func (*RunningOutput) AddMetric

func (ro *RunningOutput) AddMetric(metric cua.Metric)

AddMetric adds a metric to the output.

Takes ownership of metric

func (*RunningOutput) BufferLength

func (ro *RunningOutput) BufferLength() int

func (*RunningOutput) Close

func (ro *RunningOutput) Close()

Close closes the output

func (*RunningOutput) Init

func (ro *RunningOutput) Init() error

func (*RunningOutput) Log

func (ro *RunningOutput) Log() cua.Logger

func (*RunningOutput) LogBufferStatus

func (ro *RunningOutput) LogBufferStatus()

func (*RunningOutput) LogName

func (ro *RunningOutput) LogName() string

func (*RunningOutput) Write

func (ro *RunningOutput) Write() error

Write writes all metrics to the output, stopping when all have been sent on or error.

func (*RunningOutput) WriteBatch

func (ro *RunningOutput) WriteBatch() error

WriteBatch writes a single batch of metrics to the output.

type RunningProcessor

type RunningProcessor struct {
	sync.Mutex

	Processor cua.StreamingProcessor
	Config    *ProcessorConfig
	// contains filtered or unexported fields
}

func NewRunningProcessor

func NewRunningProcessor(processor cua.StreamingProcessor, config *ProcessorConfig) *RunningProcessor

func (*RunningProcessor) Add

func (rp *RunningProcessor) Add(m cua.Metric, acc cua.Accumulator) error

func (*RunningProcessor) Init

func (rp *RunningProcessor) Init() error

func (*RunningProcessor) Log

func (rp *RunningProcessor) Log() cua.Logger

func (*RunningProcessor) LogName

func (rp *RunningProcessor) LogName() string

func (*RunningProcessor) MakeMetric

func (rp *RunningProcessor) MakeMetric(metric cua.Metric) cua.Metric

func (*RunningProcessor) Start

func (rp *RunningProcessor) Start(acc cua.Accumulator) error

func (*RunningProcessor) Stop

func (rp *RunningProcessor) Stop()

type RunningProcessors

type RunningProcessors []*RunningProcessor

func (RunningProcessors) Len

func (rp RunningProcessors) Len() int

func (RunningProcessors) Less

func (rp RunningProcessors) Less(i, j int) bool

func (RunningProcessors) Swap

func (rp RunningProcessors) Swap(i, j int)

type TagFilter

type TagFilter struct {
	Name   string
	Filter []string
	// contains filtered or unexported fields
}

TagFilter is the name of a tag, and the values on which to filter

Jump to

Keyboard shortcuts

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