Documentation ¶
Index ¶
- Constants
- Variables
- func GetLabels(m map[string]LabelValueSupplier) []string
- type Config
- type LabelValueSupplier
- type MetricsType
- type PrometheusReporter
- func (s *PrometheusReporter) Destroy() error
- func (s *PrometheusReporter) Info() model.StatInfo
- func (s *PrometheusReporter) Init(ctx *plugin.InitContext) error
- func (s *PrometheusReporter) Name() string
- func (s *PrometheusReporter) ReportStat(metricsType model.MetricType, metricsVal model.InstanceGauge) error
- func (s *PrometheusReporter) Type() common.Type
Constants ¶
View Source
const ( // CalleeNamespace SystemMetricName. CalleeNamespace = "callee_namespace" CalleeService = "callee_service" CalleeSubset = "callee_subset" CalleeInstance = "callee_instance" CalleeRetCode = "callee_result_code" CalleeMethod = "callee_method" CallerNamespace = "caller_namespace" CallerService = "caller_service" CallerIP = "caller_ip" CallerLabels = "caller_labels" MetricNameLabel = "metric_name" // MetricsNameUpstreamRequestTotal 与路由、请求相关的指标信息. MetricsNameUpstreamRequestTotal = "upstream_rq_total" MetricsNameUpstreamRequestSuccess = "upstream_rq_success" MetricsNameUpstreamRequestTimeout = "upstream_rq_timeout" MetricsNameUpstreamRequestMaxTimeout = "upstream_rq_max_timeout" MetricsNameUpstreamRequestDelay = "upstream_rq_delay" // 限流相关指标信息. MetricsNameRateLimitRequestTotal = "ratelimit_rq_total" MetricsNameRateLimitRequestPass = "ratelimit_rq_pass" MetricsNameRateLimitRequestLimit = "ratelimit_rq_limit" // 熔断相关指标信息. MetricsNameCircuitBreakerOpen = "circuitbreaker_open" MetricsNameCircuitBreakerHalfOpen = "circuitbreaker_halfopen" // SystemMetricValue. NilValue = "__NULL__" )
View Source
const (
// PluginName is the name of the plugin.
PluginName = "prometheus"
)
Variables ¶
View Source
var ( RouterGaugeNames []string = []string{ MetricsNameUpstreamRequestTotal, MetricsNameUpstreamRequestSuccess, MetricsNameUpstreamRequestTimeout, MetricsNameUpstreamRequestMaxTimeout, } UpstreamRequestTotal = metricDesc{ Name: MetricsNameUpstreamRequestTotal, Help: "total of request per period", MetricType: TypeForCounterVec, LabelNames: GetLabels(InstanceGaugeLabelOrder), } UpstreamRequestSuccess = metricDesc{ Name: MetricsNameUpstreamRequestSuccess, Help: "total of success request per period", MetricType: TypeForCounterVec, LabelNames: GetLabels(InstanceGaugeLabelOrder), } UpstreamRequestTimeout = metricDesc{ Name: MetricsNameUpstreamRequestTimeout, Help: "total of request delay per period", MetricType: TypeForGaugeVec, LabelNames: GetLabels(InstanceGaugeLabelOrder), } UpstreamRequestMaxTimeout = metricDesc{ Name: MetricsNameUpstreamRequestMaxTimeout, Help: "maximum request delay per period", MetricType: TypeForMaxGaugeVec, LabelNames: GetLabels(InstanceGaugeLabelOrder), } UpstreamRequestDelay = metricDesc{ Name: MetricsNameUpstreamRequestDelay, Help: "per request delay per period", MetricType: TypeForHistogramVec, LabelNames: GetLabels(InstanceGaugeLabelOrder), } )
服务路由相关指标.
View Source
var ( RateLimitGaugeNames []string = []string{ MetricsNameRateLimitRequestTotal, MetricsNameRateLimitRequestPass, MetricsNameRateLimitRequestLimit, } RateLimitRequestTotal = metricDesc{ Name: MetricsNameRateLimitRequestTotal, Help: "total of rate limit per period", MetricType: TypeForCounterVec, LabelNames: GetLabels(RateLimitGaugeLabelOrder), } RateLimitRequestPass = metricDesc{ Name: MetricsNameRateLimitRequestPass, Help: "total of passed request per period", MetricType: TypeForCounterVec, LabelNames: GetLabels(RateLimitGaugeLabelOrder), } RateLimitRequestLimit = metricDesc{ Name: MetricsNameRateLimitRequestLimit, Help: "total of limited request per period", MetricType: TypeForCounterVec, LabelNames: GetLabels(RateLimitGaugeLabelOrder), } )
限流相关指标.
View Source
var ( CircuitBreakerGaugeNames []string = []string{ MetricsNameCircuitBreakerOpen, MetricsNameCircuitBreakerHalfOpen, } CircuitBreakerOpen = metricDesc{ Name: MetricsNameCircuitBreakerOpen, Help: "total of opened circuit breaker", MetricType: TypeForGaugeVec, LabelNames: GetLabels(CircuitBreakerGaugeLabelOrder), } CircuitBreakerHalfOpen = metricDesc{ Name: MetricsNameCircuitBreakerHalfOpen, Help: "total of half-open circuit breaker", MetricType: TypeForGaugeVec, LabelNames: GetLabels(CircuitBreakerGaugeLabelOrder), } )
View Source
var ( // InstanceGaugeLabelOrder 实例监控指标的label顺序 InstanceGaugeLabelOrder map[string]LabelValueSupplier = map[string]LabelValueSupplier{ CalleeNamespace: func(args interface{}) string { val := args.(*model.ServiceCallResult) return val.GetCalledInstance().GetNamespace() }, CalleeService: func(args interface{}) string { val := args.(*model.ServiceCallResult) return val.GetCalledInstance().GetService() }, CalleeSubset: func(args interface{}) string { val := args.(*model.ServiceCallResult) return val.CalledInstance.GetLogicSet() }, CalleeInstance: func(args interface{}) string { val := args.(*model.ServiceCallResult) return fmt.Sprintf("%s:%d", val.GetCalledInstance().GetHost(), val.GetCalledInstance().GetPort()) }, CalleeRetCode: func(args interface{}) string { val := args.(*model.ServiceCallResult) if val.GetRetCode() == nil { return NilValue } return fmt.Sprintf("%d", *val.GetRetCode()) }, CallerLabels: func(args interface{}) string { val := args.(*model.ServiceCallResult) if val.SourceService == nil || len(val.SourceService.Metadata) == 0 { return "" } labels := val.SourceService.Metadata var ret []string for k, v := range labels { ret = append(ret, fmt.Sprintf("%s=%s", k, v)) } return strings.Join(ret, ",") }, CallerNamespace: func(args interface{}) string { val := args.(*model.ServiceCallResult) namespace := val.GetCallerNamespace() if namespace != "" { return namespace } return NilValue }, CallerService: func(args interface{}) string { val := args.(*model.ServiceCallResult) service := val.GetCallerService() if service != "" { return service } return NilValue }, CallerIP: func(args interface{}) string { return NilValue }, } RateLimitGaugeLabelOrder map[string]LabelValueSupplier = map[string]LabelValueSupplier{ CalleeNamespace: func(args interface{}) string { val := args.(*model.RateLimitGauge) return val.GetNamespace() }, CalleeService: func(args interface{}) string { val := args.(*model.RateLimitGauge) return val.GetService() }, CalleeMethod: func(args interface{}) string { val := args.(*model.RateLimitGauge) return val.Method }, CallerLabels: func(args interface{}) string { val := args.(*model.RateLimitGauge) return formatLabelsToStr(val.Arguments) }, } CircuitBreakerGaugeLabelOrder map[string]LabelValueSupplier = map[string]LabelValueSupplier{ CalleeNamespace: func(args interface{}) string { val := args.(*model.CircuitBreakGauge) return val.GetCalledInstance().GetNamespace() }, CalleeService: func(args interface{}) string { val := args.(*model.CircuitBreakGauge) return val.GetCalledInstance().GetService() }, CalleeMethod: func(args interface{}) string { val := args.(*model.CircuitBreakGauge) return val.Method }, CalleeSubset: func(args interface{}) string { val := args.(*model.CircuitBreakGauge) return val.GetCalledInstance().GetLogicSet() }, CalleeInstance: func(args interface{}) string { val := args.(*model.CircuitBreakGauge) return fmt.Sprintf("%s:%d", val.GetCalledInstance().GetHost(), val.GetCalledInstance().GetPort()) }, CallerNamespace: func(args interface{}) string { val := args.(*model.CircuitBreakGauge) return val.GetNamespace() }, CallerService: func(args interface{}) string { val := args.(*model.CircuitBreakGauge) return val.GetService() }, } )
Functions ¶
func GetLabels ¶
func GetLabels(m map[string]LabelValueSupplier) []string
Types ¶
type Config ¶
type Config struct { Type string `yaml:"type"` IP string `yaml:"metricHost"` PortStr string `yaml:"metricPort"` Interval time.Duration `yaml:"interval"` Address string `yaml:"address"` // contains filtered or unexported fields }
Config prometheus 的配置
type LabelValueSupplier ¶
type LabelValueSupplier func(val interface{}) string
type MetricsType ¶
type MetricsType int
MetricsType 指标类型,对应 Prometheus 提供的 Collector 类型.
const ( // TypeForCounterVec metric type. TypeForCounterVec MetricsType = iota TypeForGaugeVec TypeForGauge TypeForHistogramVec TypeForMaxGaugeVec )
type PrometheusReporter ¶
type PrometheusReporter struct { *plugin.PluginBase *common.RunContext // contains filtered or unexported fields }
PrometheusReporter is a prometheus reporter.
func (*PrometheusReporter) Init ¶
func (s *PrometheusReporter) Init(ctx *plugin.InitContext) error
Init 初始化插件.
func (*PrometheusReporter) ReportStat ¶
func (s *PrometheusReporter) ReportStat(metricsType model.MetricType, metricsVal model.InstanceGauge) error
ReportStat 报告统计数据.
Click to show internal directories.
Click to hide internal directories.