Documentation
¶
Index ¶
- Constants
- Variables
- func GetEnvDuration(name string, defaultValue time.Duration) time.Duration
- func GetEnvInt(name string, defaultValue uint64) uint64
- func GetEnvSize(name string, defaultValue uint64) uint64
- func RandomSleep(ctx context.Context, max time.Duration)
- func Tick(ctx context.Context, interval, jitter time.Duration, f func() error) error
- type Action
- type ActionFn
- type Config
- type ConfigFn
- type Dog
- type ExitFile
- type ReasonItem
- type State
- type ThresholdType
Constants ¶
View Source
const ( DefaultInterval = time.Minute DefaultTimes = 5 DefaultRSSThreshold = 256 * 1024 * 1024 // 256 M DefaultJitter = 10 * time.Second )
View Source
const DogExit = "Dog.exit"
Variables ¶
View Source
var DefaultAction = func(dir string, debug bool, reasons []ReasonItem) { log.Printf("program exit by godog, reason: %v", reasons) data, _ := json.Marshal(ExitFile{ Pid: os.Getpid(), Time: time.Now().Format(time.RFC3339), Reasons: reasons, }) name := filepath.Join(dir, DogExit) _ = os.WriteFile(name, data, os.ModePerm) os.Exit(1) }
View Source
var DefaultCPUThreshold = uint64(50 * runtime.NumCPU())
Functions ¶
func GetEnvSize ¶
func RandomSleep ¶
RandomSleep will sleep for a random amount of time up to max. If the shutdown channel is closed, it will return before it has finished sleeping.
Types ¶
type Action ¶
type Action interface {
DoAction(dir string, debug bool, reasons []ReasonItem)
}
type ActionFn ¶
type ActionFn func(dir string, debug bool, reasons []ReasonItem)
type Config ¶
type Config struct {
Pid int
// RSSThreshold RSS 上限
RSSThreshold uint64
// CPUPercentThreshold 上限
CPUPercentThreshold uint64
// Interval 检查间隔
Interval time.Duration
// Jitter 间隔时间附加随机抖动
Jitter time.Duration
// Times 连续多少次
Times int
// Action 采取的动作
Action Action
// Debug 调试模式
Debug bool
// Dir 检查 Dog.busy 和生成 Dog.exit 的路径
Dir string
}
type ConfigFn ¶
type ConfigFn func(c *Config)
func WithCPUPercentThreshold ¶
func WithConfig ¶
func WithInterval ¶
func WithRSSThreshold ¶
type ExitFile ¶
type ExitFile struct {
Pid int `json:"pid"`
Time string `json:"time"`
Reasons []ReasonItem `json:"reasons"`
}
type ReasonItem ¶
type ReasonItem struct {
Type ThresholdType `json:"type"`
Reason string `json:"reason"`
Values []uint64 `json:"values"`
Threshold any `json:"threshold"`
Profile string `json:"profile"`
}
type ThresholdType ¶
type ThresholdType string
const ( RSS ThresholdType = "RSS" CPU ThresholdType = "CPU" )
Click to show internal directories.
Click to hide internal directories.
