github.com/songzhibin97/gkit@v1.2.13/watching/consts.go (about)

     1  package watching
     2  
     3  import (
     4  	"os"
     5  	"time"
     6  )
     7  
     8  const (
     9  	defaultThreadTriggerMin  = 10 // 10 threads
    10  	defaultThreadTriggerAbs  = 70 // 70 threads
    11  	defaultThreadTriggerDiff = 25 // 25%
    12  
    13  	defaultCPUTriggerMin   = 10              // 10%
    14  	defaultCPUTriggerAbs   = 70              // 70%
    15  	defaultCPUTriggerDiff  = 25              // 25%
    16  	defaultCPUSamplingTime = 5 * time.Second // collect 5s cpu profile
    17  
    18  	defaultGoroutineTriggerMin  = 3000   // 3000 goroutines
    19  	defaultGoroutineTriggerAbs  = 200000 // 200k goroutines
    20  	defaultGoroutineTriggerDiff = 20     // 20%  diff
    21  
    22  	defaultMemTriggerMin  = 10 // 10%
    23  	defaultMemTriggerAbs  = 80 // 80%
    24  	defaultMemTriggerDiff = 25 // 25%
    25  
    26  	defaultGCHeapTriggerMin  = 10 // 10%
    27  	defaultGCHeapTriggerAbs  = 40 // 40%
    28  	defaultGCHeapTriggerDiff = 20 // 20%
    29  
    30  	defaultInterval        = 5 * time.Second
    31  	defaultCooldown        = time.Minute
    32  	defaultDumpProfileType = binaryDump
    33  	defaultDumpPath        = "./tmp"
    34  	defaultLoggerName      = "watching.log"
    35  	defaultLoggerFlags     = os.O_RDWR | os.O_CREATE | os.O_APPEND
    36  	defaultLoggerPerm      = 0o644
    37  	defaultShardLoggerSize = 52428800 // 50m
    38  )
    39  
    40  type dumpProfileType int
    41  
    42  const (
    43  	binaryDump dumpProfileType = 0
    44  	textDump   dumpProfileType = 1
    45  )
    46  
    47  type configureType int
    48  
    49  const (
    50  	mem configureType = iota
    51  	cpu
    52  	thread
    53  	goroutine
    54  	gcHeap
    55  )
    56  
    57  var type2name = map[configureType]string{
    58  	mem:       "mem",
    59  	cpu:       "cpu",
    60  	thread:    "thread",
    61  	goroutine: "goroutine",
    62  	gcHeap:    "gcHeap",
    63  }
    64  
    65  const (
    66  	cgroupMemLimitPath  = "/sys/fs/cgroup/memory/memory.limit_in_bytes"
    67  	cgroupCpuQuotaPath  = "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"
    68  	cgroupCpuPeriodPath = "/sys/fs/cgroup/cpu/cpu.cfs_period_us"
    69  )
    70  
    71  const minCollectCyclesBeforeDumpStart = 10
    72  
    73  const (
    74  	LogLevelInfo = iota
    75  	LogLevelDebug
    76  )
    77  
    78  const (
    79  	// TrimResultTopN trimResult return only reserve the top n.
    80  	TrimResultTopN = 10
    81  
    82  	// NotSupportTypeMaxConfig means this profile type is
    83  	// not support control dump profile by max parameter.
    84  	NotSupportTypeMaxConfig = 0
    85  
    86  	// UniformLogFormat is the format of uniform logging.
    87  	UniformLogFormat = "[Watching] %v %v, config_min : %v, config_diff : %v, config_abs : %v, config_max : %v, previous : %v, current: %v"
    88  )