Documentation ¶
Overview ¶
Package metrics is for collecting RPC and many other metrics.
Index ¶
- Constants
- func AddCollector(name string, fun CollectorFunc)
- func Init(url *common.URL)
- func InitAppInfo(appName string, appVersion string)
- func Publish(event MetricsEvent)
- func SetRegistry(name string, v func(*common.URL) MetricRegistry)
- func Subscribe(typ string, ch chan MetricsEvent)
- func Unsubscribe(typ string)
- type AggregateCounterVec
- type ApplicationMetricLevel
- type BaseCollector
- type CollectorFunc
- type ConfigCenterLevel
- type CounterMetric
- type CounterVec
- type DefaultAggregateCounterVec
- type DefaultCounterVec
- type DefaultGaugeVec
- func (d *DefaultGaugeVec) Add(labels map[string]string, v float64)
- func (d *DefaultGaugeVec) Dec(labels map[string]string)
- func (d *DefaultGaugeVec) Inc(labels map[string]string)
- func (d *DefaultGaugeVec) Set(labels map[string]string, v float64)
- func (d *DefaultGaugeVec) Sub(labels map[string]string, v float64)
- type DefaultQpsMetricVec
- type DefaultQuantileMetricVec
- type DefaultRtVec
- type GaugeMetric
- type GaugeVec
- type MethodMetricLevel
- type MetricId
- type MetricKey
- type MetricLevel
- type MetricRegistry
- type MetricSample
- type MetricsEvent
- type ObservableMetric
- type Option
- func WithAggregationBucketNum(num int) Option
- func WithAggregationEnabled() Option
- func WithAggregationTimeWindowSeconds(seconds int) Option
- func WithConfigCenterEnabled() Option
- func WithEnabled() Option
- func WithMetadataEnabled() Option
- func WithPath(path string) Option
- func WithPort(port int) Option
- func WithPrometheus() Option
- func WithPrometheusExporterEnabled() Option
- func WithPrometheusGatewayInterval(interval time.Duration) Option
- func WithPrometheusGatewayJob(job string) Option
- func WithPrometheusGatewayPassword(password string) Option
- func WithPrometheusGatewayUrl(url string) Option
- func WithPrometheusGatewayUsername(username string) Option
- func WithPrometheusPushgatewayEnabled() Option
- func WithRegistryEnabled() Option
- type Options
- type QpsMetricVec
- type QuantileMetricVec
- type ReportMode
- type Reporter
- type ReporterConfig
- type RtOpts
- type RtVec
- type ServiceMetricLevel
- type Type
Constants ¶
const ( DefaultCompression = 100 DefaultBucketNum = 10 DefaultTimeWindowSeconds = 120 )
const ( ReportModePull = "pull" ReportModePush = "push" )
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 InitAppInfo ¶
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 ¶
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) Dec ¶
func (d *DefaultGaugeVec) Dec(labels map[string]string)
func (*DefaultGaugeVec) Inc ¶
func (d *DefaultGaugeVec) Inc(labels map[string]string)
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.
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.
type GaugeMetric ¶
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 ¶
NewMetricIdByLabels create a MetricId by key and labels
type MetricKey ¶
func NewMetricKey ¶
type MetricLevel ¶
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 WithAggregationEnabled ¶
func WithAggregationEnabled() 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 WithPrometheus ¶
func WithPrometheus() Option
func WithPrometheusExporterEnabled ¶
func WithPrometheusExporterEnabled() Option
func WithPrometheusPushgatewayEnabled ¶
func WithPrometheusPushgatewayEnabled() Option
func WithRegistryEnabled ¶
func WithRegistryEnabled() Option
type QpsMetricVec ¶
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 ¶
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 ServiceMetricLevel ¶
type ServiceMetricLevel struct { *ApplicationMetricLevel Interface string }
func NewServiceMetric ¶
func NewServiceMetric(interfaceName string) *ServiceMetricLevel
func (ServiceMetricLevel) Tags ¶
func (m ServiceMetricLevel) Tags() map[string]string