utils

package
v0.0.0-...-bf58f96 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT, MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxCheckTimes = 10
)

Variables

View Source
var (
	IsEnableRateLimiter bool      // 是否开启速率限制
	GlobalCpuLimiter    *CPULimit // CPU使用率限制
)
View Source
var ClockTicks = 100 // default value

Functions

func GetCpuTime

func GetCpuTime() (*cpu.TimesStat, error)

GetCpuTime copy from github.com/shirou/[email protected]+incompatible/process/process_linux.go

func GetDateTime

func GetDateTime() (localTime string, utcTime string, unixTime int64)

GetDateTime 获取系统当前时间

func GetEnv

func GetEnv(key string, dfault string, combineWith ...string) string

GetEnv retrieves the environment variable key. If it does not exist it returns the default. github.com/shirou/[email protected]+incompatible/internal/common/common.go

func HashRawConfig

func HashRawConfig(config *common.Config) (error, string)

HashRawConfig 获取配置hash值

func IsInDocker

func IsInDocker() bool

当且仅当 /.dockerenv 的前提下 文件存在且 cgroup 权限为 ro 或者 /proc/1/sched 进程号不为 1

func Md5

func Md5(str string) string

Md5 获取字符md5

func SetResourceLimit

func SetResourceLimit(maxCpuLimit, checkTimes int)

SetResourceLimit : 在一定程度上限制CPU使用 maxCpuLimit: 最大CPU使用率限制 checkTimes: 资源限制的检查次数

Types

type CPULimit

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

CPULimit cpu limit object

func NewCPULimit

func NewCPULimit(l, checkTimes int) *CPULimit

NewCPULimit new cpu limit object

func (*CPULimit) Allow

func (c *CPULimit) Allow() bool

Allow : judge current

func (*CPULimit) GetCheckInterval

func (c *CPULimit) GetCheckInterval() time.Duration

GetCheckInterval : get cpu check interval

func (*CPULimit) GetCpuTimes

func (c *CPULimit) GetCpuTimes(p *process.Process) (*cpu.TimesStat, error)

GetCpuTimes 获取指定进程的CPU时间统计信息。 p: 指向 process.Process 的指针,代表要查询的进程。 返回值:

*cpu.TimesStat: 指向 cpu.TimesStat 的指针,包含CPU时间统计信息。
error: 如果发生错误,将返回相应的错误信息。

func (*CPULimit) Start

func (c *CPULimit) Start()

Start : start cpu limit

func (*CPULimit) Stop

func (c *CPULimit) Stop()

Stop : stop cpu limit

Jump to

Keyboard shortcuts

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