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/procfs"
)
func main() {
p, err := procfs.Self()
if err != nil {
log.Fatalf("could not get process: %s", err)
}
stat, err := p.NewStat()
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
- type FS
- func (fs FS) AllProcs() (Procs, error)
- func (fs FS) NewIPVSBackendStatus() ([]IPVSBackendStatus, error)
- func (fs FS) NewIPVSStats() (IPVSStats, error)
- func (fs FS) NewProc(pid int) (Proc, error)
- func (fs FS) NewStat() (Stat, error)
- func (fs FS) ParseMDStat() (mdstates []MDStat, err error)
- func (fs FS) Path(p ...string) string
- func (fs FS) Self() (Proc, error)
- type IPVSBackendStatus
- type IPVSStats
- type MDStat
- type Mount
- type MountStats
- type MountStatsNFS
- type NFSBytesStats
- type NFSEventsStats
- type NFSOperationStats
- type NFSTransportStats
- type Proc
- func (p Proc) CmdLine() ([]string, error)
- func (p Proc) Comm() (string, error)
- func (p Proc) Executable() (string, error)
- func (p Proc) FileDescriptorTargets() ([]string, error)
- func (p Proc) FileDescriptors() ([]uintptr, error)
- func (p Proc) FileDescriptorsLen() (int, error)
- func (p Proc) MountStats() ([]*Mount, error)
- func (p Proc) NewIO() (ProcIO, error)
- func (p Proc) NewLimits() (ProcLimits, error)
- func (p Proc) NewStat() (ProcStat, error)
- type ProcIO
- type ProcLimits
- type ProcStat
- type Procs
- type Stat
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.
func (FS) NewIPVSBackendStatus ¶
func (fs FS) NewIPVSBackendStatus() ([]IPVSBackendStatus, error)
NewIPVSBackendStatus reads and returns the status of all (virtual,real) server pairs from the specified `proc` filesystem.
func (FS) NewIPVSStats ¶
NewIPVSStats reads the IPVS statistics from the specified `proc` filesystem.
func (FS) ParseMDStat ¶
ParseMDStat parses an mdstat-file and returns a struct with the relevant infos.
type IPVSBackendStatus ¶
type IPVSBackendStatus struct {
// The local (virtual) IP address.
LocalAddress net.IP
// The local (virtual) port.
LocalPort uint16
// The transport protocol (TCP, UDP).
Proto string
// The remote (real) IP address.
RemoteAddress net.IP
// The remote (real) port.
RemotePort uint16
// The current number of active connections for this virtual/real address pair.
ActiveConn uint64
// The current number of inactive connections for this virtual/real address pair.
InactConn uint64
// The current weight of this virtual/real address pair.
Weight uint64
}
IPVSBackendStatus holds current metrics of one virtual / real address pair.
func NewIPVSBackendStatus ¶
func NewIPVSBackendStatus() ([]IPVSBackendStatus, error)
NewIPVSBackendStatus reads and returns the status of all (virtual,real) server pairs.
type IPVSStats ¶
type IPVSStats struct {
// Total count of connections.
Connections uint64
// Total incoming packages processed.
IncomingPackets uint64
// Total outgoing packages processed.
OutgoingPackets uint64
// Total incoming traffic.
IncomingBytes uint64
// Total outgoing traffic.
OutgoingBytes uint64
}
IPVSStats holds IPVS statistics, as exposed by the kernel in `/proc/net/ip_vs_stats`.
type MDStat ¶
type MDStat struct {
// Name of the device.
Name string
// activity-state of the device.
ActivityState string
// Number of active disks.
DisksActive int64
// Total number of disks the device consists of.
DisksTotal int64
// Number of blocks the device holds.
BlocksTotal int64
// Number of blocks on the device that are in sync.
BlocksSynced int64
}
MDStat holds info parsed from /proc/mdstat.
type Mount ¶
type Mount struct {
// Name of the device.
Device string
// The mount point of the device.
Mount string
// The filesystem type used by the device.
Type string
// If available additional statistics related to this Mount.
// Use a type assertion to determine if additional statistics are available.
Stats MountStats
}
A Mount is a device mount parsed from /proc/[pid]/mountstats.
type MountStats ¶
type MountStats interface {
// contains filtered or unexported methods
}
A MountStats is a type which contains detailed statistics for a specific type of Mount.
type MountStatsNFS ¶
type MountStatsNFS struct {
// The version of statistics provided.
StatVersion string
// The age of the NFS mount.
Age time.Duration
// Statistics related to byte counters for various operations.
Bytes NFSBytesStats
// Statistics related to various NFS event occurrences.
Events NFSEventsStats
// Statistics broken down by filesystem operation.
Operations []NFSOperationStats
// Statistics about the NFS RPC transport.
Transport NFSTransportStats
}
A MountStatsNFS is a MountStats implementation for NFSv3 and v4 mounts.
type NFSBytesStats ¶
type NFSBytesStats struct {
// Number of bytes read using the read() syscall.
Read uint64
// Number of bytes written using the write() syscall.
Write uint64
// Number of bytes read using the read() syscall in O_DIRECT mode.
DirectRead uint64
// Number of bytes written using the write() syscall in O_DIRECT mode.
DirectWrite uint64
// Number of bytes read from the NFS server, in total.
ReadTotal uint64
// Number of bytes written to the NFS server, in total.
WriteTotal uint64
// Number of pages read directly via mmap()'d files.
ReadPages uint64
// Number of pages written directly via mmap()'d files.
WritePages uint64
}
A NFSBytesStats contains statistics about the number of bytes read and written by an NFS client to and from an NFS server.
type NFSEventsStats ¶
type NFSEventsStats struct {
// Number of times cached inode attributes are re-validated from the server.
InodeRevalidate uint64
// Number of times cached dentry nodes are re-validated from the server.
DnodeRevalidate uint64
// Number of times an inode cache is cleared.
DataInvalidate uint64
// Number of times cached inode attributes are invalidated.
AttributeInvalidate uint64
// Number of times files or directories have been open()'d.
VFSOpen uint64
// Number of times a directory lookup has occurred.
VFSLookup uint64
// Number of times permissions have been checked.
VFSAccess uint64
// Number of updates (and potential writes) to pages.
VFSUpdatePage uint64
// Number of pages read directly via mmap()'d files.
VFSReadPage uint64
// Number of times a group of pages have been read.
VFSReadPages uint64
// Number of pages written directly via mmap()'d files.
VFSWritePage uint64
// Number of times a group of pages have been written.
VFSWritePages uint64
// Number of times directory entries have been read with getdents().
VFSGetdents uint64
// Number of times attributes have been set on inodes.
VFSSetattr uint64
// Number of pending writes that have been forcefully flushed to the server.
VFSFlush uint64
// Number of times fsync() has been called on directories and files.
VFSFsync uint64
// Number of times locking has been attemped on a file.
VFSLock uint64
// Number of times files have been closed and released.
VFSFileRelease uint64
// Unknown. Possibly unused.
CongestionWait uint64
// Number of times files have been truncated.
Truncation uint64
// Number of times a file has been grown due to writes beyond its existing end.
WriteExtension uint64
// Number of times a file was removed while still open by another process.
SillyRename uint64
// Number of times the NFS server gave less data than expected while reading.
ShortRead uint64
// Number of times the NFS server wrote less data than expected while writing.
ShortWrite uint64
// Number of times the NFS server indicated EJUKEBOX; retrieving data from
// offline storage.
JukeboxDelay uint64
// Number of NFS v4.1+ pNFS reads.
PNFSRead uint64
// Number of NFS v4.1+ pNFS writes.
PNFSWrite uint64
}
A NFSEventsStats contains statistics about NFS event occurrences.
type NFSOperationStats ¶
type NFSOperationStats struct {
// The name of the operation.
Operation string
// Number of requests performed for this operation.
Requests uint64
// Number of times an actual RPC request has been transmitted for this operation.
Transmissions uint64
// Number of times a request has had a major timeout.
MajorTimeouts uint64
// Number of bytes sent for this operation, including RPC headers and payload.
BytesSent uint64
// Number of bytes received for this operation, including RPC headers and payload.
BytesReceived uint64
// Duration all requests spent queued for transmission before they were sent.
CumulativeQueueTime time.Duration
// Duration it took to get a reply back after the request was transmitted.
CumulativeTotalResponseTime time.Duration
// Duration from when a request was enqueued to when it was completely handled.
CumulativeTotalRequestTime time.Duration
}
A NFSOperationStats contains statistics for a single operation.
type NFSTransportStats ¶
type NFSTransportStats struct {
// The local port used for the NFS mount.
Port uint64
// Number of times the client has had to establish a connection from scratch
// to the NFS server.
Bind uint64
// Number of times the client has made a TCP connection to the NFS server.
Connect uint64
// Duration (in jiffies, a kernel internal unit of time) the NFS mount has
// spent waiting for connections to the server to be established.
ConnectIdleTime uint64
// Duration since the NFS mount last saw any RPC traffic.
IdleTime time.Duration
// Number of RPC requests for this mount sent to the NFS server.
Sends uint64
// Number of RPC responses for this mount received from the NFS server.
Receives uint64
// Number of times the NFS server sent a response with a transaction ID
// unknown to this client.
BadTransactionIDs uint64
// A running counter, incremented on each request as the current difference
// ebetween sends and receives.
CumulativeActiveRequests uint64
// A running counter, incremented on each request by the current backlog
// queue size.
CumulativeBacklog uint64
// Maximum number of simultaneously active RPC requests ever used.
MaximumRPCSlotsUsed uint64
// A running counter, incremented on each request as the current size of the
// sending queue.
CumulativeSendingQueue uint64
// A running counter, incremented on each request as the current size of the
// pending queue.
CumulativePendingQueue uint64
}
A NFSTransportStats contains statistics for the NFS mount RPC requests and responses.
type Proc ¶
type Proc struct {
// The process ID.
PID int
// contains filtered or unexported fields
}
Proc provides information about a running process.
func (Proc) Executable ¶
Executable returns the absolute path of the executable command of a process.
func (Proc) FileDescriptorTargets ¶
FileDescriptorTargets returns the targets of all file descriptors of a process. If a file descriptor is not a symlink to a file (like a socket), that value will be the empty string.
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) MountStats ¶
MountStats retrieves statistics and configuration for mount points in a process's namespace.
func (Proc) NewLimits ¶
func (p Proc) NewLimits() (ProcLimits, error)
NewLimits returns the current soft limits of the process.
type ProcIO ¶
type ProcIO struct {
// Chars read.
RChar uint64
// Chars written.
WChar uint64
// Read syscalls.
SyscR uint64
// Write syscalls.
SyscW uint64
// Bytes read.
ReadBytes uint64
// Bytes written.
WriteBytes uint64
// Bytes written, but taking into account truncation. See
// Documentation/filesystems/proc.txt in the kernel sources for
// detailed explanation.
CancelledWriteBytes int64
}
ProcIO models the content of /proc/<pid>/io.
type ProcLimits ¶
type ProcLimits struct {
// CPU time limit in seconds.
CPUTime int
// Maximum size of files that the process may create.
FileSize int
// Maximum size of the process's data segment (initialized data,
// uninitialized data, and heap).
DataSize int
// Maximum size of the process stack in bytes.
StackSize int
// Maximum size of a core file.
CoreFileSize int
// Limit of the process's resident set in pages.
ResidentSet int
// Maximum number of processes that can be created for the real user ID of
// the calling process.
Processes int
// Value one greater than the maximum file descriptor number that can be
// opened by this process.
OpenFiles int
// Maximum number of bytes of memory that may be locked into RAM.
LockedMemory int
// Maximum size of the process's virtual memory address space in bytes.
AddressSpace int
// Limit on the combined number of flock(2) locks and fcntl(2) leases that
// this process may establish.
FileLocks int
// Limit of signals that may be queued for the real user ID of the calling
// process.
PendingSignals int
// Limit on the number of bytes that can be allocated for POSIX message
// queues for the real user ID of the calling process.
MsqqueueSize int
// Limit of the nice priority set using setpriority(2) or nice(2).
NicePriority int
// Limit of the real-time priority set using sched_setscheduler(2) or
// sched_setparam(2).
RealtimePriority int
// Limit (in microseconds) on the amount of CPU time that a process
// scheduled under a real-time scheduling policy may consume without making
// a blocking system call.
RealtimeTimeout int
}
ProcLimits represents the soft limits for each of the process's resource limits. For more information see getrlimit(2): http://man7.org/linux/man-pages/man2/getrlimit.2.html.
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.
