metrics

package
v0.0.0-...-fee140a Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 6 Imported by: 0

README

metrics

Contains interfaces and methods for generating application metrics and sending them to external services. Metrics can be generated anywhere in the application and optionally sent to a single external service. The naming convention for metrics names and attributes is PascalCase, also known as upper camel case (e.g. UpperCamelCase).

Information for each metrics generator is available in the GoDoc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(ctx context.Context, data Data) error

Generate is a convenience function that encapsulates the factory function and creates a metric. If the SUBSTATION_METRICS environment variable is not set, then no metrics are created.

func Make

func Make(destination string) (generator, error)

Make returns a configured generator.

Types

type AWSCloudWatchEmbeddedMetrics

type AWSCloudWatchEmbeddedMetrics struct{}

AWSCloudWatchEmbeddedMetrics creates a metric in the AWS Embedded Metrics Format and writes it to standard output. This is the preferred method for generating metrics from AWS Lambda functions. Read more about the Embedded Metrics Format specification here: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format_Specification.html.

func (AWSCloudWatchEmbeddedMetrics) Generate

func (m AWSCloudWatchEmbeddedMetrics) Generate(ctx context.Context, data Data) (err error)

Generate creates a metric with the AWSCloudWatchEmbeddedMetrics metrics generator. All Attributes in the metrics.Data struct are inserted as CloudWatch Metrics dimensions; if the generator is invoked from an AWS Lambda function, then the function name is automatically added as a dimension. This method creates a JSON object with the structure shown below, where references are filled in from the metrics.Data struct:

{
	"_aws": {
		"Timestamp": $currentTime,
		"CloudWatchMetrics": [
			{
				"Namespace": $metricsApplication,
				"Dimensions": [
					[
						$data.Attributes.key
					]
				],
				"Name": $data.Name,
			}
		]
	},
	$data.Attributes.key: $data.Attributes.value,
	$data.Name: $data.Value
}

type Data

type Data struct {
	// Contextual information related to the metric. If the external service accepts key-value pairs (e.g., identifiers, tags), then this is passed directly to the service.
	Attributes map[string]string

	// A short name that describes the metric. This is passed directly to the external service and should use the upper camel case (UpperCamelCase) naming convention.
	Name string

	// The metric data point. This value is converted to the correct data type before being sent to the external service.
	Value interface{}
}

Data contains a metric that can be sent to external services.

func (*Data) AddAttributes

func (d *Data) AddAttributes(attr map[string]string)

AddAttributes is a convenience method for adding attributes to a metric.

Jump to

Keyboard shortcuts

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