base

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxLogWaitDuration = 800 * time.Millisecond
	MaxZeroDuration    = 3
	MetricsNumber      = 5
	MaxAddDuration     = 800 * time.Millisecond
)
View Source
const (
	// metric name
	// MetricForClientRqTimeout time consumed per interface call
	MetricForClientRqTimeout string = "client_rq_timeout"
	// MetricForClientRqIntervalCount total number of client request in current interval
	MetricForClientRqIntervalCount string = "client_rq_interval_count"
	// MetricForClientRqTimeoutMin max latency of client requests
	MetricForClientRqTimeoutMin string = "client_rq_timeout_min"
	// MetricForClientRqTimeoutAvg min latency of client requests
	MetricForClientRqTimeoutAvg string = "client_rq_timeout_avg"
	// MetricForClientRqTimeoutMax average latency of client requests
	MetricForClientRqTimeoutMax string = "client_rq_timeout_max"

	// metric type
	TypeForGaugeVec string = "gauge_vec"
)

Variables

View Source
var (
	// metricDescList Metrics Description Defines the list
	MetricDescList = []metricDesc{
		{
			Name:       MetricForClientRqTimeout,
			Help:       "time consumed per interface call",
			MetricType: TypeForGaugeVec,
			LabelNames: []string{
				metrics.LabelApi,
				metrics.LabelProtocol,
				metrics.LabelErrCode,
			},
		},
		{
			Name:       MetricForClientRqIntervalCount,
			Help:       "total number of client request in current interval",
			MetricType: TypeForGaugeVec,
			LabelNames: []string{
				metrics.LabelApi,
				metrics.LabelProtocol,
				metrics.LabelErrCode,
			},
		},
		{
			Name:       MetricForClientRqTimeoutMax,
			Help:       "max latency of client requests",
			MetricType: TypeForGaugeVec,
			LabelNames: []string{
				metrics.LabelApi,
				metrics.LabelProtocol,
				metrics.LabelErrCode,
			},
		},
		{
			Name:       MetricForClientRqTimeoutMin,
			Help:       "min latency of client requests",
			MetricType: TypeForGaugeVec,
			LabelNames: []string{
				metrics.LabelApi,
				metrics.LabelProtocol,
				metrics.LabelErrCode,
			},
		},
		{
			Name:       MetricForClientRqTimeoutAvg,
			Help:       "average latency of client requests",
			MetricType: TypeForGaugeVec,
			LabelNames: []string{
				metrics.LabelApi,
				metrics.LabelProtocol,
				metrics.LabelErrCode,
			},
		},
	}
)

Functions

func BuildMetricLabels

func BuildMetricLabels(item *APICallStatisItem) map[string]string

BuildMetricLabels build metric label from APICall or APICallStatisItem

Types

type APICall

type APICall struct {
	Count            int
	Api              string
	Code             int
	Duration         int64
	Protocol         string
	TrafficDirection string
	Component        metrics.CallMetricType
}

APICall 接口调用

type APICallStatisItem

type APICallStatisItem struct {
	API              string
	TrafficDirection string
	Code             int
	Count            int64
	AccTime          int64
	MinTime          int64
	MaxTime          int64
	Protocol         string
	ZeroDuration     int64 // 没有请求持续的时间,持续时间长超过阈值从 prometheus 中移除掉
}

APICallStatisItem 接口调用统计条目

type BaseWorker

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

func NewBaseWorker

func NewBaseWorker(ctx context.Context, handler MetricsHandler) (*BaseWorker, error)

func (*BaseWorker) ReportCallMetrics

func (s *BaseWorker) ReportCallMetrics(metric metrics.CallMetric)

ReportCallMetrics report call metrics info

func (*BaseWorker) Run

func (s *BaseWorker) Run(ctx context.Context, interval time.Duration)

Run 主流程

type CacheCall

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

CacheCall 接口调用

type CacheCallStatis

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

CacheCallStatis 接口调用统计

func NewCacheCallStatis

func NewCacheCallStatis(ctx context.Context) (*CacheCallStatis, error)

func (*CacheCallStatis) Add

func (a *CacheCallStatis) Add(ac metrics.CallMetric)

add 添加接口调用数据

type CacheCallStatisItem

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

CacheCallStatisItem 接口调用统计条目

type CacheStatics

type CacheStatics struct {
	CacheCallStatis *CacheCallStatis
	// contains filtered or unexported fields
}

ComponentCacheStatics statics components

func NewCacheStatics

func NewCacheStatics(statis *CacheCallStatis) *CacheStatics

func (*CacheStatics) Add

func (c *CacheStatics) Add(ac metrics.CallMetric)

type ComponentStatics

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

ComponentStatics statics components

func (*ComponentStatics) Add

func (a *ComponentStatics) Add(ac *APICall)

add 添加接口调用数据

type MetricData

type MetricData struct {
	Name       string
	Data       float64
	Labels     map[string]string
	DeleteFlag bool
}

MetricData metric 结构体

type MetricsHandler

type MetricsHandler func(mt metrics.CallMetricType, start time.Time, staticsSlice []*APICallStatisItem)

Jump to

Keyboard shortcuts

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