Documentation ¶
Index ¶
- Constants
- Variables
- func FileRootPath() string
- func InitLog()
- func ListenStart(remote string, useHTTP bool)
- func RouterEnhance(hs *grope.GHttpServe)
- func RouterProc(hs *grope.GHttpServe)
- func UsageCPU() (float64, error)
- type CGroup
- type CPU
- type CPUGroup
- type CPUInfo
- type Disk
- type DiskStat
- type DiskStats
- type LoadAvg
- type MemInfo
- type Mount
- type Mounts
- type NetStat
- type Proc
- type Resp
- type SockStat
- type Stat
- type Swaps
- type Version
Constants ¶
const ( // CodeSuccess 成功 CodeSuccess = iota // CodeFile 失败 CodeFile )
const ( // ProductionEnv 是否生产环境,在生产环境下控制台不会输出任何日志 ProductionEnv = "PRODUCTION" // LogDirEnv 日志文件目录 LogDirEnv = "LOG_DIR" // LogFileMaxSizeEnv 每个日志文件保存的最大尺寸 单位:M LogFileMaxSizeEnv = "LOG_FILE_MAX_SIZE" // LogFileMaxAgeEnv 文件最多保存多少天 LogFileMaxAgeEnv = "LOG_FILE_MAX_AGE" // LogUtcEnv CST & UTC 时间 LogUtcEnv = "LOG_UTC" // LogLevelEnv 日志级别(debugLevel/infoLevel/warnLevel/ErrorLevel/panicLevel/fatalLevel) LogLevelEnv = "LOG_LEVEL" )
const (
DefaultBufferSize = 1024
)
const (
ListenAddr = "LISTEN_ADDR"
)
Variables ¶
var CGroups []CGroup
CGroups CGroup集合
Functions ¶
Types ¶
type CGroup ¶
type CGroup struct { // SubSysName subsystem的名字 SubSysName string // subsystem所关联到的cgroup树的ID,如果多个subsystem关联到同一颗cgroup树,那么他们的这个字段将一样, // 比如这里的cpu和cpuacct就一样,表示他们绑定到了同一颗树。如果出现下面的情况,这个字段将为0: // // 当前subsystem没有和任何cgroup树绑定 // // 当前subsystem已经和cgroup v2的树绑定 // // 当前subsystem没有被内核开启 Hierarchy int // subsystem所关联的cgroup树中进程组的个数,也即树上节点的个数 NumCGroups int // 1表示开启,0表示没有被开启(可以通过设置内核的启动参数“cgroup_disable”来控制subsystem的开启). Enabled bool }
CGroup 是Linux下的一种将进程按组进行管理的机制,在用户层看来,cgroup技术就是把系统中的所有进程组织成一颗一颗独立的树, 每棵树都包含系统的所有进程,树的每个节点是一个进程组,而每颗树又和一个或者多个subsystem关联,树的作用是将进程分组, 而subsystem的作用就是对这些组进行操作。
type CPU ¶
type CPU struct { Core string // CPU核 User int64 // 从系统启动开始累计到当前时刻,处于用户态的运行时间,不包含 nice值为负进程 Nice int64 // 从系统启动开始累计到当前时刻,nice值为负的进程所占用的CPU时间 System int64 // 从系统启动开始累计到当前时刻,处于核心态的运行时间 Idle int64 // 从系统启动开始累计到当前时刻,除IO等待时间以外的其它等待时间 IOWait int64 // 从系统启动开始累计到当前时刻,IO等待时间(since 2.5.41) Irq int64 // 从系统启动开始累计到当前时刻,硬中断时间(since 2.6.0-test4) SoftIrq int64 // 从系统启动开始累计到当前时刻,软中断时间(since 2.6.0-test4) Steal int64 // 虚拟化环境中运行其他操作系统上花费的时间(since 2.6.11) Guest int64 // 操作系统运行虚拟CPU花费的时间(since 2.6.24) GuestNice int64 // 运行一个带nice值的guest花费的时间(since 2.6.33) }
CPU 利用率
总的cpu时间totalCpuTime = user + nice + system + idle + iowait + irq + softirq + stealstolen + guest
进程的总Cpu时间processCpuTime = utime + stime + cutime + cstime,该值包括其所有线程的cpu时间
type CPUInfo ¶
type CPUInfo struct { Processor string // 逻辑处理器的id(0) VendorID string // CPU制造商(GenuineIntel) CPUFamily string // CPU产品系列代号(6) Model string // CPU属于其系列中的哪一代号(79) ModelName string // CPU属于的名字、编号、主频(Intel(R) Xeon(R) CPU E5-26xx v4) Stepping string // CPU属于制作更新版本(1) Microcode string // (0x1) CPUMHz string // CPU的实际使用主频(2394.454) CacheSize string // CPU二级cache大小(4096 KB) PhysicalID string // 物理封装的处理器的id,从0开始,说明我的服务器有两个物理CPU(0) Siblings string // 位于相同物理封装的处理器中的逻辑处理器的数量(1) CoreID string // 当前物理核在其所处的CPU中的编号,该编号不一定连续(0) CPUCores string // 该逻辑核所处CPU的物理核数(1) ApicID string // 用来区分不同逻辑和的编号,每个逻辑和的此编号不同,不一定连续(0) InitialApicID string // (0) Fpu string // 是否具有浮点运算单元(yes) FpuException string // 是否支持浮点计算异常(yes) CPUIDLevel string // 执行cpuid指令前,eax寄存器中的值,不同cpuid指令会返回不同内容(13) WP string // 表明当前CPU是否在内核态支持对用户空间的写保护(yes) Flags []string // 当前CPU支持的功能(fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch bmi1 avx2 bmi2 rdseed adx xsaveopt) Bogomips string // 测算CPU速度(4788.90) ClFlushSize string // 每次刷新缓存的大小单位(64) CacheAlignment string // 缓存地址对齐单位(64) AddressSizes string // 可访问地址空间为数(40 bits physical, 48 bits virtual) PowerManagement string // 电源管理相关 }
CPUInfo 中央处理器信息
type DiskStat ¶
type DiskStat struct { Major int `json:"major"` // major device number Minor int `json:"minor"` // minor device number Name string `json:"name"` // device name ReadIOs uint64 `json:"read_ios"` // number of read I/Os processed ReadMerges uint64 `json:"read_merges"` // number of read I/Os merged with in-queue I/O ReadSectors uint64 `json:"read_sectors"` // number of 512 byte sectors read ReadTicks uint64 `json:"read_ticks"` // total wait time for read requests in milliseconds WriteIOs uint64 `json:"write_ios"` // number of write I/Os processed WriteMerges uint64 `json:"write_merges"` // number of write I/Os merged with in-queue I/O WriteSectors uint64 `json:"write_sectors"` // number of 512 byte sectors written WriteTicks uint64 `json:"write_ticks"` // total wait time for write requests in milliseconds InFlight uint64 `json:"in_flight"` // number of I/Os currently in flight IOTicks uint64 `json:"io_ticks"` // total time this block device has been active in milliseconds TimeInQueue uint64 `json:"time_in_queue"` // total wait time for all requests in milliseconds }
DiskStat is disk statistics to help measure disk activity.
Note:
- On a very busy or long-lived system values may wrap.
- No kernel locks are held while modifying these counters. This implies that minor inaccuracies may occur.
More more info see: https://www.kernel.org/doc/Documentation/iostats.txt and https://www.kernel.org/doc/Documentation/block/stat.txt
func (*DiskStat) GetIOTicks ¶
GetIOTicks 返回磁盘一直处于活动状态的持续时间
func (*DiskStat) GetReadTicks ¶
GetReadTicks 返回等待读取请求的持续时间
func (*DiskStat) GetTimeInQueue ¶
GetTimeInQueue 返回所有请求等待的持续时间
func (*DiskStat) GetWriteTicks ¶
GetWriteTicks 返回写请求等待的持续时间
type LoadAvg ¶
type LoadAvg struct { LAvg1 string // 1-分钟平均负载 LAvg5 string // 5-分钟平均负载 LAvg15 string // 15-分钟平均负载 NrRunning string // 分子是正在运行的进程数,分母是进程总数 LastPid string // 最大的pid值,包括轻量级进程,即线程 }
LoadAvg 系统平均负载均衡
type MemInfo ¶
type MemInfo struct { MemTotal string // 所有可用RAM大小 (即物理内存减去一些预留位和内核的二进制代码大小) MemFree string // LowFree与HighFree的总和,被系统留着未使用的内存 MemAvailable string // 有些应用程序会根据系统的可用内存大小自动调整内存申请的多少,所以需要一个记录当前可用内存数量的统计值,MemFree并不适用,因为MemFree不能代表全部可用的内存,系统中有些内存虽然已被使用但是可以回收的,比如cache/buffer、slab都有一部分可以回收,所以这部分可回收的内存加上MemFree才是系统可用的内存,即MemAvailable。/proc/meminfo中的MemAvailable是内核使用特定的算法估算出来的,要注意这是一个估计值,并不精确。 Buffers string // 用来给文件做缓冲大小 Cached string // 被高速缓冲存储器(cache memory)用的内存的大小(等于 diskcache minus SwapCache ) SwapCached string // 被高速缓冲存储器(cache memory)用的交换空间的大小。已经被交换出来的内存,但仍然被存放在swap file中。用来在需要的时候很快的被替换而不需要再次打开I/O端口 Active string // 在活跃使用中的缓冲或高速缓冲存储器页面文件的大小,除非非常必要否则不会被移作他用 Inactive string // 在不经常使用中的缓冲或高速缓冲存储器页面文件的大小,可能被用于其他途径 ActiveAnon string // InactiveAnon string // ActiveFile string // InactiveFile string // Unevictable string // MLocked string // SwapTotal string // 交换空间的总大小 SwapFree string // 未被使用交换空间的大小 Dirty string // 等待被写回到磁盘的内存大小 WriteBack string // 正在被写回到磁盘的内存大小 AnonPages string // 未映射页的内存大小 Mapped string // 设备和文件等映射的大小 Shmem string // Slab string // 内核数据结构缓存的大小,可以减少申请和释放内存带来的消耗 SReclaimable string // 可收回Slab的大小 SUnreclaim string // 不可收回Slab的大小(SUnreclaim+SReclaimable=Slab) KernelStack string // 每一个用户线程都会分配一个kernel stack(内核栈),内核栈虽然属于线程,但用户态的代码不能访问,只有通过系统调用(syscall)、自陷(trap)或异常(exception)进入内核态的时候才会用到,也就是说内核栈是给kernel code使用的。在x86系统上Linux的内核栈大小是固定的8K或16K PageTables string // 管理内存分页页面的索引表的大小 NFSUnstable string // 不稳定页表的大小 Bounce string // 有些老设备只能访问低端内存,比如16M以下的内存,当应用程序发出一个I/O 请求,DMA的目的地址却是高端内存时(比如在16M以上),内核将在低端内存中分配一个临时buffer作为跳转,把位于高端内存的缓存数据复制到此处。这种额外的数据拷贝被称为“bounce buffering”,会降低I/O 性能。大量分配的bounce buffers 也会占用额外的内存。 WriteBackTmp string // CommitLimit string // CommittedAS string // VMAllocTotal string // 可以vmalloc虚拟内存大小 VMAllocUsed string // 已经被使用的虚拟内存大小 VMAllocChunk string // HardwareCorrupted string // 当系统检测到内存的硬件故障时,会把有问题的页面删除掉,不再使用,/proc/meminfo中的HardwareCorrupted统计了删除掉的内存页的总大小。 AnonHugePages string // CmaTotal string // CmaFree string // HugePagesTotal string // 对应内核参数 vm.nr_hugepages,也可以在运行中的系统上直接修改 /proc/sys/vm/nr_hugepages,修改的结果会立即影响空闲内存 MemFree的大小,因为HugePages在内核中独立管理,只要一经定义,无论是否被使用,都不再属于free memory。 HugePagesFree string // HugePagesRsvd string // HugePagesSurp string // HugePageSize string // DirectMap4k string // DirectMap2M string // DirectMap1G string // }
MemInfo 存储器使用信息,包括物理内存和交换内存
type NetStat ¶
type NetStat struct { // TcpExt EmbryonicRsts uint64 `json:"embryonic_rsts"` PruneCalled uint64 `json:"prune_called"` RcvPruned uint64 `json:"rcv_pruned"` OfoPruned uint64 `json:"ofo_pruned"` OutOfWindowIcmps uint64 `json:"out_of_window_icmps"` LockDroppedIcmps uint64 `json:"lock_dropped_icmps"` ArpFilter uint64 `json:"arp_filter"` TW uint64 `json:"tw"` TWRecycled uint64 `json:"tw_recycled"` TWKilled uint64 `json:"tw_killed"` PAWSPassive uint64 `json:"paws_passive"` PAWSActive uint64 `json:"paws_active"` PAWSEstab uint64 `json:"paws_estab"` DelayedACKs uint64 `json:"delayed_acks"` DelayedACKLocked uint64 `json:"delayed_ack_locked"` DelayedACKLost uint64 `json:"delayed_ack_lost"` ListenOverflows uint64 `json:"listen_overflows"` ListenDrops uint64 `json:"listen_drops"` TCPPrequeued uint64 `json:"tcp_prequeued"` TCPDirectCopyFromBacklog uint64 `json:"tcp_direct_copy_from_backlog"` TCPDirectCopyFromPrequeue uint64 `json:"tcp_direct_copy_from_prequeue"` TCPPrequeueDropped uint64 `json:"tcp_prequeue_dropped"` TCPHPHits uint64 `json:"tcp_hp_hits"` TCPHPHitsToUser uint64 `json:"tcp_hp_hits_to_user"` TCPPureAcks uint64 `json:"tcp_pure_acks"` TCPHPAcks uint64 `json:"tcp_hp_acks"` TCPRenoRecovery uint64 `json:"tcp_reno_recovery"` TCPSackRecovery uint64 `json:"tcp_sack_recovery"` TCPSACKReneging uint64 `json:"tcp_sack_reneging"` TCPFACKReorder uint64 `json:"tcp_fack_reorder"` TCPSACKReorder uint64 `json:"tcp_sack_reorder"` TCPRenoReorder uint64 `json:"tcp_reno_reorder"` TCPTSReorder uint64 `json:"tcp_ts_reorder"` TCPFullUndo uint64 `json:"tcp_full_undo"` TCPPartialUndo uint64 `json:"tcp_partial_undo"` TCPDSACKUndo uint64 `json:"tcp_dsack_undo"` TCPLossUndo uint64 `json:"tcp_loss_undo"` TCPLoss uint64 `json:"tcp_loss"` TCPLostRetransmit uint64 `json:"tcp_lost_retransmit"` TCPRenoFailures uint64 `json:"tcp_reno_failures"` TCPSackFailures uint64 `json:"tcp_sack_failures"` TCPLossFailures uint64 `json:"tcp_loss_failures"` TCPFastRetrans uint64 `json:"tcp_fast_retrans"` TCPForwardRetrans uint64 `json:"tcp_forward_retrans"` TCPSlowStartRetrans uint64 `json:"tcp_slow_start_retrans"` TCPTimeouts uint64 `json:"tcp_timeouts"` TCPLossProbes uint64 `json:"tcp_loss_probes"` TCPLossProbeRecovery uint64 `json:"tcp_loss_probe_recovery"` TCPRenoRecoveryFail uint64 `json:"tcp_reno_recovery_fail"` TCPSackRecoveryFail uint64 `json:"tcp_sack_recovery_fail"` TCPSchedulerFailed uint64 `json:"tcp_scheduler_failed"` TCPRcvCollapsed uint64 `json:"tcp_rcv_collapsed"` TCPDSACKOldSent uint64 `json:"tcp_dsack_old_sent"` TCPDSACKOfoSent uint64 `json:"tcp_dsack_ofo_sent"` TCPDSACKRecv uint64 `json:"tcp_dsack_recv"` TCPDSACKOfoRecv uint64 `json:"tcp_dsack_ofo_recv"` TCPAbortOnSyn uint64 `json:"tcp_abort_on_syn"` TCPAbortOnData uint64 `json:"tcp_abort_on_data"` TCPAbortOnClose uint64 `json:"tcp_abort_on_close"` TCPAbortOnMemory uint64 `json:"tcp_abort_on_memory"` TCPAbortOnTimeout uint64 `json:"tcp_abort_on_timeout"` TCPAbortOnLinger uint64 `json:"tcp_abort_on_linger"` TCPAbortFailed uint64 `json:"tcp_abort_failed"` TCPMemoryPressures uint64 `json:"tcp_memory_pressures"` TCPSACKDiscard uint64 `json:"tcp_sack_discard"` TCPDSACKIgnoredOld uint64 `json:"tcp_dsack_ignored_old"` TCPDSACKIgnoredNoUndo uint64 `json:"tcp_dsack_ignored_no_undo"` TCPSpuriousRTOs uint64 `json:"tcp_spurious_rtos"` TCPMD5NotFound uint64 `json:"tcp_md5_not_found"` TCPMD5Unexpected uint64 `json:"tcp_md5_unexpected"` TCPSackShifted uint64 `json:"tcp_sack_shifted"` TCPSackMerged uint64 `json:"tcp_sack_merged"` TCPSackShiftFallback uint64 `json:"tcp_sack_shift_fallback"` TCPBacklogDrop uint64 `json:"tcp_backlog_drop"` TCPMinTTLDrop uint64 `json:"tcp_min_ttl_drop"` TCPDeferAcceptDrop uint64 `json:"tcp_defer_accept_drop"` IPReversePathFilter uint64 `json:"ip_reverse_path_filter"` TCPTimeWaitOverflow uint64 `json:"tcp_time_wait_overflow"` TCPReqQFullDoCookies uint64 `json:"tcp_req_q_full_do_cookies"` TCPReqQFullDrop uint64 `json:"tcp_req_q_full_drop"` TCPRetransFail uint64 `json:"tcp_retrans_fail"` TCPRcvCoalesce uint64 `json:"tcp_rcv_coalesce"` TCPOFOQueue uint64 `json:"tcp_ofo_drop"` TCPOFODrop uint64 `json:"tcp_ofo_drop"` TCPOFOMerge uint64 `json:"tcp_ofo_merge"` TCPChallengeACK uint64 `json:"tcp_challenge_ack"` TCPSYNChallenge uint64 `json:"tcp_syn_challenge"` TCPFastOpenActive uint64 `json:"tcp_fast_open_active"` TCPFastOpenActiveFail uint64 `json:"tcp_fast_open_active_fail"` TCPFastOpenPassive uint64 `json:"tcp_fast_open_passive"` TCPFastOpenPassiveFail uint64 `json:"tcp_fast_open_passive_fail"` TCPFastOpenListenOverflow uint64 `json:"tcp_fast_open_listen_overflow"` TCPFastOpenCookieReqd uint64 `json:"tcp_fast_open_cookie_reqd"` TCPSpuriousRtxHostQueues uint64 `json:"tcp_spurious_rtx_host_queues"` BusyPollRxPackets uint64 `json:"busy_poll_rx_packets"` TCPAutoCorking uint64 `json:"tcp_auto_corking"` TCPFromZeroWindowAdv uint64 `json:"tcp_from_zero_window_adv"` TCPToZeroWindowAdv uint64 `json:"tcp_to_zero_window_adv"` TCPWantZeroWindowAdv uint64 `json:"tcp_want_zero_window_adv"` TCPSynRetrans uint64 `json:"tcp_syn_retrans"` TCPOrigDataSent uint64 `json:"tcp_orig_data_sent"` // IpExt InNoRoutes uint64 `json:"in_no_routes"` InTruncatedPkts uint64 `json:"in_truncated_pkts"` InMcastPkts uint64 `json:"in_mcast_pkts"` OutMcastPkts uint64 `json:"out_mcast_pkts"` InBcastPkts uint64 `json:"in_bcast_pkts"` OutBcastPkts uint64 `json:"out_bcast_pkts"` InOctets uint64 `json:"in_octets"` OutOctets uint64 `json:"out_octets"` InMcastOctets uint64 `json:"in_mcast_octets"` OutMcastOctets uint64 `json:"out_mcast_octets"` InBcastOctets uint64 `json:"in_bcast_octets"` OutBcastOctets uint64 `json:"out_bcast_octets"` InCsumErrors uint64 `json:"in_csum_errors"` InNoECTPkts uint64 `json:"in_no_ect_pkts"` InECT1Pkts uint64 `json:"in_ect1_pkts"` InECT0Pkts uint64 `json:"in_ect0_pkts"` InCEPkts uint64 `json:"in_ce_pkts"` }
type Proc ¶
type Proc struct { Hostname string CPUGroup *CPUGroup MemInfo *MemInfo LoadAvg *LoadAvg //Swaps *Swaps Version *Version Stat *Stat //CGroup *CGroup UsageCPU float64 Mounts *Mounts Disk *Disk //DiskStats *DiskStats SockStat *SockStat }
Proc 监听发送完整对象
type SockStat ¶
type SockStat struct { // sockets: SocketsUsed uint64 `json:"sockets_used" field:"sockets.used"` // TCP: TCPInUse uint64 `json:"tcp_in_use" field:"TCP.inuse"` TCPOrphan uint64 `json:"tcp_orphan" field:"TCP.orphan"` TCPTimeWait uint64 `json:"tcp_time_wait" field:"TCP.tw"` TCPAllocated uint64 `json:"tcp_allocated" field:"TCP.alloc"` TCPMemory uint64 `json:"tcp_memory" field:"TCP.mem"` //TCP6: TCP6InUse uint64 `json:"tcp6_in_use" field:"TCP6.inuse"` // UDP: UDPInUse uint64 `json:"udp_in_use" field:"UDP.inuse"` UDPMemory uint64 `json:"udp_memory" field:"UDP.mem"` // UDP6: UDP6InUse uint64 `json:"udp6_in_use" field:"UDP6.inuse"` // UDPLITE: UDPLITEInUse uint64 `json:"udplite_in_use" field:"UDPLITE.inuse"` // UDPLITE6: UDPLITE6InUse uint64 `json:"udplite6_in_use" field:"UDPLITE6.inuse"` // RAW: RAWInUse uint64 `json:"raw_in_use" field:"RAW.inuse"` // RAW6: RAW6InUse uint64 `json:"raw6_in_use" field:"RAW6.inuse"` // FRAG: FRAGInUse uint64 `json:"frag_in_use" field:"FRAG.inuse"` FRAGMemory uint64 `json:"frag_memory" field:"FRAG.memory"` // FRAG6: FRAG6InUse uint64 `json:"frag6_in_use" field:"FRAG6.inuse"` FRAG6Memory uint64 `json:"frag6_memory" field:"FRAG6.memory"` }
type Stat ¶
type Stat struct { CPUs []*CPU Intr string // 此处较多冗余信息,简化之,这行给出中断的信息,第一个为自系统启动以来,发生的所有的中断的次数。然后每个数对应一个特定的中断自系统启动以来所发生的次数 Ctxt string // 自系统启动以来CPU发生的上下文交换的次数 BTime string // 系统启动到现在的时间,单位为秒(s) Processes string // 自系统启动以来所创建的任务的个数目 ProcsRunning string // 当前运行队列的任务的数目 ProcsBlocked string // 当前被阻塞的任务的数目 SoftIrq string // 此行显示所有CPU的softirq总数,第一列是所有软件和每个软件的总数,后面的列是特定softirq的总数 }
Stat 这个文件包含的信息有 CPU 利用率,磁盘,内存页,内存对换,全部中断,接触开关以及赏赐自举时间