metrics

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Overview

Package metrics is a system-independent module it consider metrics key as first-class citizen each function is for recording one kind of metrics key and value it expose standard API to record runtime metrics for a service use prom as default metrics system

Index

Constants

View Source
const (
	LTotalRequest          = "requests_total"
	LTotalSuccess          = "successes_total"
	LTotalFailures         = "failures_total"
	LRequestLatencySeconds = "request_latency_seconds"
	LError4XX              = "status_4xx"
	LError5XX              = "status_5xx"
	LServiceName           = "service_name"
	LApp                   = "app"
	LVersion               = "version"
	LStartTime             = "start_time_seconds"
)

Constants with attributes for metrics data Label start with word "L"

Variables

View Source
var (
	//LabelNames is a fixed list with service name, appID, version
	LabelNames = []string{LServiceName, LApp, LVersion}
)

Functions

func Init

func Init() error

Init initiate the recorder

func RecordLatency

func RecordLatency(labelValues map[string]string, latency float64)

RecordLatency record an operation latency

func RecordStartTime

func RecordStartTime(labelValues map[string]string, start time.Time)

RecordStartTime record mesher start time

func RecordStatus

func RecordStatus(labelValues map[string]string, statusCode int)

RecordStatus record an operation status

Types

type Options

type Options struct {
	LabelNames []string //default label names, if RecordOptions LabelNames is nil
}

Options define recorder options

type PromRecorder added in v1.7.0

type PromRecorder struct {
	LabelNames []string
}

PromRecorder record metrics

func NewPromRecorder

func NewPromRecorder(opts *Options) (*PromRecorder, error)

NewPromRecorder return a prom recorder

func (*PromRecorder) RecordLatency added in v1.7.0

func (e *PromRecorder) RecordLatency(LabelValues map[string]string, latency float64)

RecordLatency record operation latency

func (*PromRecorder) RecordStartTime added in v1.7.0

func (e *PromRecorder) RecordStartTime(LabelValues map[string]string, start time.Time)

RecordStartTime save start time

func (*PromRecorder) RecordStatus added in v1.7.0

func (e *PromRecorder) RecordStatus(LabelValues map[string]string, statusCode int)

RecordStatus record different metrics based on status

type PrometheusExporter

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

PrometheusExporter struct has attributes for prometheus data

func GetPrometheusExporter

func GetPrometheusExporter() *PrometheusExporter

GetPrometheusExporter returns default prometheus exporter

func (*PrometheusExporter) Count

func (s *PrometheusExporter) Count(name string, labelNames []string, labels prometheus.Labels)

Count function returns count

func (*PrometheusExporter) Gauge

func (s *PrometheusExporter) Gauge(name string, val float64, labelNames []string, labels prometheus.Labels)

Gauge function

func (*PrometheusExporter) Summary

func (s *PrometheusExporter) Summary(name string, val float64, labelNames []string, labels prometheus.Labels)

Summary function

type PrometheusMesherSinker

type PrometheusMesherSinker struct {
	PromRegistry prometheus.Registerer //Prometheus registry
}

PrometheusMesherSinker is the struct for prometheus configuration parameters

var (
	//DefaultPrometheusExporter stores value of default prometheus exporter type
	DefaultPrometheusExporter = GetPrometheusExporter()
	//DefaultPrometheusSinker stores value of default prometheus exporter type
	DefaultPrometheusSinker *PrometheusMesherSinker
)

Jump to

Keyboard shortcuts

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