metrics

package
v0.0.0-...-90deddd Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

Reflow Metrics Library

The Reflow metrics library should be used to provide observability into Reflow.

Defining metrics

Metrics are defined in metrics.yaml. Each named dictionary in the metrics.yaml root array will produce a metric. Note that the name for a metric must be given in snake_case and contain only lowercase alpha characters. Metric configuration dictionaries can have the following fields:

  • Type

    • The following types of metrics are available.
      • counter - counters can only be incremented or reset to zero.
      • gauge - gauges can be incremented, decremented or set to an arbitrary value.
      • histogram - histograms can used to observe arbitrary values (discretized to a set of buckets configured at compilation).
  • Help

    • All metrics should be documented with a helpful help message. This field can be used by clients to provide documentation at query-time.
  • Labels

    • Labels give dimensionality to metrics. Labels are written in snake_case and can only contain lowercase alpha characters.
  • Buckets

    • Buckets is a special field available on the "histogram" metric type. Observations will be discretized to fit into these buckets, based on the implementation of the metrics client.

Regenerating metrics.go

After updating metrics.json, use the genmetrics utility binary to generate static the go package functions that are called to provide observations.

go run cmd/genmetrics/main.go metrics/metrics.yaml metrics

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Counters = map[string]counterOpts{
		"allocs_completed_count": {
			Help: "Count of completed allocs.",
		},
		"allocs_completed_size": {
			Help: "Size of completed allocs.",
		},
		"allocs_started_count": {
			Help: "Count of started allocs.",
		},
		"allocs_started_size": {
			Help: "Size of started allocs.",
		},
		"tasks_completed_count": {
			Help: "Count of completed tasks.",
		},
		"tasks_completed_size": {
			Help: "Size of completed tasks.",
		},
		"tasks_started_count": {
			Help: "Count of started tasks.",
		},
		"tasks_started_size": {
			Help: "Size of started tasks.",
		},
		"tasks_submitted_count": {
			Help: "Count of submitted tasks.",
		},
		"tasks_submitted_size": {
			Help: "Size of submitted tasks.",
		},
	}
	Gauges = map[string]gaugeOpts{
		"allocs_live_resources": {
			Help:   "Resources of live allocs.",
			Labels: []string{"resource"},
		},
		"allocs_live_size": {
			Help: "Size of live allocs.",
		},
		"memstats_heap_inuse_bytes": {
			Help: "Bytes of memory used by in use heap spans.",
		},
		"memstats_heap_objects": {
			Help: "Current number of allocated heap objects.",
		},
		"memstats_heap_sys_bytes": {
			Help: "Bytes of heap memory obtained from the OS.",
		},
		"memstats_stack_inuse_bytes": {
			Help: "Bytes of memory used for stack spans.",
		},
		"memstats_stack_sys_bytes": {
			Help: "Bytes of stack memory obtained from the OS.",
		},
		"pool_avail_resources": {
			Help:   "Available resources in a pool.",
			Labels: []string{"resource"},
		},
		"pool_avail_size": {
			Help: "Available size in a pool.",
		},
		"pool_total_resources": {
			Help:   "Total resources in a pool.",
			Labels: []string{"resource"},
		},
		"pool_total_size": {
			Help: "Total size of a pool.",
		},
		"tasks_in_progress_resources": {
			Help:   "Resources of tasks currently being processed.",
			Labels: []string{"resource"},
		},
		"tasks_in_progress_size": {
			Help: "Size of tasks currently being processed.",
		},
	}
	Histograms = map[string]histogramOpts{
		"dydbassoc_op_latency_seconds": {
			Help:    "Dydbassoc operation latency in seconds.",
			Labels:  []string{"operation"},
			Buckets: []float64{0.001, 0.01, 0.1, 1, 10},
		},
	}
)

Functions

func On

func On(ctx context.Context) bool

On returns true if there is a current Client associated with the provided context.

func WithClient

func WithClient(ctx context.Context, client Client) context.Context

WithClient returns a context that emits trace events to the provided Client.

Types

type Client

type Client interface {
	GetGauge(name string, labels map[string]string) Gauge
	GetCounter(name string, labels map[string]string) Counter
	GetHistogram(name string, labels map[string]string) Histogram
}

Client is a sink for metrics.

var NopClient Client = &nopClient{}

NopClient is default metrics client that does nothing.

type Counter

type Counter interface {
	// Inc adds one to the counter
	Inc()
	// Add adds the given value to the counter. It panics if the value is <
	// 0.
	Add(float64)
}

Counter wraps prometheus.Counter. Counters can only increase in value.

func GetAllocsCompletedCountCounter

func GetAllocsCompletedCountCounter(ctx context.Context) Counter

GetAllocsCompletedCountCounter returns a Counter to set metric allocs_completed_count (count of completed allocs).

func GetAllocsCompletedSizeCounter

func GetAllocsCompletedSizeCounter(ctx context.Context) Counter

GetAllocsCompletedSizeCounter returns a Counter to set metric allocs_completed_size (size of completed allocs).

func GetAllocsStartedCountCounter

func GetAllocsStartedCountCounter(ctx context.Context) Counter

GetAllocsStartedCountCounter returns a Counter to set metric allocs_started_count (count of started allocs).

func GetAllocsStartedSizeCounter

func GetAllocsStartedSizeCounter(ctx context.Context) Counter

GetAllocsStartedSizeCounter returns a Counter to set metric allocs_started_size (size of started allocs).

func GetTasksCompletedCountCounter

func GetTasksCompletedCountCounter(ctx context.Context) Counter

GetTasksCompletedCountCounter returns a Counter to set metric tasks_completed_count (count of completed tasks).

func GetTasksCompletedSizeCounter

func GetTasksCompletedSizeCounter(ctx context.Context) Counter

GetTasksCompletedSizeCounter returns a Counter to set metric tasks_completed_size (size of completed tasks).

func GetTasksStartedCountCounter

func GetTasksStartedCountCounter(ctx context.Context) Counter

GetTasksStartedCountCounter returns a Counter to set metric tasks_started_count (count of started tasks).

func GetTasksStartedSizeCounter

func GetTasksStartedSizeCounter(ctx context.Context) Counter

GetTasksStartedSizeCounter returns a Counter to set metric tasks_started_size (size of started tasks).

func GetTasksSubmittedCountCounter

func GetTasksSubmittedCountCounter(ctx context.Context) Counter

GetTasksSubmittedCountCounter returns a Counter to set metric tasks_submitted_count (count of submitted tasks).

func GetTasksSubmittedSizeCounter

func GetTasksSubmittedSizeCounter(ctx context.Context) Counter

GetTasksSubmittedSizeCounter returns a Counter to set metric tasks_submitted_size (size of submitted tasks).

type Gauge

type Gauge interface {
	// Set updates the value of the gauge
	Set(float64)
	// Inc increments the Gauge by 1. Use Add to increment it by arbitrary
	// values.
	Inc()
	// Dec decrements the Gauge by 1. Use Sub to decrement it by arbitrary
	// values.
	Dec()
	// Add adds the given value to the Gauge. (The value can be negative,
	// resulting in a decrease of the Gauge.)
	Add(float64)
	// Sub subtracts the given value from the Gauge. (The value can be
	// negative, resulting in an increase of the Gauge.)
	Sub(float64)
}

Gauge wraps prometheus.Gauge. Gauges can be set to arbitrary values.

func GetAllocsLiveResourcesGauge

func GetAllocsLiveResourcesGauge(ctx context.Context, resource string) Gauge

GetAllocsLiveResourcesGauge returns a Gauge to set metric allocs_live_resources (resources of live allocs).

func GetAllocsLiveSizeGauge

func GetAllocsLiveSizeGauge(ctx context.Context) Gauge

GetAllocsLiveSizeGauge returns a Gauge to set metric allocs_live_size (size of live allocs).

func GetMemstatsHeapInuseBytesGauge

func GetMemstatsHeapInuseBytesGauge(ctx context.Context) Gauge

GetMemstatsHeapInuseBytesGauge returns a Gauge to set metric memstats_heap_inuse_bytes (bytes of memory used by in use heap spans).

func GetMemstatsHeapObjectsGauge

func GetMemstatsHeapObjectsGauge(ctx context.Context) Gauge

GetMemstatsHeapObjectsGauge returns a Gauge to set metric memstats_heap_objects (current number of allocated heap objects).

func GetMemstatsHeapSysBytesGauge

func GetMemstatsHeapSysBytesGauge(ctx context.Context) Gauge

GetMemstatsHeapSysBytesGauge returns a Gauge to set metric memstats_heap_sys_bytes (bytes of heap memory obtained from the OS).

func GetMemstatsStackInuseBytesGauge

func GetMemstatsStackInuseBytesGauge(ctx context.Context) Gauge

GetMemstatsStackInuseBytesGauge returns a Gauge to set metric memstats_stack_inuse_bytes (bytes of memory used for stack spans).

func GetMemstatsStackSysBytesGauge

func GetMemstatsStackSysBytesGauge(ctx context.Context) Gauge

GetMemstatsStackSysBytesGauge returns a Gauge to set metric memstats_stack_sys_bytes (bytes of stack memory obtained from the OS).

func GetPoolAvailResourcesGauge

func GetPoolAvailResourcesGauge(ctx context.Context, resource string) Gauge

GetPoolAvailResourcesGauge returns a Gauge to set metric pool_avail_resources (available resources in a pool).

func GetPoolAvailSizeGauge

func GetPoolAvailSizeGauge(ctx context.Context) Gauge

GetPoolAvailSizeGauge returns a Gauge to set metric pool_avail_size (available size in a pool).

func GetPoolTotalResourcesGauge

func GetPoolTotalResourcesGauge(ctx context.Context, resource string) Gauge

GetPoolTotalResourcesGauge returns a Gauge to set metric pool_total_resources (total resources in a pool).

func GetPoolTotalSizeGauge

func GetPoolTotalSizeGauge(ctx context.Context) Gauge

GetPoolTotalSizeGauge returns a Gauge to set metric pool_total_size (total size of a pool).

func GetTasksInProgressResourcesGauge

func GetTasksInProgressResourcesGauge(ctx context.Context, resource string) Gauge

GetTasksInProgressResourcesGauge returns a Gauge to set metric tasks_in_progress_resources (resources of tasks currently being processed).

func GetTasksInProgressSizeGauge

func GetTasksInProgressSizeGauge(ctx context.Context) Gauge

GetTasksInProgressSizeGauge returns a Gauge to set metric tasks_in_progress_size (size of tasks currently being processed).

type Histogram

type Histogram interface {
	// Observe adds a sample observation to the histogram
	Observe(float64)
}

Histogram wraps prometheus.Histogram. Histograms record observations of events and discretize them into preconfigured buckets.

func GetDydbassocOpLatencySecondsHistogram

func GetDydbassocOpLatencySecondsHistogram(ctx context.Context, operation string) Histogram

GetDydbassocOpLatencySecondsHistogram returns a Histogram to set metric dydbassoc_op_latency_seconds (dydbassoc operation latency in seconds).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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