metrics

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2020 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnitBytes = "Bytes"
	// UnitSeconds      = "Seconds"
	// UnitMicroseconds = "Microseconds"
	UnitMilliseconds = "Milliseconds"
	UnitCount        = "Count"
)

Values that AWS understands as Metric Units

View Source
const (
	Namespace = "Panther"
)
View Source
const NanosecondsPerMillisecond int64 = 1000000

The standard go time library supports nanoseconds since epoch time, not milliseconds. So we frequently convert.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dimension

type Dimension struct {
	Name  string
	Value string
}

Dimension represents the name and value of a given dimension. Each dimension must have its name in at least one DimensionSet to be recognized as a dimension.

type DimensionSet

type DimensionSet = []string

DimensionSet is a slice of strings containing the dimension names that will be applied to all metrics logged. The values within this slice MUST also be members on the root node, referred to as the Target Members

A DimensionSet MUST NOT contain more than 9 dimension keys.

The target member defines a dimension that will be published as part of the metric identity. Every DimensionSet used creates a new metric in CloudWatch.

type EmbeddedMetric

type EmbeddedMetric struct {
	// A slice of MetricDirectiveObjects used to instruct CloudWatch to extract metrics from the
	// root node of the LogEvent.
	CloudWatchMetrics []MetricDirectiveObject

	// A number representing the time stamp used for metrics extracted from the event. Values MUST
	// be expressed as the number of milliseconds after Jan 1, 1970 00:00:00 UTC.
	Timestamp int64
}

EmbeddedMetric is the value mapped to the required top level member of the root node `_aws` in the AWS embedded metric format.

type Logger

type Logger interface {
	Log(dimensions []Dimension, values ...Metric)
}

func MustLogger

func MustLogger(dimensionSets []DimensionSet) Logger

MustLogger creates a new Logger based on the given input, and panics if the input is invalid

func NewLogger

func NewLogger(dimensionSets []DimensionSet) (Logger, error)

NewLogger create a new logger for a set of dimensions, returning an error if dimensions are invalid

type Metric

type Metric struct {
	// A reference to a metric Target Member. Each Metric Name must also be a top level member.
	Name string

	// Valid Unit values (defaults to None):
	// Seconds | Microseconds | Milliseconds | Bytes | Kilobytes | Megabytes | Gigabytes | Terabytes
	// Bits | Kilobits | Megabits | Gigabits | Terabits | Percent | Count | Bytes/Second |
	// Kilobytes/Second | Megabytes/Second | Gigabytes/Second | Terabytes/Second | Bits/Second |
	// Kilobits/Second | Megabits/Second | Gigabits/Second | Terabits/Second | Count/Second | None
	Unit string

	// This value is not marshalled to JSON as it is not part of the AWS embedded metric format. We
	// simply include it here for convenience when calling the loggers defined here, so that it is
	// not required to consider the value of a metric separate from its Name and Unit.
	Value interface{} `json:"-"`
}

Metric contains a name and a unit used to describe a particular metric value

type MetricDirectiveObject

type MetricDirectiveObject struct {
	// A string representing the CloudWatch namespace for the metric.
	Namespace string

	// A slice representing the collection of DimensionSets for the metric
	Dimensions []DimensionSet

	// A slice of Metric values and units. This slice MUST NOT contain more than 100 Metrics.
	Metrics []Metric
}

MetricDirectiveObject instructs downstream services that the LogEvent contains metrics that will be extracted and published to CloudWatch.

type StaticLogger

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

StaticLogger conveniently stores repeatedly used embedded metric format configurations such as dimensionSets and metric name/unit so that they do not need to be specified each time. StaticLogger only supports one dimension set and one metric which must be set at initialization.

These limitations still allow for 90% of use cases, and are more suitable for performance critical parts of the code than the Logger.

func MustStaticLogger

func MustStaticLogger(dimensionSets []DimensionSet, metrics []Metric) *StaticLogger

MustStaticLogger creates a new StaticLogger based on the given input, and panics if the input is invalid

func NewStaticLogger

func NewStaticLogger(dimensionSets []DimensionSet, metrics []Metric) (*StaticLogger, error)

NewStaticLogger create a new logger for a given set of dimensions and metric, returning an error if the dimensions or metric are invalid

func (*StaticLogger) Log

func (l *StaticLogger) Log(metrics []Metric, dimensions ...Dimension)

Log sends a log formatted in the CloudWatch embedded metric format

func (*StaticLogger) LogSingle

func (l *StaticLogger) LogSingle(value interface{}, dimensions ...Dimension)

LogSingle sends a log for a single metric

Jump to

Keyboard shortcuts

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