procuse

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Copyright (c) 2025 EterLine (Andrew) This file is part of fstmon. Licensed under the MIT License. See the LICENSE file for details.

Copyright (c) 2025 EterLine (Andrew) This file is part of fstmon. Licensed under the MIT License. See the LICENSE file for details.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFieldCountMismatch - field count mismatch in a row
	ErrFieldCountMismatch = NewProcError("field count mismatch")

	// ErrLineCountMismatch - field count mismatch in a line
	ErrLineCountMismatch = NewProcError("line count mismatch")

	// ErrEmptyRow - row unexpectedly empty
	ErrEmptyRow = NewProcError("empty row")

	// ErrInvalidNumber - failed to parse numeric field
	ErrInvalidNumber = NewProcError("invalid number")

	// ErrFileRead - failed to read /proc file
	ErrFileRead = NewProcError("failed to read /proc file")

	// ErrInvalidField - invalid row or line field format
	ErrInvalidField = func(p []byte) ProcUseError { return NewProcError(fmt.Sprintf("invalid field format - field: '%s'", p)) }
)

Functions

This section is empty.

Types

type LoadAvg

type LoadAvg struct {
	Load1  float64 `json:"load_1"`
	Load5  float64 `json:"load_5"`
	Load15 float64 `json:"load_15"`

	Running      int32 `json:"uptime"`
	TotalThreads int32 `json:"total_threads"`
	LastPID      int32 `json:"last_pid"`
}

LoadAvg - average load

┌───────────────┬──────────────────────────────────────────────────────────────────────────┐
│ Field         │ Description                                                              │
├───────────────┼──────────────────────────────────────────────────────────────────────────┤
│ Load1         │ The system load average over the last 1 minute.                          │
│ Load5         │ The system load average over the last 5 minutes.                         │
│ Load15        │ The system load average over the last 15 minutes.                        │
│ Running       │ Number of currently running processes and total number of processes, e.g.│
│ TotalThreads  │ "2/150" means 2 running out of 150 total processes.                      │
│ LastPID       │ The process ID of the last process created.                              │
└───────────────┴──────────────────────────────────────────────────────────────────────────┘

func ReadLoadAvg

func ReadLoadAvg() (LoadAvg, error)

type NetArp

type NetArp struct {
	IPAddr    netip.Addr       `json:"ip_addr"`
	HWType    uint16           `json:"hw_type"`
	Flags     uint16           `json:"flags"`
	HWAddress net.HardwareAddr `json:"hw_address"`
	Mask      netip.Prefix     `json:"mask"`
	Device    string           `json:"device"`
}

NetArpEntry – ARP table entry parsed from /proc/net/arp

┌────────────┬───────────────────────────────────────────────────────────────────────────────┐
│ Field      │ Description                                                                   │
├────────────┼───────────────────────────────────────────────────────────────────────────────┤
│ IPAddr     │ IPv4 address of the ARP entry (netip.Addr for safe and fast address handling) │
│ HWType     │ Hardware type (usually 1 – Ethernet)                                          │
│ Flags      │ Entry flags (0x2 indicates a complete/valid ARP entry)                        │
│ HWAddress  │ MAC address associated with the IP (net.HardwareAddr)                         │
│ Mask       │ Subnet mask (usually "*", mapped to an empty netip.Prefix)                    │
│ Device     │ Network interface name (e.g., "eth0", "ens18")                                │
└────────────┴───────────────────────────────────────────────────────────────────────────────┘

func ReadNetArp

func ReadNetArp() ([]NetArp, error)

type NetDev

type NetDev struct {
	Interface string   `json:"interface"`
	RX        NetDevRX `json:"rx"`
	TX        NetDevTX `json:"tx"`
}

func ReadNetDev

func ReadNetDev() ([]NetDev, error)

type NetDevRX

type NetDevRX struct {
	Bytes      uint64 `json:"bytes"`
	Packets    uint64 `json:"packets"`
	Errs       uint64 `json:"errs"`
	Drop       uint64 `json:"drop"`
	Fifo       uint64 `json:"fifo"`
	Frame      uint64 `json:"frame"`
	Compressed uint64 `json:"compressed"`
	Multicast  uint64 `json:"multicast"`
}

NetDevRX – Receive segment

┌────────────┬────────────────────────────────────────────────────────────┐
│ Field      │ Description                                                │
├────────────┼────────────────────────────────────────────────────────────┤
│ Bytes      │ Total number of bytes received                             │
│ Packets    │ Total number of packets received                           │
│ Errs       │ Number of receive errors                                   │
│ Drop       │ Number of received packets dropped                         │
│ Fifo       │ Number of FIFO buffer errors on receive                    │
│ Frame      │ Number of frame alignment errors                           │
│ Compressed │ Number of compressed packets received (if any)             │
│ Multicast  │ Number of multicast packets received                       │
└────────────┴────────────────────────────────────────────────────────────┘

type NetDevTX

type NetDevTX struct {
	Bytes      uint64 `json:"bytes"`
	Packets    uint64 `json:"packets"`
	Errs       uint64 `json:"errs"`
	Drop       uint64 `json:"drop"`
	Fifo       uint64 `json:"fifo"`
	Colls      uint64 `json:"colls"`
	Carrier    uint64 `json:"carrier"`
	Compressed uint64 `json:"compressed"`
}

NetDevTX – Transmit segment

┌────────────┬────────────────────────────────────────────────────────────┐
│ Field      │ Description                                                │
├────────────┼────────────────────────────────────────────────────────────┤
│ Bytes      │ Total number of bytes transmitted                          │
│ Packets    │ Total number of packets transmitted                        │
│ Errs       │ Number of transmission errors                              │
│ Drop       │ Number of transmitted packets dropped                      │
│ Fifo       │ Number of FIFO buffer errors on transmit                   │
│ Colls      │ Number of collisions detected during transmission          │
│ Carrier    │ Number of carrier sense errors                             │
│ Compressed │ Number of compressed packets transmitted (if any)          │
└────────────┴────────────────────────────────────────────────────────────┘

type NetProtocol

type NetProtocol struct {
	Protocol string           `json:"protocol"`
	Size     uint             `json:"size"`
	Sockets  int              `json:"sockets"`
	Memory   int              `json:"memory"`
	Press    string           `json:"press"`
	MaxHdr   uint             `json:"maxhdr"`
	Slab     bool             `json:"slab"`
	Module   string           `json:"module"`
	Flags    NetProtocolFlags `json:"flags"`
}

NetProtocolEntry – one line in /proc/net/protocols

┌─────────────┬───────────────────────────────────────────────┐
│ Field       │ Description                                   │
├─────────────┼───────────────────────────────────────────────┤
│ Protocol    │ Protocol name (string)                        │
│ Size        │ Size of protocol struct (uint)                │
│ Sockets     │ Number of active sockets (int)               │
│ Memory      │ Memory usage (int)                            │
│ Press       │ Memory pressure (string, e.g., "NI", "no")  │
│ MaxHdr      │ Maximum header size (uint)                    │
│ Slab        │ Slab usage ("yes"/"no")                       │
│ Module      │ Kernel module name handling the protocol      │
│ Flags       │ Array of booleans for cl, co, di, ac...     │
└─────────────┴───────────────────────────────────────────────┘

func ReadNetProtocols

func ReadNetProtocols() ([]NetProtocol, error)

type NetProtocolFlags

type NetProtocolFlags struct {
	CL bool `json:"cl"`
	CO bool `json:"co"`
	DI bool `json:"di"`
	AC bool `json:"ac"`
	IO bool `json:"io"`
	IN bool `json:"in"`
	DE bool `json:"de"`
	SH bool `json:"sh"`
	SS bool `json:"ss"`
	GS bool `json:"gs"`
	SE bool `json:"se"`
	RE bool `json:"re"`
	BI bool `json:"bi"`
	BR bool `json:"br"`
	HA bool `json:"ha"`
	UH bool `json:"uh"`
	GP bool `json:"gp"`
	EM bool `json:"em"`
}

NetProtocolFlags – boolean flags of a protocol

type ProcUseError

type ProcUseError struct {
	// contains filtered or unexported fields
}

ProcUseError - an error originating from ProcFS usage

func NewProcError

func NewProcError(msg string) ProcUseError

NewProcError - creates a new ProcUseError with a message

func (ProcUseError) Error

func (p ProcUseError) Error() string

Error - returns the error string

func (ProcUseError) Unwrap

func (p ProcUseError) Unwrap() error

Unwrap - returns the wrapped error

func (ProcUseError) Wrap

func (p ProcUseError) Wrap(err error) ProcUseError

Wrap - wraps an existing error with ProcUseError context

type Process

type Process struct {
	PID         int32   `json:"pid"`
	PPID        int32   `json:"ppid"`
	Cpu         float64 `json:"cpu"`
	Memory      float64 `json:"mem"`
	User        string  `json:"user"`
	Command     string  `json:"command"`
	Class       string  `json:"class"`
	State       string  `json:"state"`
	FullCommand string  `json:"full_command"`
}

Process holds detailed information about proc

┌─────────────┬────────────────────────────────────────────────────────┐
│ Value       │ Description                                            │
├─────────────┼────────────────────────────────────────────────────────┤
│ PID         │ Process ID                                             │
│ PPID        │ Parent process ID                                      │
│ Cpu         │ Cpu usage                                              │
│ Memory      │ Memory usage                                           │
│ User        │ Executed by username                                   │
│ Command     │ Command name                                           │
│ Class       │                                                        │
│ State       │ Indicating process state                               │
│ FullCommand │ Full exec command                                      │
└─────────────┴────────────────────────────────────────────────────────┘

type SelfStatus

type SelfStatus struct {
	CapAmbMask                uint64
	CapBndMask                uint64
	CapEffMask                uint64
	CapInhMask                uint64
	CapPrmMask                uint64
	CoreDumping               uint32
	CpusAllowedMaskVec        []uint8
	CpusAllowedList           string
	FDSize                    uint32
	Gid                       []uint16
	Groups                    []uint16
	HugetlbPages              uint64
	Kthread                   uint64
	MemsAllowed               []string
	MemsAllowedList           string
	NSpgid                    int64
	NSpid                     int64
	NSsid                     int64
	NStgid                    int64
	Name                      string
	Ngid                      int64
	NoNewPrivs                int64
	PPid                      int32
	Pid                       int32
	RssAnon                   uint64
	RssFile                   uint64
	RssShmem                  uint64
	Seccomp                   uint64
	SeccompFilters            uint64
	ShdPnd                    uint64
	SigBlk                    uint64
	SigCgt                    uint64
	SigIgn                    uint64
	SigPnd                    uint64
	SigQ                      string
	SpeculationIndirectBranch string
	SpeculationStoreBypass    string
	State                     string
	THPEnabled                uint64
	Tgid                      uint64
	Threads                   uint64
	TracerPid                 int32
	Uid                       []uint16
	VmData                    uint64
	VmExe                     uint64
	VmHWM                     uint64
	VmLck                     uint64
	VmLib                     uint64
	VmPTE                     uint64
	VmPeak                    uint64
	VmPin                     uint64
	VmRSS                     uint64
	VmSize                    uint64
	VmStk                     uint64
	VmSwap                    uint64
	NonvoluntaryCtxtSwitches  uint64
	UntagMask                 uint64
	VoluntaryCtxtSwitches     uint64
	X86ThreadFeatures         []string
	X86ThreadFeaturesLocked   []string
}

SelfStatus holds detailed information about this program process

┌─────────────────────────────┬───────────────────────────────────────────────────────────────┐
│ Field                       │ Description                                                   │
├─────────────────────────────┼───────────────────────────────────────────────────────────────┤
│ CapAmbMask                  │ Ambient capabilities mask (bitmask of permitted capabilities) │
│ CapBndMask                  │ Capability bounding set mask (limits capabilities for thread) │
│ CapEffMask                  │ Effective capabilities mask (currently effective capabilities)│
│ CapInhMask                  │ Inheritable capabilities mask (inheritable by child processes)│
│ CapPrmMask                  │ Permitted capabilities mask                                   │
│ CoreDumping                 │ Core dumping flag (1 if core dump allowed, 0 otherwise)       │
│ CpusAllowedMaskVec          │ CPUs allowed mask (bitmask vector representing allowed CPUs)  │
│ CpusAllowedList             │ CPUs allowed list (string listing allowed CPUs)               │
│ FDSize                      │ File descriptor limit (max open files for process)            │
│ Gid                         │ Real, effective, saved set, and filesystem group IDs (list)   │
│ Groups                      │ Supplementary group IDs (list)                                │
│ HugetlbPages                │ Number of huge pages used                                     │
│ Kthread                     │ Kernel thread flag (1 if kernel thread, else 0)               │
│ MemsAllowed                 │ Allowed NUMA memory nodes (list of strings)                   │
│ MemsAllowedList             │ Allowed memory nodes (string list)                            │
│ NSpgid                      │ PID in PID namespace (process group ID)                       │
│ NSpid                       │ PID in PID namespace (process ID)                             │
│ NSsid                       │ Session ID in namespace                                       │
│ NStgid                      │ Thread group ID in namespace                                  │
│ Name                        │ Command name (process name)                                   │
│ Ngid                        │ Thread group ID (kernel thread group ID)                      │
│ NoNewPrivs                  │ No new privileges flag (1 if set, else 0)                     │
│ PPid                        │ Parent process ID                                             │
│ Pid                         │ Process ID                                                    │
│ RssAnon                     │ Anonymous RSS (resident set size)                             │
│ RssFile                     │ File-backed RSS                                               │
│ RssShmem                    │ Shared memory RSS                                             │
│ Seccomp                     │ Seccomp mode (0=no seccomp, 1=strict, 2=filter)               │
│ SeccompFilters              │ Number of seccomp filters applied                             │
│ ShdPnd                      │ Number of pages pending writeback                             │
│ SigBlk                      │ Signal mask of blocked signals (bitmask)                      │
│ SigCgt                      │ Signal mask of caught signals (bitmask)                       │
│ SigIgn                      │ Signal mask of ignored signals (bitmask)                      │
│ SigPnd                      │ Signal mask of pending signals (bitmask)                      │
│ SigQ                        │ Queue of signals pending delivery (string)                    │
│ SpeculationIndirectBranch   │ Status of speculation indirect branch mitigation (string)     │
│ SpeculationStoreBypass      │ Status of speculation store bypass mitigation (string)        │
│ State                       │ Process state (e.g. R=running, S=sleeping)                    │
│ THPEnabled                  │ Transparent Huge Pages enabled (1=yes, 0=no)                  │
│ Tgid                        │ Thread group ID (main thread’s PID)                           │
│ Threads                     │ Number of threads in thread group                             │
│ TracerPid                   │ PID of process tracing this process (0 if none)               │
│ Uid                         │ Real, effective, saved set, and filesystem user IDs (list)    │
│ VmData                      │ Size of data segment (in kB)                                  │
│ VmExe                       │ Size of text segment (in kB)                                  │
│ VmHWM                       │ Peak resident set size ("high water mark") in kB              │
│ VmLck                       │ Locked memory size (in kB)                                    │
│ VmLib                       │ Shared library code size (in kB)                              │
│ VmPTE                       │ Page table entries size (in kB)                               │
│ VmPeak                      │ Peak virtual memory size (in kB)                              │
│ VmPin                       │ Pinned memory size (in kB)                                    │
│ VmRSS                       │ Resident Set Size (in kB)                                     │
│ VmSize                      │ Virtual memory size (in kB)                                   │
│ VmStk                       │ Stack size (in kB)                                            │
│ VmSwap                      │ Swapped-out virtual memory size (in kB)                       │
│ NonvoluntaryCtxtSwitches    │ Number of forced context switches                             │
│ UntagMask                   │ Untag mask (architecture-specific, related to hardware tags)  │
│ VoluntaryCtxtSwitches       │ Number of voluntary context switches                          │
│ X86ThreadFeatures           │ List of CPU thread features enabled (strings)                 │
│ X86ThreadFeaturesLocked     │ List of locked CPU thread features (strings)                  │
└─────────────────────────────┴───────────────────────────────────────────────────────────────┘

type Uptime

type Uptime struct {
	Uptime   time.Duration `json:"uptime"`
	IdleTime time.Duration `json:"idle_time"`
}

Uptime - host running time

┌─────────────┬───────────────────────────────────────────────────────────────────────┐
│ Field       │ Description                                                           │
├─────────────┼───────────────────────────────────────────────────────────────────────┤
│ Uptime      │ The total number of seconds the system has been running since boot.   │
│ IdleTime    │ The total number of seconds all CPUs have spent idle since boot.      │
└─────────────┴───────────────────────────────────────────────────────────────────────┘

func ReadUptime

func ReadUptime() (Uptime, error)

type VmStat

type VmStat map[string]uint64

VmStat – representation of Linux /proc/vmstat metrics

┌──────────────┬───────────────────────────────────────────────────────────────┐
│ Key          │ Description                                                   │
├──────────────┼───────────────────────────────────────────────────────────────┤
│ string       │ Metric name as found in /proc/vmstat (e.g., "nr_free_pages")  │
│ uint64       │ Metric value corresponding to the key                         │
└──────────────┴───────────────────────────────────────────────────────────────┘

Each entry in the VmStat map corresponds to one line in the /proc/vmstat file:

name value

For example:

nr_free_pages 437524
nr_zone_active_anon 247064

- Keys are the metric names. - Values are parsed as uint64. - This map provides fast access to any vmstat metric by name.

func ReadVmStat

func ReadVmStat() (VmStat, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL