flow

package
v0.0.0-...-6cf1638 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: MulanPSL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BreakerHandler *gobreaker.CircuitBreaker[[]byte]

Functions

This section is empty.

Types

type QpsCounter

type QpsCounter struct {
	QpsCounterMap sync.Map
}
var (
	QpsCounterHandler *QpsCounter
)

QpsCounterHandler QPS计算器

func (*QpsCounter) GetQpsCounterItem

func (qc *QpsCounter) GetQpsCounterItem(serviceName string, redisCli *redis.Client) *QpsCounterItem

type QpsCounterItem

type QpsCounterItem struct {
	RedisCli *redis.Client

	Requests  int64     // 请求计数
	StartTime time.Time // 开始时间
	// contains filtered or unexported fields
}

func (*QpsCounterItem) GetQps

func (qci *QpsCounterItem) GetQps(ctx context.Context) (string, error)

func (*QpsCounterItem) WriteQPS

func (qci *QpsCounterItem) WriteQPS(ctx context.Context, qps float64) error

type QpsLimiter

type QpsLimiter struct {
	// key: serviceName value: *flow.QpsLimiterItem
	QpsLimiterMap sync.Map
}
var QpsLimiterHandler *QpsLimiter

QpsLimiterHandler QPS限流器

func (*QpsLimiter) GetQpsLimiter

func (ql *QpsLimiter) GetQpsLimiter(serverName string, qps float64) *QpsLimiterItem

type QpsLimiterItem

type QpsLimiterItem struct {
	ServiceName string
	QpsLimiter  *rate.Limiter
}

type ReqCounter

type ReqCounter struct {
	// key:ServiceName val: *flow.ReqCounterItem
	ReqCounterMap sync.Map
}
var (
	ReqCounterHandler *ReqCounter
)

ReqCounterHandler 请求计算器

func (*ReqCounter) GetReqCounterItem

func (handler *ReqCounter) GetReqCounterItem(serviceName string, redisCli *redis.Client) *ReqCounterItem

type ReqCounterItem

type ReqCounterItem struct {
	Client      *redis.Client
	ServiceName string // 服务名称
}

ReqCounterItem 结构体用于统计服务的请求

func (*ReqCounterItem) CleanupOldData

func (src *ReqCounterItem) CleanupOldData(ctx context.Context, retentionDays int) (int64, error)

CleanupOldData 清理指定服务的过期统计数据

func (*ReqCounterItem) GetHourlyCountsForDate

func (src *ReqCounterItem) GetHourlyCountsForDate(ctx context.Context, date string) ([]int64, error)

GetHourlyCountsForDate 获取指定日期每小时的请求计数

func (*ReqCounterItem) RecordRequest

func (src *ReqCounterItem) RecordRequest(ctx context.Context) error

RecordRequest 增加当前小时的请求计数

Jump to

Keyboard shortcuts

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