metrics

package
v0.0.0-...-3736fb9 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package metrics provides setup of metrics that can be used internally to measure various application states. All metrics for the application are defined here and other applications use this package to grab the metrics and use them. This package will also report any metric that is not used in the first 10 seconds after the app has started to prevent useless metrics from existing, as all metrics should be grabbed by that time.

In a package you want to set metrics, you can do it as follows:

var addCount metrics.Int64Counter

func init() {
	addCounter = metrics.Get.Int64("petstore/server/AddPets/requests")
}
...

func (s *Server) AddPets(ctx context.Context, req *pb.AddPetsReq) (*pb.AddpetsResp, error) {
	...
	// Do this if you have multiple changes that don't require special labels per update.
	metrics.Meter.RecordBatch(ctx, nil, addCounter.Measure(ctx, 1))
	// Do this if you only need to make one change or need special labels.
	addCounter.Add(ctx, 1, attribute.String("label", "value")
	...
}

To cause metrics to be exported package main():

func main() {
	...
	stop, err := metrics.Start(ctx, metrics.OTELGRPC{Addr: "ip:port"})
	if err != nil {
		log.Fatal(err)
	}
	defer stop()
	...
}

Index

Constants

This section is empty.

Variables

View Source
var Get = newLookups()

Get is used to lookup metrics by name.

View Source
var Meter = global.Meter("petstore")

Meter is the meter for the petstore.

Functions

This section is empty.

Types

type Controller

type Controller interface {
	// contains filtered or unexported methods
}

Controller represents the controller to send metrics to.

type Lookups

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

Lookups provides lookups for metrics based on their names.

func (*Lookups) Int64

func (l *Lookups) Int64(s string) metric.Int64Counter

Int64 grabs the Int64Counter metric named "s". If not found, panics.

func (*Lookups) Int64Hist

func (l *Lookups) Int64Hist(s string) metric.Int64Histogram

Int64Hist grabs the Int64Histogram metric named "s". If not found, panics.

func (*Lookups) Int64Hists

func (l *Lookups) Int64Hists(s ...string) []metric.Int64Histogram

func (*Lookups) Int64UD

func (l *Lookups) Int64UD(s string) metric.Int64UpDownCounter

Int64UD grabs the Int64UpDownCounter metric named "s". If not found, panics.

func (*Lookups) Int64UDs

func (l *Lookups) Int64UDs(s ...string) []metric.Int64UpDownCounter

Int64UDs grabs a list of Int64UpDownCounters.

func (*Lookups) Int64s

func (l *Lookups) Int64s(s ...string) []metric.Int64Counter

Int64s grabs a list of Int64Counters.

type OTELGRPC

type OTELGRPC struct {
	// Addr is the local address to export on.
	Addr string
}

OTELGRPC represents exporting to the "go.opentelemetry.io/otel/sdk/metric/controller/basic" controller.

type Stop

type Stop func()

Stop is used to stop OTEL metric handling.

func Start

func Start(ctx context.Context, c Controller) (Stop, error)

Start is used to start OTEL metric handling.

Jump to

Keyboard shortcuts

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