Documentation ¶
Index ¶
- Constants
- func CheckBlackWhiteList(name string, whiteList []*regexp.Regexp, blackList []*regexp.Regexp) bool
- func CheckInSimpleList(name string, list []*regexp.Regexp) bool
- func CheckInStringList(name string, list []*regexp.Regexp) bool
- func CounterDiff(now, before uint64) uint64
- func FilterDiskIoStats(diskStats map[string]DiskStats, config configs.DiskConfig) map[string]DiskStats
- func FilterNetIOStats(ioCounterStat []net.IOCountersStat, config configs.NetConfig) []net.IOCountersStat
- func FilterNetInterfaceStats(interfaceStats []net.InterfaceStat, config configs.NetConfig) []net.InterfaceStat
- func FilterPartitions(partitionStats []disk.PartitionStat, config configs.DiskConfig) []disk.PartitionStat
- func GetCpuCores() (int32, error)
- func GetDateTime(tolerate int64) (string, string, int)
- func GetDiskSpeed(last, current map[string]DiskStats)
- func GetLoginUsers() (int, error)
- func GetMaxFiles() (int, error)
- func GetNetInfoFromDev() (map[string]NetInfo, error)
- func GetProcEnv() (runningProc, blockedProc, proc, ctxt int, lasterr error)
- func GetSwapInfo() (in, out float64, lasterr error)
- func GetSwapinfoLogic(sinfo *swapinfo) (*swapinfo, error)
- func GetUname() (string, error)
- func IOCounters(names ...string) (map[string]DiskStats, error)
- func PhysicalMemoryInfo(specialSource bool) (info *mem.VirtualMemoryStat, err error)
- func ProtoCounters(protocols []string) ([]net.ProtoCountersStat, error)
- type BKInfoStat
- type BaseSocketInfo
- type CpuReport
- type DiskReport
- type DiskStats
- type ElementInfo
- type EnvReport
- type FileSocketItem
- type InetDiagMsg
- type InetDiagReq
- type JobMgr
- type LoadReport
- type MemReport
- type NetInfo
- type NetReport
- type NoneSocketFilter
- type ReportData
- type SocketFilter
- type SocketInfo
- type SocketStatusCount
- type Stat
- type SystemReport
- type TcpSocketListenFilter
- type TcpSocketListenPortFilter
- type UdpSocketListenPortFilter
Constants ¶
const ( FilePath = "/proc/sys/fs/file-max" VersionPath = "/proc/version" StatPath = "/proc/stat" PtsPath = "/dev/pts" )
const ( DevPath = "/proc/net/dev" CollsIndex = 13 CarrierIndex = 14 SumLength = 16 NetCoutnerMaxSize = math.MaxUint64 )
const ( TCP_ESTABLISHED = iota + 1 TCP_SYN_SENT TCP_SYN_RECV TCP_FIN_WAIT1 TCP_FIN_WAIT2 TCP_TIME_WAIT TCP_CLOSE TCP_CLOSE_WAIT TCP_LAST_ACK TCP_LISTEN // 0x0A TCP_CLOSING // now a valid state TCP_MAX_STATES )
tcp status reference: source/include/net/tcp_states.h
enum { TCP_ESTABLISHED = 1, TCP_SYN_SENT, TCP_SYN_RECV, TCP_FIN_WAIT1, TCP_FIN_WAIT2, TCP_TIME_WAIT, TCP_CLOSE, TCP_CLOSE_WAIT, TCP_LAST_ACK, TCP_LISTEN, TCP_CLOSING, * Now a valid state * TCP_NEW_SYN_RECV, // kernel > 4.1 TCP_MAX_STATES * Leave at the end! * };
const (
SectorSize = 512
)
const TCPDIAG_GETSOCK = 18
Socket identity struct inet_diag_sockid { __be16 idiag_sport; __be16 idiag_dport; __be32 idiag_src[4]; __be32 idiag_dst[4]; __u32 idiag_if; __u32 idiag_cookie[2];
#define INET_DIAG_NOCOOKIE (~0U) };
/* Request structure
struct inet_diag_req { __u8 idiag_family; /* Family of addresses. __u8 idiag_src_len; __u8 idiag_dst_len; __u8 idiag_ext; /* Query extended information struct inet_diag_sockid id; __u32 idiag_states; __u32 idiag_dbs; }; struct inet_diag_msg { __u8 idiag_family; __u8 idiag_state; __u8 idiag_timer; __u8 idiag_retrans; struct inet_diag_sockid id; __u32 idiag_expires; __u32 idiag_rqueue; __u32 idiag_wqueue; __u32 idiag_uid; __u32 idiag_inode; };
Variables ¶
This section is empty.
Functions ¶
func CheckBlackWhiteList ¶
根据黑白名单检查是否对应的数据应该上报,返回true则应上报,false则不应上报
func CounterDiff ¶
func FilterDiskIoStats ¶
func FilterDiskIoStats(diskStats map[string]DiskStats, config configs.DiskConfig) map[string]DiskStats
FilterDiskIoStats 过滤磁盘io信息
func FilterNetIOStats ¶
func FilterNetIOStats(ioCounterStat []net.IOCountersStat, config configs.NetConfig) []net.IOCountersStat
func FilterNetInterfaceStats ¶
func FilterNetInterfaceStats(interfaceStats []net.InterfaceStat, config configs.NetConfig) []net.InterfaceStat
func FilterPartitions ¶
func FilterPartitions(partitionStats []disk.PartitionStat, config configs.DiskConfig) []disk.PartitionStat
FilterPartitions :
func GetDiskSpeed ¶
func GetLoginUsers ¶
GetLoginUsers: 获取当前登录的用户数量,通过遍历/dev/pts下的终端数量,判断用户个数 返回内容是map,key为用户名,value为该用户登录的数量,以便统计
func GetProcEnv ¶
func GetSwapInfo ¶
func GetSwapinfoLogic ¶
func GetSwapinfoLogic(sinfo *swapinfo) (*swapinfo, error)
func PhysicalMemoryInfo ¶
func PhysicalMemoryInfo(specialSource bool) (info *mem.VirtualMemoryStat, err error)
func ProtoCounters ¶
func ProtoCounters(protocols []string) ([]net.ProtoCountersStat, error)
Types ¶
type BKInfoStat ¶
add systemtype info
type BaseSocketInfo ¶
type CpuReport ¶
type DiskReport ¶
type DiskReport struct { DiskStats map[string]DiskStats `json:"diskstat"` Partitions []disk.PartitionStat `json:"partition"` Usage []disk.UsageStat `json:"usage"` }
func GetDiskInfo ¶
func GetDiskInfo(config configs.DiskConfig) (*DiskReport, error)
func (*DiskReport) AssignDiskStats ¶
func (report *DiskReport) AssignDiskStats(stats map[string]DiskStats)
type DiskStats ¶
type DiskStats struct { ReadCount uint64 `json:"readCount"` MergedReadCount uint64 `json:"mergedReadCount"` WriteCount uint64 `json:"writeCount"` MergedWriteCount uint64 `json:"mergedWriteCount"` ReadBytes uint64 `json:"readBytes"` WriteBytes uint64 `json:"writeBytes"` ReadTime uint64 `json:"readTime"` WriteTime uint64 `json:"writeTime"` IopsInProgress uint64 `json:"iopsInProgress"` IoTime uint64 `json:"ioTime"` WeightedIO uint64 `json:"weightedIO"` Name string `json:"name"` SerialNumber string `json:"serialNumber"` Label string `json:"label"` MajorNum uint64 `json:"major"` MinorNum uint64 `json:"minor"` ReadSectors uint64 `json:"readSectors"` WriteSectors uint64 `json:"writeSectors"` SpeedIORead float64 `json:"speedIORead"` SpeedByteRead float64 `json:"speedByteRead"` SpeedIOWrite float64 `json:"speedIOWrite"` SpeedByteWrite float64 `json:"speedByteWrite"` Util float64 `json:"util"` AvgrqSz float64 `json:"avgrq_sz"` AvgquSz float64 `json:"avgqu_sz"` Await float64 `json:"await"` Svctm float64 `json:"svctm"` }
func ToDiskStats ¶
func ToDiskStats(stats disk.IOCountersStat) DiskStats
type EnvReport ¶
type EnvReport struct { Contab []toolkit.Crontab `json:"crontab"` Host string `json:"host"` Route string `json:"route"` MaxFiles int `json:"maxfiles"` Uname string `json:"uname"` LoginUser int `json:"login_user"` RunningProc int `json:"proc_running_current"` BlockedProc int `json:"procs_blocked_current"` Totalproc int `json:"procs_processes_total"` Ctxt int `json:"procs_ctxt_total"` }
func GetEnvInfo ¶
func GetEnvInfo(config configs.BasereportConfig) (*EnvReport, error)
type FileSocketItem ¶
type InetDiagMsg ¶
type InetDiagMsg struct { Family uint8 // 0,1 State uint8 // 1,2 Timer uint8 // 2,3 Retrans uint8 // 3,4 Sport uint16 // 4,6 Dport uint16 // 6,8 Src [4]uint32 Dst [4]uint32 If uint32 Cookie [2]uint32 Expires uint32 Rqueue uint32 Wqueue uint32 Uid uint32 Inode uint32 }
Inet_diag_msg represents recv msg data
type InetDiagReq ¶
type InetDiagReq struct { Family uint8 SrcLen uint8 DstLen uint8 Ext uint8 Sport uint16 Dport uint16 Src [4]uint32 Dst [4]uint32 If uint32 Cookie [2]uint32 States uint32 Dbs uint32 }
Inet_diag_req represents request msg data
func (InetDiagReq) MarshalBinary ¶
func (m InetDiagReq) MarshalBinary() []byte
MarshalBinary marshals a Message into a byte slice.
type JobMgr ¶
type JobMgr struct {
// contains filtered or unexported fields
}
func (*JobMgr) MarkFinished ¶
func (jm *JobMgr) MarkFinished()
type LoadReport ¶
type MemReport ¶
type MemReport struct { Swapin float64 `json:"swap_in"` Swapout float64 `json:"swap_out"` Info *mem.VirtualMemoryStat `json:"meminfo"` SwapInfo *mem.SwapMemoryStat `json:"vmstat"` }
type NetReport ¶
type NetReport struct { Interface []net.InterfaceStat `json:"interface"` Stat []Stat `json:"dev"` Netstat SocketStatusCount `json:"netstat"` Protocol map[string]map[string]int64 `json:"protocolstat"` }
type NoneSocketFilter ¶
type NoneSocketFilter struct{}
NoneSocketFilter will return all sockets
func (NoneSocketFilter) Filter ¶
func (f NoneSocketFilter) Filter(socket SocketInfo) bool
type ReportData ¶
type ReportData struct { bkcommon.DateTime Cpu *CpuReport `json:"cpu"` Env *EnvReport `json:"env"` Disk *DiskReport `json:"disk"` Load *LoadReport `json:"load"` Mem *MemReport `json:"mem"` Net *NetReport `json:"net"` System *SystemReport `json:"system"` }
func Collect ¶
func Collect(config configs.BasereportConfig, firstRun bool) (ReportData, error)
type SocketFilter ¶
type SocketFilter interface { // return true when you want the msg Filter(socket SocketInfo) bool }
type SocketInfo ¶
type SocketInfo struct { BaseSocketInfo Inode uint64 Type uint32 // syscall.SOCK_STREAM or syscall.SOCK_DGR }
type SocketStatusCount ¶
type SocketStatusCount struct { Established uint `json:"established"` SyncSent uint `json:"syncSent"` SynRecv uint `json:"synRecv"` FinWait1 uint `json:"finWait1"` FinWait2 uint `json:"finWait2"` TimeWait uint `json:"timeWait"` Close uint `json:"close"` CloseWait uint `json:"closeWait"` LastAck uint `json:"lastAck"` Listen uint `json:"listen"` Closing uint `json:"closing"` }
func GetTcp4SocketStatusCount ¶
func GetTcp4SocketStatusCount() (SocketStatusCount, error)
GetTcp4SocketStatusCount get sockets status
func GetTcp4SocketStatusCountByNetlink ¶
func GetTcp4SocketStatusCountByNetlink() (SocketStatusCount, error)
GetTcp4SocketStatusCountByNetlink get sockets status by netlink
type Stat ¶
type Stat struct { net.IOCountersStat NetInfo SpeedSent uint64 `json:"speedSent"` // speed of sent, bytes/second SpeedRecv uint64 `json:"speedRecv"` // speed of received, bytes/second SpeedPacketsSent uint64 `json:"speedPacketsSent"` // speed of packets sent, nr/second SpeedPacketsRecv uint64 `json:"speedPacketsRecv"` // speed of packets received, nr/second }
type SystemReport ¶
type SystemReport struct {
Info BKInfoStat `json:"info"`
}
func GetSystemInfo ¶
func GetSystemInfo() (*SystemReport, error)
type TcpSocketListenFilter ¶
type TcpSocketListenFilter struct{}
TcpSocketListenFilter only return listen status tcp sockets
func (TcpSocketListenFilter) Filter ¶
func (f TcpSocketListenFilter) Filter(socket SocketInfo) bool
type TcpSocketListenPortFilter ¶
TcpSocketListenPortFilter filters
func (TcpSocketListenPortFilter) Filter ¶
func (f TcpSocketListenPortFilter) Filter(socket SocketInfo) bool
type UdpSocketListenPortFilter ¶
UdpSocketListenPortFilter filters
func (UdpSocketListenPortFilter) Filter ¶
func (f UdpSocketListenPortFilter) Filter(socket SocketInfo) bool