rkmidprom

package
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package rkmidprom has a couple of utility functions to start prometheus and pushgateway client locally.

Package rkmidprom provide options

Index

Constants

View Source
const (
	// LabelerTypeHttp type of labeler
	LabelerTypeHttp = "http"
	// LabelerTypeGrpc type of labeler
	LabelerTypeGrpc = "grpc"
)
View Source
const (
	// MetricsNameElapsedNano records RPC duration
	MetricsNameElapsedNano = "elapsedNano"
	// MetricsNameResCode records response code
	MetricsNameResCode = "resCode"
)

Variables

View Source
var SummaryObjectives = map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001, 0.999: 0.0001}

SummaryObjectives will track quantile of P50, P90, P99, P9999 by default.

Functions

func ClearAllMetrics

func ClearAllMetrics()

Internal use only.

Types

type AfterCtx

type AfterCtx struct {
	Input struct {
		ResCode string
	}
	Output struct{}
}

AfterCtx context for After() function

func NewAfterCtx

func NewAfterCtx() *AfterCtx

NewAfterCtx create new AfterCtx with fields initialized

type BeforeCtx

type BeforeCtx struct {
	Input struct {
		RestMethod  string
		RestPath    string
		GrpcType    string
		GrpcMethod  string
		GrpcService string
	}
	Output struct {
		StartTime time.Time
	}
}

BeforeCtx context for Before() function

func NewBeforeCtx

func NewBeforeCtx() *BeforeCtx

NewBeforeCtx create new BeforeCtx with fields initialized

type BootConfig

type BootConfig struct {
	Enabled bool     `yaml:"enabled" json:"enabled"`
	Ignore  []string `yaml:"ignore" json:"ignore"`
}

BootConfig for YAML

type MetricsSet

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

MetricsSet is a collections of counter, gauge, summary, histogram and link to certain registerer. User need to provide own prometheus.Registerer.

1: namespace: the namespace of prometheus metrics 2: sysSystem: the subSystem of prometheus metrics 3: keys: a map stores all keys 4: counters: map of counters 5: gauges: map of gauges 6: summaries: map of summaries 7: histograms: map of histograms 8: lock: lock for thread safety 9: registerer prometheus.Registerer

func GetServerMetricsSet

func GetServerMetricsSet(entryName string) *MetricsSet

GetServerMetricsSet server metrics set.

func NewMetricsSet

func NewMetricsSet(namespace, subSystem string, registerer prometheus.Registerer) *MetricsSet

NewMetricsSet creates metrics set with namespace, subSystem and registerer.

If no registerer was provided, then prometheus.DefaultRegisterer would be used.

Important! namespace, subSystem, labels should match prometheus regex as bellow ^[a-zA-Z_:][a-zA-Z0-9_:]*$ If provided name is not valid, then default ones would be assigned

func (*MetricsSet) GetCounter

func (set *MetricsSet) GetCounter(name string) *prometheus.CounterVec

GetCounter is thread safe

func (*MetricsSet) GetCounterWithLabels

func (set *MetricsSet) GetCounterWithLabels(name string, labels prometheus.Labels) prometheus.Counter

GetCounterWithLabels is thread safe

Get counter with values matched with labels Users should always be sure about the number of labels.

func (*MetricsSet) GetCounterWithValues

func (set *MetricsSet) GetCounterWithValues(name string, values ...string) prometheus.Counter

GetCounterWithValues is thread safe

Get counter with values matched with labels Users should always be sure about the number of labels.

func (*MetricsSet) GetGauge

func (set *MetricsSet) GetGauge(name string) *prometheus.GaugeVec

GetGauge is thread safe

func (*MetricsSet) GetGaugeWithLabels

func (set *MetricsSet) GetGaugeWithLabels(name string, labels prometheus.Labels) prometheus.Gauge

GetGaugeWithLabels is thread safe Get gauge with values matched with labels Users should always be sure about the number of labels.

func (*MetricsSet) GetGaugeWithValues

func (set *MetricsSet) GetGaugeWithValues(name string, values ...string) prometheus.Gauge

GetGaugeWithValues is thread safe

Get gauge with values matched with labels Users should always be sure about the number of labels.

func (*MetricsSet) GetHistogram

func (set *MetricsSet) GetHistogram(name string) *prometheus.HistogramVec

GetHistogram is thread safe

func (*MetricsSet) GetHistogramWithLabels

func (set *MetricsSet) GetHistogramWithLabels(name string, labels prometheus.Labels) prometheus.Observer

GetHistogramWithLabels is thread safe

Get histogram with values matched with labels Users should always be sure about the number of labels.

func (*MetricsSet) GetHistogramWithValues

func (set *MetricsSet) GetHistogramWithValues(name string, values ...string) prometheus.Observer

GetHistogramWithValues is thread safe

Get histogram with values matched with labels Users should always be sure about the number of labels.

func (*MetricsSet) GetNamespace

func (set *MetricsSet) GetNamespace() string

GetNamespace returns namespace

func (*MetricsSet) GetRegisterer

func (set *MetricsSet) GetRegisterer() prometheus.Registerer

GetRegisterer returns registerer

func (*MetricsSet) GetSubSystem

func (set *MetricsSet) GetSubSystem() string

GetSubSystem returns subsystem

func (*MetricsSet) GetSummary

func (set *MetricsSet) GetSummary(name string) *prometheus.SummaryVec

GetSummary is thread safe

func (*MetricsSet) GetSummaryWithLabels

func (set *MetricsSet) GetSummaryWithLabels(name string, labels prometheus.Labels) prometheus.Observer

GetSummaryWithLabels is thread safe

Get summary with values matched with labels Users should always be sure about the number of labels.

func (*MetricsSet) GetSummaryWithValues

func (set *MetricsSet) GetSummaryWithValues(name string, values ...string) prometheus.Observer

GetSummaryWithValues is thread safe

Get summary with values matched with labels Users should always be sure about the number of labels.

func (*MetricsSet) ListCounters

func (set *MetricsSet) ListCounters() []*prometheus.CounterVec

ListCounters is thread safe

func (*MetricsSet) ListGauges

func (set *MetricsSet) ListGauges() []*prometheus.GaugeVec

ListGauges is thread safe

func (*MetricsSet) ListHistograms

func (set *MetricsSet) ListHistograms() []*prometheus.HistogramVec

ListHistograms is thread safe

func (*MetricsSet) ListSummaries

func (set *MetricsSet) ListSummaries() []*prometheus.SummaryVec

ListSummaries is thread safe

func (*MetricsSet) RegisterCounter

func (set *MetricsSet) RegisterCounter(name string, labelKeys ...string) error

RegisterCounter is thread safe Register a counter with namespace and subsystem in MetricsSet

func (*MetricsSet) RegisterGauge

func (set *MetricsSet) RegisterGauge(name string, labelKeys ...string) error

RegisterGauge thread safe Register a gauge with namespace and subsystem in MetricsSet

func (*MetricsSet) RegisterHistogram

func (set *MetricsSet) RegisterHistogram(name string, bucket []float64, labelKeys ...string) error

RegisterHistogram thread safe Register a histogram with namespace, subsystem and objectives in MetricsSet If bucket is nil, then empty bucket would be applied

func (*MetricsSet) RegisterSummary

func (set *MetricsSet) RegisterSummary(name string, objectives map[float64]float64, labelKeys ...string) error

RegisterSummary thread safe Register a summary with namespace, subsystem and objectives in MetricsSet If objectives is nil, then default SummaryObjectives would be applied

func (*MetricsSet) UnRegisterCounter

func (set *MetricsSet) UnRegisterCounter(name string)

UnRegisterCounter is thread safe Unregister metrics, error would be thrown only when invalid name was provided

func (*MetricsSet) UnRegisterGauge

func (set *MetricsSet) UnRegisterGauge(name string)

UnRegisterGauge thread safe Unregister metrics, error would be thrown only when invalid name was provided

func (*MetricsSet) UnRegisterHistogram

func (set *MetricsSet) UnRegisterHistogram(name string)

UnRegisterHistogram thread safe Unregister metrics, error would be thrown only when invalid name was provided

func (*MetricsSet) UnRegisterSummary

func (set *MetricsSet) UnRegisterSummary(name string)

UnRegisterSummary thread safe Unregister metrics, error would be thrown only when invalid name was provided

type Option

type Option func(*optionSet)

Option options provided to Interceptor or optionsSet while creating

func ToOptions

func ToOptions(config *BootConfig,
	entryName, entryType string,
	reg *prometheus.Registry, labelerType string) []Option

ToOptions convert BootConfig into Option list

func WithEntryNameAndType

func WithEntryNameAndType(entryName, entryType string) Option

WithEntryNameAndType provide entry name and entry type.

func WithLabelerType

func WithLabelerType(l string) Option

WithLabelerType provide Labeler which will init metrics based on that

func WithMockOptionSet

func WithMockOptionSet(mock OptionSetInterface) Option

WithMockOptionSet provide mock OptionSetInterface

func WithPathToIgnore

func WithPathToIgnore(paths ...string) Option

WithPathToIgnore provide paths prefix that will ignore.

func WithRegisterer

func WithRegisterer(registerer prometheus.Registerer) Option

WithRegisterer provide prometheus.Registerer.

type OptionSetInterface

type OptionSetInterface interface {
	GetEntryName() string

	GetEntryType() string

	BeforeCtx(*http.Request) *BeforeCtx

	Before(*BeforeCtx)

	AfterCtx(string) *AfterCtx

	After(before *BeforeCtx, after *AfterCtx)

	ShouldIgnore(string) bool
}

OptionSetInterface mainly for testing purpose

func NewOptionSet

func NewOptionSet(opts ...Option) OptionSetInterface

NewOptionSet Create new optionSet with options.

func NewOptionSetMock

func NewOptionSetMock(before *BeforeCtx, after *AfterCtx) OptionSetInterface

NewOptionSetMock for testing purpose

Jump to

Keyboard shortcuts

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