Documentation ¶
Overview ¶
Package rkmidmetrics has couple of utility functions to start prometheus and pushgateway client locally.
package rkmidmetrics provide options
Index ¶
- Constants
- Variables
- func ClearAllMetrics()
- type AfterCtx
- type BeforeCtx
- type BootConfig
- type MetricsSet
- func (set *MetricsSet) GetCounter(name string) *prometheus.CounterVec
- func (set *MetricsSet) GetCounterWithLabels(name string, labels prometheus.Labels) prometheus.Counter
- func (set *MetricsSet) GetCounterWithValues(name string, values ...string) prometheus.Counter
- func (set *MetricsSet) GetGauge(name string) *prometheus.GaugeVec
- func (set *MetricsSet) GetGaugeWithLabels(name string, labels prometheus.Labels) prometheus.Gauge
- func (set *MetricsSet) GetGaugeWithValues(name string, values ...string) prometheus.Gauge
- func (set *MetricsSet) GetHistogram(name string) *prometheus.HistogramVec
- func (set *MetricsSet) GetHistogramWithLabels(name string, labels prometheus.Labels) prometheus.Observer
- func (set *MetricsSet) GetHistogramWithValues(name string, values ...string) prometheus.Observer
- func (set *MetricsSet) GetNamespace() string
- func (set *MetricsSet) GetRegisterer() prometheus.Registerer
- func (set *MetricsSet) GetSubSystem() string
- func (set *MetricsSet) GetSummary(name string) *prometheus.SummaryVec
- func (set *MetricsSet) GetSummaryWithLabels(name string, labels prometheus.Labels) prometheus.Observer
- func (set *MetricsSet) GetSummaryWithValues(name string, values ...string) prometheus.Observer
- func (set *MetricsSet) ListCounters() []*prometheus.CounterVec
- func (set *MetricsSet) ListGauges() []*prometheus.GaugeVec
- func (set *MetricsSet) ListHistograms() []*prometheus.HistogramVec
- func (set *MetricsSet) ListSummaries() []*prometheus.SummaryVec
- func (set *MetricsSet) RegisterCounter(name string, labelKeys ...string) error
- func (set *MetricsSet) RegisterGauge(name string, labelKeys ...string) error
- func (set *MetricsSet) RegisterHistogram(name string, bucket []float64, labelKeys ...string) error
- func (set *MetricsSet) RegisterSummary(name string, objectives map[float64]float64, labelKeys ...string) error
- func (set *MetricsSet) UnRegisterCounter(name string)
- func (set *MetricsSet) UnRegisterGauge(name string)
- func (set *MetricsSet) UnRegisterHistogram(name string)
- func (set *MetricsSet) UnRegisterSummary(name string)
- type Option
- func ToOptions(config *BootConfig, entryName, entryType string, reg *prometheus.Registry, ...) []Option
- func WithEntryNameAndType(entryName, entryType string) Option
- func WithIgnorePrefix(paths ...string) Option
- func WithLabelerType(l string) Option
- func WithMockOptionSet(mock OptionSetInterface) Option
- func WithRegisterer(registerer prometheus.Registerer) Option
- type OptionSetInterface
Constants ¶
const ( // LabelerTypeHttp type of labeler LabelerTypeHttp = "http" // LabelerTypeGrpc type of labeler LabelerTypeGrpc = "grpc" )
const ( // MetricsNameElapsedNano records RPC duration MetricsNameElapsedNano = "elapsedNano" // MetricsNameResCode records response code MetricsNameResCode = "resCode" )
Variables ¶
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 ¶
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"` IgnorePrefix []string `yaml:"ignorePrefix" json:"ignorePrefix"` }
BootConfig for YAML
type MetricsSet ¶ added in v1.0.9
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 ¶ added in v1.0.9
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 ¶ added in v1.0.9
func (set *MetricsSet) GetCounter(name string) *prometheus.CounterVec
GetCounter is thread safe
func (*MetricsSet) GetCounterWithLabels ¶ added in v1.0.9
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 ¶ added in v1.0.9
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 ¶ added in v1.0.9
func (set *MetricsSet) GetGauge(name string) *prometheus.GaugeVec
GetGauge is thread safe
func (*MetricsSet) GetGaugeWithLabels ¶ added in v1.0.9
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 ¶ added in v1.0.9
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 ¶ added in v1.0.9
func (set *MetricsSet) GetHistogram(name string) *prometheus.HistogramVec
GetHistogram is thread safe
func (*MetricsSet) GetHistogramWithLabels ¶ added in v1.0.9
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 ¶ added in v1.0.9
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 ¶ added in v1.0.9
func (set *MetricsSet) GetNamespace() string
GetNamespace returns namespace
func (*MetricsSet) GetRegisterer ¶ added in v1.0.9
func (set *MetricsSet) GetRegisterer() prometheus.Registerer
GetRegisterer returns registerer
func (*MetricsSet) GetSubSystem ¶ added in v1.0.9
func (set *MetricsSet) GetSubSystem() string
GetSubSystem returns subsystem
func (*MetricsSet) GetSummary ¶ added in v1.0.9
func (set *MetricsSet) GetSummary(name string) *prometheus.SummaryVec
GetSummary is thread safe
func (*MetricsSet) GetSummaryWithLabels ¶ added in v1.0.9
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 ¶ added in v1.0.9
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 ¶ added in v1.0.9
func (set *MetricsSet) ListCounters() []*prometheus.CounterVec
ListCounters is thread safe
func (*MetricsSet) ListGauges ¶ added in v1.0.9
func (set *MetricsSet) ListGauges() []*prometheus.GaugeVec
ListGauges is thread safe
func (*MetricsSet) ListHistograms ¶ added in v1.0.9
func (set *MetricsSet) ListHistograms() []*prometheus.HistogramVec
ListHistograms is thread safe
func (*MetricsSet) ListSummaries ¶ added in v1.0.9
func (set *MetricsSet) ListSummaries() []*prometheus.SummaryVec
ListSummaries is thread safe
func (*MetricsSet) RegisterCounter ¶ added in v1.0.9
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 ¶ added in v1.0.9
func (set *MetricsSet) RegisterGauge(name string, labelKeys ...string) error
RegisterGauge thread safe Register a gauge with namespace and subsystem in MetricsSet
func (*MetricsSet) RegisterHistogram ¶ added in v1.0.9
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 ¶ added in v1.0.9
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 ¶ added in v1.0.9
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 ¶ added in v1.0.9
func (set *MetricsSet) UnRegisterGauge(name string)
UnRegisterGauge thread safe Unregister metrics, error would be thrown only when invalid name was provided
func (*MetricsSet) UnRegisterHistogram ¶ added in v1.0.9
func (set *MetricsSet) UnRegisterHistogram(name string)
UnRegisterHistogram thread safe Unregister metrics, error would be thrown only when invalid name was provided
func (*MetricsSet) UnRegisterSummary ¶ added in v1.0.9
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 ¶
WithEntryNameAndType provide entry name and entry type.
func WithIgnorePrefix ¶
WithIgnorePrefix provide paths prefix that will ignore. Mainly used for swagger main page and RK TV entry.
func WithLabelerType ¶
WithLabelerType provide Labeler which will init metrics based on that
func WithMockOptionSet ¶
func WithMockOptionSet(mock OptionSetInterface) Option
WithMockOptionSet provide mock OptionSetInterface
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) }
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