Documentation ¶
Overview ¶
Package inspect inspects '/proc/*'.
Index ¶
- Variables
- func BinarySearchInt64(nums []int64, v int64) int
- func ConvertDS(dss ...DSEntry) (header []string, rows [][]string)
- func ConvertNS(nss ...NSEntry) (header []string, rows [][]string)
- func ConvertPS(nss ...PSEntry) (header []string, rows [][]string)
- func ConvertSS(nss ...SSEntry) (header []string, rows [][]string)
- func StringDS(header []string, rows [][]string, topLimit int) string
- func StringNS(header []string, rows [][]string, topLimit int) string
- func StringPS(header []string, rows [][]string, topLimit int) string
- func StringSS(header []string, rows [][]string, topLimit int) string
- type CSV
- type DSEntry
- type EntryOp
- type NSEntry
- type OpFunc
- func WithDiskDevice(name string) OpFunc
- func WithExtraPath(path string) OpFunc
- func WithLocalPort(port int64) OpFunc
- func WithNetworkInterface(name string) OpFunc
- func WithPID(pid int64) OpFunc
- func WithProgram(name string) OpFunc
- func WithProgramMatch(matchFunc func(string) bool) OpFunc
- func WithRemotePort(port int64) OpFunc
- func WithTCP() OpFunc
- func WithTCP6() OpFunc
- func WithTopExecPath(path string) OpFunc
- func WithTopLimit(limit int) OpFunc
- func WithTopStream(str *top.Stream) OpFunc
- type PSEntry
- type Proc
- type ProcSlice
- type SSEntry
- type Tree
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func BinarySearchInt64 ¶
BinarySearchInt64 binary-searches the int64 slice and returns the index of the matching element. So input slice must be sorted. It returns -1 if not found.
Types ¶
type CSV ¶
type CSV struct { FilePath string PID int64 DiskDevice string NetworkInterface string Header []string HeaderIndex map[string]int MinUnixNanosecond int64 MinUnixSecond int64 MaxUnixNanosecond int64 MaxUnixSecond int64 // ExtraPath contains extra information. ExtraPath string // TopStream feeds realtime 'top' command data in the background, every second. // And whenver 'Add' gets called, returns the latest 'top' data. // Use this to provide more accurate CPU usage. TopStream *top.Stream // Rows are sorted by unix time in nanoseconds. // It's the number of nanoseconds (not seconds) elapsed // since January 1, 1970 UTC. Rows []Proc }
CSV represents CSV data (header, rows, etc.).
func NewCSV ¶
func NewCSV(fpath string, pid int64, diskDevice string, networkInterface string, extraPath string, tcfg *top.Config) (c *CSV, err error)
NewCSV returns a new CSV.
func ReadCSV ¶
ReadCSV reads a CSV file and convert to 'CSV'. Make sure to change this whenever 'Proc' fields are updated.
func (*CSV) Add ¶
Add is called periodically to append a new entry to CSV; it only appends. If the data is used for time series, make sure to handle missing time stamps between. e.g. interpolate by estimating the averages between last row and new row to be inserted.
func (*CSV) Interpolate ¶
Interpolate interpolates missing rows in CSV assuming CSV is to be collected for every second. 'Missing' means unix seconds in rows are not continuous. It fills in the empty rows by estimating the averages. It returns a new copy of CSV. And the new copy sets all unix nanoseconds to 0., since it's now aggregated by the unix "second".
type DSEntry ¶
type DSEntry struct { Device string ReadsCompleted uint64 SectorsRead uint64 TimeSpentOnReading string WritesCompleted uint64 SectorsWritten uint64 TimeSpentOnWriting string // extra fields for sorting TimeSpentOnReadingMs uint64 TimeSpentOnWritingMs uint64 }
DSEntry represents disk statistics. Simplied from 'DiskStat'.
type EntryOp ¶
type EntryOp struct { ProgramMatchFunc func(string) bool PID int64 TopLimit int // for ss TCP bool TCP6 bool LocalPort int64 RemotePort int64 // for ps TopExecPath string TopStream *top.Stream // for Proc DiskDevice string NetworkInterface string ExtraPath string // contains filtered or unexported fields }
EntryOp defines entry option(filter).
type NSEntry ¶
type NSEntry struct { Interface string ReceiveBytes string ReceivePackets uint64 TransmitBytes string TransmitPackets uint64 // extra fields for sorting ReceiveBytesNum uint64 TransmitBytesNum uint64 }
NSEntry represents network statistics. Simplied from 'NetDev'.
type OpFunc ¶
type OpFunc func(*EntryOp)
OpFunc applies each filter.
func WithDiskDevice ¶
WithDiskDevice to filter entries by disk device.
func WithExtraPath ¶
WithExtraPath to filter entries by disk device.
func WithLocalPort ¶
WithLocalPort to filter entries by local port.
func WithNetworkInterface ¶
WithNetworkInterface to filter entries by disk device.
func WithProgram ¶
WithProgram to filter entries by program name.
func WithProgramMatch ¶
WithProgramMatch matches command name.
func WithRemotePort ¶
WithRemotePort to filter entries by remote port.
func WithTCP6 ¶
func WithTCP6() OpFunc
WithTCP6 to filter entries by TCP6. Can be used with 'WithTCP'.
func WithTopExecPath ¶
WithTopExecPath configures 'top' command path.
func WithTopStream ¶
WithTopStream gets the PSEntry from the 'top' stream.
type PSEntry ¶
type PSEntry struct { Program string State string PID int64 PPID int64 CPU string VMRSS string VMSize string FD uint64 Threads uint64 VoluntaryCtxtSwitches uint64 NonvoluntaryCtxtSwitches uint64 // extra fields for sorting CPUNum float64 VMRSSNum uint64 VMSizeNum uint64 }
PSEntry is a process entry. Simplied from 'Stat' and 'Status'.
type Proc ¶
type Proc struct { // UnixNanosecond is unix nano second when this Proc row gets created. UnixNanosecond int64 // UnixSecond is the converted Unix seconds from UnixNano. UnixSecond int64 PSEntry PSEntry LoadAvg proc.LoadAvg DSEntry DSEntry ReadsCompletedDelta uint64 SectorsReadDelta uint64 WritesCompletedDelta uint64 SectorsWrittenDelta uint64 // ReadBytesDelta is calculated from SectorsReadDelta // while SECTOR_SIZE is 512 (one sector is 512-byte) in Linux kernel // (http://lkml.iu.edu/hypermail/linux/kernel/1508.2/00431.html). ReadBytesDelta uint64 ReadMegabytesDelta uint64 // WriteBytesDelta is calculated from SectorsWrittenDelta // while SECTOR_SIZE is 512 (one sector is 512-byte) in Linux kernel // (http://lkml.iu.edu/hypermail/linux/kernel/1508.2/00431.html). WriteBytesDelta uint64 WriteMegabytesDelta uint64 NSEntry NSEntry ReceiveBytesDelta string ReceivePacketsDelta uint64 TransmitBytesDelta string TransmitPacketsDelta uint64 ReceiveBytesNumDelta uint64 TransmitBytesNumDelta uint64 // Extra exists to support customized data query. Extra []byte }
Proc represents an entry of various system statistics.
func Combine ¶
Combine combines a list Proc and returns one combined Proc. Field values are estimated. UnixNanosecond is reset 0. And UnixSecond and other fields that cannot be averaged are set with the field value in the last element. This is meant to be used to combine Proc rows with duplicate unix second timestamps.
func GetProc ¶
GetProc returns current 'Proc' data. PID is required. Disk device, network interface, extra path are optional.
func Interpolate ¶
Interpolate returns the missing, estimated 'Proc's if any. It assumes that 'upper' Proc is later than 'lower'. And UnixSecond and other fields that cannot be averaged are set with the field value in the last element.
type ProcSlice ¶
type ProcSlice []Proc
ProcSlice is a slice of 'Proc' and implements the sort.Sort interface in unix nano/second ascending order.
type SSEntry ¶
type SSEntry struct { Protocol string Program string State string PID int64 LocalIP string LocalPort int64 RemoteIP string RemotePort int64 User user.User }
SSEntry is a socket entry. Simplied from 'NetTCP'.
type Tree ¶
Tree defines binary search tree.
func NewBinaryTree ¶
NewBinaryTree builds a new binary search tree. The original slice won't be sorted.
func NewBinaryTreeInt64 ¶
NewBinaryTreeInt64 builds a new binary search tree. The original slice won't be sorted.