prometheus

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: MIT, Apache-2.0, BSD-2-Clause, + 4 more Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 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      = "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 string = "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: TypeForCounterVec,
		LabelNames: GetLabels(CircuitBreakerGaugeLabelOrder),
	}

	CircuitBreakerHalfOpen = metricDesc{
		Name:       MetricsNameCircuitBreakerHalfOpen,
		Help:       "total of half-open circuit breaker",
		MetricType: TypeForCounterVec,
		LabelNames: GetLabels(CircuitBreakerGaugeLabelOrder),
	}
)
View Source
var (
	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()
		},
		CalleeMethod: func(args interface{}) string {
			val := args.(*model.ServiceCallResult)
			return val.Method
		},
		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 {
			return NilValue
		},
		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.Labels["method"]
		},
		CallerLabels: func(args interface{}) string {
			val := args.(*model.RateLimitGauge)
			return formatLabelsToStr(val.Labels)
		},
	}

	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 {
	IP      string `yaml:"metricHost"`
	PortStr string `yaml:"metricPort"`
	Port    int    `yaml:"-"`
}

Config prometheus 的配置

func (*Config) SetDefault

func (c *Config) SetDefault()

SetDefault Setting defaults

func (*Config) Verify

func (c *Config) Verify() error

Verify verify config

type LabelValueSupplier

type LabelValueSupplier func(val interface{}) string

type MetricsType

type MetricsType int

MetricsType 指标类型,对应 Prometheus 提供的 Collector 类型

const (
	// metric type
	TypeForCounterVec MetricsType = iota
	TypeForGaugeVec
	TypeForGauge
	TypeForHistogramVec
	TypeForMaxGaugeVec
)

type PrometheusHandler

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

PrometheusHandler

func (*PrometheusHandler) Close

func (p *PrometheusHandler) Close() error

func (*PrometheusHandler) GetHttpHandler

func (p *PrometheusHandler) GetHttpHandler() http.Handler

GetHttpHandler 获取 handler

func (*PrometheusHandler) ReportStat

func (p *PrometheusHandler) ReportStat(metricsType model.MetricType, metricsVal model.InstanceGauge) error

ReportStat 上报采集指标到 prometheus,这里只针对部分 model.InstanceGauge 的实现做处理

type PrometheusReporter

type PrometheusReporter struct {
	*plugin.PluginBase
	*common.RunContext
	// contains filtered or unexported fields
}

func (*PrometheusReporter) Destroy

func (g *PrometheusReporter) Destroy() error

Destroy

func (*PrometheusReporter) Info

func (s *PrometheusReporter) Info() model.StatInfo

func (*PrometheusReporter) Init

Init 初始化插件

func (*PrometheusReporter) Name

func (s *PrometheusReporter) Name() string

Name 插件名,一个类型下插件名唯一

func (*PrometheusReporter) ReportStat

func (s *PrometheusReporter) ReportStat(metricType model.MetricType, metricsVal model.InstanceGauge) error

func (*PrometheusReporter) Type

func (s *PrometheusReporter) Type() common.Type

Type 插件类型

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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