Documentation ¶
Overview ¶
Package procfs provides functions to retrieve system, kernel and process metrics from the pseudo-filesystem proc.
Example:
package main import ( "fmt" "log" "github.com/prometheus/client_golang/procfs" ) func main() { p, err := procfs.Self() if err != nil { log.Fatalf("could not get process: %s", err) } stat, err := p.Stat() if err != nil { log.Fatalf("could not get process stat: %s", err) } fmt.Printf("command: %s\n", stat.Comm) fmt.Printf("cpu time: %fs\n", stat.CPUTime()) fmt.Printf("vsize: %dB\n", stat.VirtualMemory()) fmt.Printf("rss: %dB\n", stat.ResidentMemory()) }
Index ¶
Constants ¶
const DefaultMountPoint = "/proc"
DefaultMountPoint is the common mount point of the proc filesystem.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FS ¶
type FS string
FS represents the pseudo-filesystem proc, which provides an interface to kernel data structures.
func NewFS ¶
NewFS returns a new FS mounted under the given mountPoint. It will error if the mount point can't be read.
type Proc ¶
type Proc struct { // The process ID. PID int // contains filtered or unexported fields }
Proc provides information about a running process.
func (Proc) FileDescriptors ¶
FileDescriptors returns the currently open file descriptors of a process.
func (Proc) FileDescriptorsLen ¶
FileDescriptorsLen returns the number of currently open file descriptors of a process.
func (Proc) NewLimits ¶
func (p Proc) NewLimits() (ProcLimits, error)
NewLimits returns the current soft limits of the process.
type ProcLimits ¶
type ProcLimits struct { CPUTime int FileSize int DataSize int StackSize int CoreFileSize int ResidentSet int Processes int OpenFiles int LockedMemory int AddressSpace int FileLocks int PendingSignals int MsqqueueSize int NicePriority int RealtimePriority int RealtimeTimeout int }
ProcLimits represents the soft limits for each of the process's resource limits.
type ProcStat ¶
type ProcStat struct { // The process ID. PID int // The filename of the executable. Comm string // The process state. State string // The PID of the parent of this process. PPID int // The process group ID of the process. PGRP int // The session ID of the process. Session int // The controlling terminal of the process. TTY int // The ID of the foreground process group of the controlling terminal of // the process. TPGID int // The kernel flags word of the process. Flags uint // The number of minor faults the process has made which have not required // loading a memory page from disk. MinFlt uint // The number of minor faults that the process's waited-for children have // made. CMinFlt uint // The number of major faults the process has made which have required // loading a memory page from disk. MajFlt uint // The number of major faults that the process's waited-for children have // made. CMajFlt uint // Amount of time that this process has been scheduled in user mode, // measured in clock ticks. UTime uint // Amount of time that this process has been scheduled in kernel mode, // measured in clock ticks. STime uint // Amount of time that this process's waited-for children have been // scheduled in user mode, measured in clock ticks. CUTime uint // Amount of time that this process's waited-for children have been // scheduled in kernel mode, measured in clock ticks. CSTime uint // For processes running a real-time scheduling policy, this is the negated // scheduling priority, minus one. Priority int // The nice value, a value in the range 19 (low priority) to -20 (high // priority). Nice int // Number of threads in this process. NumThreads int // The time the process started after system boot, the value is expressed // in clock ticks. Starttime uint64 // Virtual memory size in bytes. VSize int // Resident set size in pages. RSS int // contains filtered or unexported fields }
ProcStat provides status information about the process, read from /proc/[pid]/stat.
func (ProcStat) ResidentMemory ¶
ResidentMemory returns the resident memory size in bytes.
func (ProcStat) VirtualMemory ¶
VirtualMemory returns the virtual memory size in bytes.