kmetrics

package
v0.0.0-...-4695a13 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OpsLatencyMetric    = CreateKmetric(context.Background(), "op_latency_ms", "desc", []string{"method", "status", "error", "notes"})
	OpsLatencyHistogram = CreateKhistogram(context.Background(), "op_lat_ms", "desc", []string{"method", "status", "error"}, []int64{1, 2, 3, 6, 10, 20, 30, 60, 100, 200, 300, 600, 1000, 2000, 3000, 6000, 10000, 20000, 30000}) // note: metrics name cannot conflict, that's why we name this `op_lat_ms`
)

Functions

func AddInt64DerivedGaugeWithLabels

func AddInt64DerivedGaugeWithLabels(ctx context.Context, r *metric.Registry, fn func() int64, gaugeName string, description string, labels map[string]string)

func InstrumentHistogramRunVoid

func InstrumentHistogramRunVoid(ctx context.Context, method string, ef FuncTypeVoid)

Histogram is very expensive. You should use InstrumentSummaryRunVoid() instead most of the time. Only use InstrumentHistogramRunVoid() for important metrics.

func InstrumentSummaryRunVoid

func InstrumentSummaryRunVoid(ctx context.Context, method string, ef FuncTypeVoid, customNotes string)

InstrumentSummaryRunVoid: helper function for adding metrics coverage for a function that returns void.

Types

type FuncTypeError

type FuncTypeError func(ctx context.Context) error

FuncTypeError is a function being decorated. When an error happens, this func should return an error.

type FuncTypeVoid

type FuncTypeVoid func()

FuncTypeVoid is a function being decorated. When an error happens, this func should throw (panic), that's why this func doesn't return an error.

type GaugeGroup

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

GaugeGroup is a group of gauges that share the same gauge name but come with different tags.

func NewGaugeGroup

func NewGaugeGroup(name, desc string, tagNames ...string) *GaugeGroup

func (*GaugeGroup) Read

func (gg *GaugeGroup) Read() *metricdata.Metric

func (*GaugeGroup) UpdateValue

func (gg *GaugeGroup) UpdateValue(dict map[string]*GaugeTimeSequence)

GaugeGroup is designed for scenarios like "top 10 worker's current load". So when updating value, we never update individual values, instead, we always update all time sequences at the same time.

type GaugeTimeSequence

type GaugeTimeSequence struct {
	Key string

	Value int64
	// contains filtered or unexported fields
}

GaugeTimeSequence is one time sequence (one specific tag value).

func NewGaugeTimeSequence

func NewGaugeTimeSequence(parent *GaugeGroup, value int64, tags ...string) *GaugeTimeSequence

func (*GaugeTimeSequence) Read

type HistoBucket

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

********************** HistoBucket ***********************

func CreateHistoBucket

func CreateHistoBucket(ctx context.Context, parent *HistoSequence, bucketName string) *HistoBucket

type HistoSequence

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

func CreateHistoSequence

func CreateHistoSequence(ctx context.Context, key string, parent *Khistogram, tagValues []string) *HistoSequence

func (*HistoSequence) Add

func (ts *HistoSequence) Add(val int64)

func (*HistoSequence) ReadCount

func (ts *HistoSequence) ReadCount() *metricdata.TimeSeries

func (*HistoSequence) ReadData

func (ts *HistoSequence) ReadData() []*metricdata.TimeSeries

func (*HistoSequence) ReadSum

func (ts *HistoSequence) ReadSum() *metricdata.TimeSeries

type HistoSequenceCollection

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

HistoSequenceCollection is immutable, so every time we need to add new HistoSequence, we need to create a new one and atomic.StorePointer

func CreateHistoSequenceCollection

func CreateHistoSequenceCollection(parent *Khistogram) *HistoSequenceCollection

type Khistogram

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

func CreateKhistogram

func CreateKhistogram(ctx context.Context, name string, description string, tags []string, buckets []int64) *Khistogram

example buckets: []int64{1,3,10,100,1000,10000,60000} example buckets: []int64{2,10,50,200,1000,5000,20000} example buckets: []int64{1,3,10,30,100,300,1000,3000,10000,30000} example buckets: []int64{1,2,3,6,10,20,30,60,100,200,300,600,1000,2000,3000,6000,10000,20000,30000}

func (*Khistogram) GetHistoSequence

func (m *Khistogram) GetHistoSequence(ctx context.Context, tags ...string) *HistoSequence

The tags list has to be the same len as the tagNames in Kmetric, same order as well.

func (*Khistogram) Read

func (ts *Khistogram) Read() []*metricdata.Metric

func (*Khistogram) ReadBucket

func (m *Khistogram) ReadBucket() *metricdata.Metric

func (*Khistogram) ReadCount

func (m *Khistogram) ReadCount() *metricdata.Metric

func (*Khistogram) ReadSum

func (m *Khistogram) ReadSum() *metricdata.Metric

type Kmetric

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

Kmetric means 1 metric For 1 Kmetric, it may produce multiple metric name, such as "shardmgr_log_size_sum" and "shardmgr_log_size_count". For each metrics name, it often contains multiple time-sequence (tags), such as event="EtcdLockNotFound", event="CreatingLease", etc.

func CreateKmetric

func CreateKmetric(ctx context.Context, name string, description string, tags []string) *Kmetric

func (*Kmetric) CountOnly

func (km *Kmetric) CountOnly() *Kmetric

func (*Kmetric) GetTimeSequence

func (m *Kmetric) GetTimeSequence(ctx context.Context, tags ...string) *TimeSequence

The tags list has to be the same len as the tagNames in Kmetric, same order as well.

func (*Kmetric) ReadCount

func (m *Kmetric) ReadCount() *metricdata.Metric

func (*Kmetric) ReadSum

func (m *Kmetric) ReadSum() *metricdata.Metric

type KmetricsCollection

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

KmetricsCollection is immutable; a new collection is created for new Kmetrics.

func CreateKmetricsCollection

func CreateKmetricsCollection() *KmetricsCollection

CreateKmetricsCollection initializes a new KmetricsCollection.

func (*KmetricsCollection) Clone

func (collection *KmetricsCollection) Clone() *KmetricsCollection

Clone creates a copy of the KmetricsCollection.

type KmetricsRegistry

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

KmetricsRegistry implements the metricproducer.Producer interface.

func GetKmetricsRegistry

func GetKmetricsRegistry() *KmetricsRegistry

GetKmetricsRegistry returns the singleton instance of KmetricsRegistry.

func NewKmetricsRegistry

func NewKmetricsRegistry() *KmetricsRegistry

NewKmetricsRegistry initializes a new KmetricsRegistry.

func (*KmetricsRegistry) AddGlobalTag

func (registry *KmetricsRegistry) AddGlobalTag(key, value string)

AddGlobalTag adds a global tag for all metrics.

func (*KmetricsRegistry) Read

func (registry *KmetricsRegistry) Read() []*metricdata.Metric

Read returns all registered metrics.

func (*KmetricsRegistry) RegisterGaugeGroup

func (registry *KmetricsRegistry) RegisterGaugeGroup(gg *GaugeGroup)

RegisterGaugeGroup registers a new GaugeGroup.

func (*KmetricsRegistry) RegisterHistogram

func (registry *KmetricsRegistry) RegisterHistogram(nh *Khistogram)

RegisterHistogram registers a new Khistogram.

func (*KmetricsRegistry) RegisterKmetric

func (registry *KmetricsRegistry) RegisterKmetric(km *Kmetric)

RegisterMetric registers a new Kmetric.

type TimeSequence

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

1 TimeSequence = 1 unique tag value combination 1 Kmetric may contain N TimeSequences

func CreateTimeSequence

func CreateTimeSequence(ctx context.Context, key string, parent *Kmetric, tagValues []string) *TimeSequence

func (*TimeSequence) Add

func (ts *TimeSequence) Add(val int64)

func (*TimeSequence) Get

func (ts *TimeSequence) Get() (count int64, sum int64)

func (*TimeSequence) ReadCount

func (ts *TimeSequence) ReadCount() *metricdata.TimeSeries

func (*TimeSequence) ReadSum

func (ts *TimeSequence) ReadSum() *metricdata.TimeSeries

func (*TimeSequence) Touch

func (ts *TimeSequence) Touch()

Touch() creates this time sequence, mostly for counter metrics. For example: you need to monitor how many times event A happens, but event A happens rarely, so you probably need a way to create this TimeSequence as 0 (before event A actually happens).

type TimeSequenceCollection

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

TimeSequenceCollection is immutable, so every time we need to add a new TimeSequence, we need to create a new one and atomic.StorePointer

func CreateTimeSequenceCollection

func CreateTimeSequenceCollection(parent *Kmetric) *TimeSequenceCollection

Jump to

Keyboard shortcuts

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