metrics

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package metrics is for collecting RPC and many other metrics.

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

func AddCollector(name string, fun CollectorFunc)

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

func Init

func Init(url *common.URL)

Init Metrics module

func InitAppInfo

func InitAppInfo(appName string, appVersion string)

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

func Publish

func Publish(event MetricsEvent)

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

func SetRegistry

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

SetRegistry extend more MetricRegistry, default PrometheusRegistry

func Subscribe

func Subscribe(typ string, ch chan MetricsEvent)

Subscribe subscribes to events of the given type.

func Unsubscribe

func Unsubscribe(typ string)

Unsubscribe unsubscribes from events of the given type.

Types

type AggregateCounterVec

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

func NewAggregateCounterVec(metricRegistry MetricRegistry, metricKey *MetricKey) AggregateCounterVec

type ApplicationMetricLevel

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

func GetApplicationLevel

func GetApplicationLevel() *ApplicationMetricLevel

func (*ApplicationMetricLevel) Tags

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

type BaseCollector

type BaseCollector struct {
	R MetricRegistry
}

func (*BaseCollector) StateCount

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

type CollectorFunc

type CollectorFunc func(MetricRegistry, *common.URL)

CollectorFunc used to extend more indicators

type ConfigCenterLevel

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

func NewConfigCenterLevel

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

func (ConfigCenterLevel) Tags

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

type CounterMetric

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

CounterMetric counter metric

type CounterVec

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

func NewCounterVec(metricRegistry MetricRegistry, metricKey *MetricKey) CounterVec

NewCounterVec create a CounterVec default implementation.

type DefaultAggregateCounterVec

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

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

type DefaultCounterVec

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

DefaultCounterVec is a default CounterVec implementation.

func (*DefaultCounterVec) Add

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

func (*DefaultCounterVec) Inc

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

type DefaultGaugeVec

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

DefaultGaugeVec is a default GaugeVec implementation.

func (*DefaultGaugeVec) Add

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

func (*DefaultGaugeVec) Dec

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

func (*DefaultGaugeVec) Inc

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

func (*DefaultGaugeVec) Set

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

func (*DefaultGaugeVec) Sub

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

type DefaultQpsMetricVec

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

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

type DefaultQuantileMetricVec

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

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

type DefaultRtVec

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

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

type GaugeMetric

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

GaugeMetric gauge metric

type GaugeVec

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

func NewGaugeVec(metricRegistry MetricRegistry, metricKey *MetricKey) GaugeVec

NewGaugeVec create a GaugeVec default implementation.

type MethodMetricLevel

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

func (MethodMetricLevel) Tags

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

type MetricId

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

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

func NewMetricIdByLabels

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

NewMetricIdByLabels create a MetricId by key and labels

func (*MetricId) TagKeys

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

type MetricKey

type MetricKey struct {
	Name string
	Desc string
}

func NewMetricKey

func NewMetricKey(name string, desc string) *MetricKey

type MetricLevel

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

type MetricRegistry

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

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

type MetricsEvent interface {
	Type() string
}

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

type ObservableMetric

type ObservableMetric interface {
	Observe(float64)
}

histogram summary rt metric

type Option

type Option func(*Options)

func WithAggregationBucketNum

func WithAggregationBucketNum(num int) Option

func WithAggregationEnabled

func WithAggregationEnabled() Option

func WithAggregationTimeWindowSeconds

func WithAggregationTimeWindowSeconds(seconds int) Option

func WithConfigCenterEnabled

func WithConfigCenterEnabled() Option

func WithEnabled

func WithEnabled() Option

WithEnabled this will enable rpc and tracing by default, config-center, metadata and registry metrics will still be in disable state.

func WithMetadataEnabled

func WithMetadataEnabled() Option

func WithPath

func WithPath(path string) Option

func WithPort

func WithPort(port int) Option

func WithPrometheus

func WithPrometheus() Option

func WithPrometheusExporterEnabled

func WithPrometheusExporterEnabled() Option

func WithPrometheusGatewayInterval

func WithPrometheusGatewayInterval(interval time.Duration) Option

func WithPrometheusGatewayJob

func WithPrometheusGatewayJob(job string) Option

func WithPrometheusGatewayPassword

func WithPrometheusGatewayPassword(password string) Option

func WithPrometheusGatewayUrl

func WithPrometheusGatewayUrl(url string) Option

func WithPrometheusGatewayUsername

func WithPrometheusGatewayUsername(username string) Option

func WithPrometheusPushgatewayEnabled

func WithPrometheusPushgatewayEnabled() Option

func WithRegistryEnabled

func WithRegistryEnabled() Option

type Options

type Options struct {
	Metrics *global.MetricsConfig
}

func NewOptions

func NewOptions(opts ...Option) *Options

type QpsMetricVec

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

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

func NewQpsMetricVec

func NewQpsMetricVec(metricRegistry MetricRegistry, metricKey *MetricKey) QpsMetricVec

type QuantileMetricVec

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

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

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

type RtVec

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

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

NewRtVec create a RtVec default implementation DefaultRtVec.

type ServiceMetricLevel

type ServiceMetricLevel struct {
	*ApplicationMetricLevel
	Interface string
}

func NewServiceMetric

func NewServiceMetric(interfaceName string) *ServiceMetricLevel

func (ServiceMetricLevel) Tags

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

type Type

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