metrics

package
v3.1.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 License: Apache-2.0 Imports: 6 Imported by: 4

Documentation

Overview

Package metrics define interfaces for metrics collection.

Index

Constants

View Source
const (
	DefaultCompression       = 100
	DefaultBucketNum         = 10
	DefaultTimeWindowSeconds = 120
)
View Source
const (
	ReportModePull = "pull"
	ReportModePush = "push"
)
View Source
const DefMaxAge = 600000000000

Variables

This section is empty.

Functions

func AddCollector added in v3.1.1

func AddCollector(name string, fun CollectorFunc)

AddCollector add more indicators, like metadata, sla, config-center etc.

func Init added in v3.1.1

func Init(url *common.URL)

Init Metrics module

func InitAppInfo added in v3.1.1

func InitAppInfo(appName string, appVersion string)

cannot import rootConfig,may cause cycle import,so be it

func Publish added in v3.1.1

func Publish(event MetricsEvent)

Publish publishes an event to all subscribers of the same type.

func SetRegistry added in v3.1.1

func SetRegistry(name string, v func(*common.URL) MetricRegistry)

SetRegistry extend more MetricRegistry, default PrometheusRegistry

func Subscribe added in v3.1.1

func Subscribe(typ string, ch chan MetricsEvent)

Subscribe subscribes to events of the given type.

func Unsubscribe added in v3.1.1

func Unsubscribe(typ string)

Unsubscribe unsubscribes from events of the given type.

Types

type AggregateCounterVec added in v3.1.1

type AggregateCounterVec interface {
	Inc(labels map[string]string)
}

AggregateCounterVec means a set of aggregate counter metrics with the same metricKey but different labels.

func NewAggregateCounterVec added in v3.1.1

func NewAggregateCounterVec(metricRegistry MetricRegistry, metricKey *MetricKey) AggregateCounterVec

type ApplicationMetricLevel added in v3.1.1

type ApplicationMetricLevel struct {
	ApplicationName string
	Version         string
	GitCommitId     string
	Ip              string
	HostName        string
}

func GetApplicationLevel added in v3.1.1

func GetApplicationLevel() *ApplicationMetricLevel

func (*ApplicationMetricLevel) Tags added in v3.1.1

func (m *ApplicationMetricLevel) Tags() map[string]string

type BaseCollector added in v3.1.1

type BaseCollector struct {
	R MetricRegistry
}

func (*BaseCollector) StateCount added in v3.1.1

func (c *BaseCollector) StateCount(total, succ, fail *MetricKey, level MetricLevel, succed bool)

type CollectorFunc added in v3.1.1

type CollectorFunc func(MetricRegistry, *common.URL)

CollectorFunc used to extend more indicators

type ConfigCenterLevel added in v3.1.1

type ConfigCenterLevel struct {
	ApplicationName string
	Ip              string
	HostName        string
	Key             string
	Group           string
	ConfigCenter    string
	ChangeType      string
}

func NewConfigCenterLevel added in v3.1.1

func NewConfigCenterLevel(key string, group string, configCenter string, changeType string) *ConfigCenterLevel

func (ConfigCenterLevel) Tags added in v3.1.1

func (l ConfigCenterLevel) Tags() map[string]string

type CounterMetric added in v3.1.1

type CounterMetric interface {
	Inc()
	Add(float64)
}

CounterMetric counter metric

type CounterVec added in v3.1.1

type CounterVec interface {
	Inc(labels map[string]string)
	Add(labels map[string]string, v float64)
}

CounterVec means a set of counters with the same metricKey but different labels

func NewCounterVec added in v3.1.1

func NewCounterVec(metricRegistry MetricRegistry, metricKey *MetricKey) CounterVec

NewCounterVec create a CounterVec default implementation.

type DefaultAggregateCounterVec added in v3.1.1

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

DefaultAggregateCounterVec is a default AggregateCounterVec implementation.

It is concurrent safe, and it uses the aggregate.TimeWindowCounter to store and calculate the aggregate counter metrics.

func (*DefaultAggregateCounterVec) Inc added in v3.1.1

func (d *DefaultAggregateCounterVec) Inc(labels map[string]string)

type DefaultCounterVec added in v3.1.1

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

DefaultCounterVec is a default CounterVec implementation.

func (*DefaultCounterVec) Add added in v3.1.1

func (d *DefaultCounterVec) Add(labels map[string]string, v float64)

func (*DefaultCounterVec) Inc added in v3.1.1

func (d *DefaultCounterVec) Inc(labels map[string]string)

type DefaultGaugeVec added in v3.1.1

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

DefaultGaugeVec is a default GaugeVec implementation.

func (*DefaultGaugeVec) Add added in v3.1.1

func (d *DefaultGaugeVec) Add(labels map[string]string, v float64)

func (*DefaultGaugeVec) Dec added in v3.1.1

func (d *DefaultGaugeVec) Dec(labels map[string]string)

func (*DefaultGaugeVec) Inc added in v3.1.1

func (d *DefaultGaugeVec) Inc(labels map[string]string)

func (*DefaultGaugeVec) Set added in v3.1.1

func (d *DefaultGaugeVec) Set(labels map[string]string, v float64)

func (*DefaultGaugeVec) Sub added in v3.1.1

func (d *DefaultGaugeVec) Sub(labels map[string]string, v float64)

type DefaultQpsMetricVec added in v3.1.1

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

DefaultQpsMetricVec is a default QpsMetricVec implementation.

It is concurrent safe, and it uses the aggregate.TimeWindowCounter to store and calculate the qps metrics.

func (*DefaultQpsMetricVec) Record added in v3.1.1

func (d *DefaultQpsMetricVec) Record(labels map[string]string)

type DefaultQuantileMetricVec added in v3.1.1

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

DefaultQuantileMetricVec is a default QuantileMetricVec implementation.

It is concurrent safe, and it uses the aggregate.TimeWindowQuantile to store and calculate the quantile metrics.

func (*DefaultQuantileMetricVec) Record added in v3.1.1

func (d *DefaultQuantileMetricVec) Record(labels map[string]string, v float64)

type DefaultRtVec added in v3.1.1

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

DefaultRtVec is a default RtVec implementation.

If rtOpts.Aggregate is true, it will use the aggregate.TimeWindowAggregator with local aggregation, else it will use the aggregate.Result without aggregation.

func (*DefaultRtVec) Record added in v3.1.1

func (d *DefaultRtVec) Record(labels map[string]string, v float64)

type GaugeMetric added in v3.1.1

type GaugeMetric interface {
	Set(float64)
	Inc()
	Dec()
	Add(float64)
	Sub(float64)
}

GaugeMetric gauge metric

type GaugeVec added in v3.1.1

type GaugeVec interface {
	Set(labels map[string]string, v float64)
	Inc(labels map[string]string)
	Dec(labels map[string]string)
	Add(labels map[string]string, v float64)
	Sub(labels map[string]string, v float64)
}

GaugeVec means a set of gauges with the same metricKey but different labels

func NewGaugeVec added in v3.1.1

func NewGaugeVec(metricRegistry MetricRegistry, metricKey *MetricKey) GaugeVec

NewGaugeVec create a GaugeVec default implementation.

type MethodMetricLevel added in v3.1.1

type MethodMetricLevel struct {
	*ServiceMetricLevel
	Method  string
	Group   string
	Version string
}

func (MethodMetricLevel) Tags added in v3.1.1

func (m MethodMetricLevel) Tags() map[string]string

type MetricId added in v3.1.1

type MetricId struct {
	Name string
	Desc string
	Tags map[string]string // also named label
	Type Type              // TODO check if this field is useful
}

MetricId # HELP dubbo_metadata_store_provider_succeed_total Succeed Store Provider Metadata # TYPE dubbo_metadata_store_provider_succeed_total gauge dubbo_metadata_store_provider_succeed_total{application_name="provider",hostname="localhost",interface="org.example.DemoService",ip="10.252.156.213",} 1.0 other properties except value

func NewMetricId added in v3.1.1

func NewMetricId(key *MetricKey, level MetricLevel) *MetricId

func NewMetricIdByLabels added in v3.1.1

func NewMetricIdByLabels(key *MetricKey, labels map[string]string) *MetricId

NewMetricIdByLabels create a MetricId by key and labels

func (*MetricId) TagKeys added in v3.1.1

func (m *MetricId) TagKeys() []string

type MetricKey added in v3.1.1

type MetricKey struct {
	Name string
	Desc string
}

func NewMetricKey added in v3.1.1

func NewMetricKey(name string, desc string) *MetricKey

type MetricLevel added in v3.1.1

type MetricLevel interface {
	Tags() map[string]string
}

type MetricRegistry added in v3.1.1

type MetricRegistry interface {
	Counter(*MetricId) CounterMetric        // add or update a counter
	Gauge(*MetricId) GaugeMetric            // add or update a gauge
	Histogram(*MetricId) ObservableMetric   // add a metric num to a histogram
	Summary(*MetricId) ObservableMetric     // add a metric num to a summary
	Rt(*MetricId, *RtOpts) ObservableMetric // add a metric num to a rt
	Export()                                // expose metric data, such as Prometheus http exporter

}

MetricRegistry data container,data compute、expose、agg

type MetricSample added in v3.1.1

type MetricSample struct {
	*MetricId
	// contains filtered or unexported fields
}

MetricSample a metric sample,This is the final data presentation, not an intermediate result(like summary,histogram they will export to a set of MetricSample)

type MetricsEvent added in v3.1.1

type MetricsEvent interface {
	Type() string
}

MetricsEvent represents an event that can be published and subscribed to.

type ObservableMetric added in v3.1.1

type ObservableMetric interface {
	Observe(float64)
}

histogram summary rt metric

type QpsMetricVec added in v3.1.1

type QpsMetricVec interface {
	Record(labels map[string]string)
}

QpsMetricVec means a set of qps metrics with the same metricKey but different labels.

func NewQpsMetricVec added in v3.1.1

func NewQpsMetricVec(metricRegistry MetricRegistry, metricKey *MetricKey) QpsMetricVec

type QuantileMetricVec added in v3.1.1

type QuantileMetricVec interface {
	Record(labels map[string]string, v float64)
}

QuantileMetricVec means a set of quantile metrics with the same metricKey but different labels.

func NewQuantileMetricVec added in v3.1.1

func NewQuantileMetricVec(metricRegistry MetricRegistry, metricKeys []*MetricKey, quantiles []float64) QuantileMetricVec

type ReportMode

type ReportMode string

type Reporter

type Reporter interface {
	StartServer(config *ReporterConfig)
	ShutdownServer()
}

Reporter is an interface used to represent the backend of metrics to be exported

type ReporterConfig

type ReporterConfig struct {
	Enable             bool
	Namespace          string
	Mode               ReportMode
	Port               string
	Path               string
	PushGatewayAddress string
	SummaryMaxAge      int64
	Protocol           string // exporters, like prometheus
}

func NewReporterConfig

func NewReporterConfig() *ReporterConfig

type RtOpts added in v3.1.1

type RtOpts struct {
	Aggregate         bool
	BucketNum         int   // only for aggRt
	TimeWindowSeconds int64 // only for aggRt
}

type RtVec added in v3.1.1

type RtVec interface {
	Record(labels map[string]string, v float64)
}

RtVec means a set of rt metrics with the same metricKey but different labels

func NewRtVec added in v3.1.1

func NewRtVec(metricRegistry MetricRegistry, metricKey *MetricKey, rtOpts *RtOpts) RtVec

NewRtVec create a RtVec default implementation DefaultRtVec.

type ServiceMetricLevel added in v3.1.1

type ServiceMetricLevel struct {
	*ApplicationMetricLevel
	Interface string
}

func NewServiceMetric added in v3.1.1

func NewServiceMetric(interfaceName string) *ServiceMetricLevel

func (ServiceMetricLevel) Tags added in v3.1.1

func (m ServiceMetricLevel) Tags() map[string]string

type Type added in v3.1.1

type Type uint8 // TODO check if Type is is useful

Type metric type, same with micrometer

const (
	Counter Type = iota
	Gauge
	LongTaskTimer
	Timer
	DistributionSummary
	Other
)

Directories

Path Synopsis
util

Jump to

Keyboard shortcuts

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