proc

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package proc provides utilities for reading process statistics from /proc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBootTime

func GetBootTime() (time.Time, error)

GetBootTime returns the system boot time.

func GetProcessStartTime

func GetProcessStartTime(pid int) (time.Time, error)

GetProcessStartTime returns when a process started based on /proc/[pid]/stat.

func ReadAllStats

func ReadAllStats(pids []int, tracker *CPUTracker) (map[int]*Stats, error)

ReadAllStats reads statistics for multiple PIDs.

Types

type CPUTracker

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

CPUTracker tracks CPU usage across multiple samples.

func NewCPUTracker

func NewCPUTracker() *CPUTracker

NewCPUTracker creates a new CPU usage tracker.

func (*CPUTracker) CleanupStale

func (t *CPUTracker) CleanupStale(activePIDs []int)

CleanupStale removes snapshots for PIDs no longer in the provided list.

type Stats

type Stats struct {
	PID        int     `json:"pid"`
	CPUPercent float64 `json:"cpu_percent"` // CPU usage as percentage (0-100+)
	MemoryMB   int64   `json:"memory_mb"`   // Resident memory in megabytes
	MemoryRSS  int64   `json:"memory_rss"`  // Resident set size in bytes
	VirtualMB  int64   `json:"virtual_mb"`  // Virtual memory in megabytes
	State      string  `json:"state"`       // Process state (R, S, D, Z, T, etc.)
	Threads    int     `json:"threads"`     // Number of threads
	StartTime  int64   `json:"start_time"`  // Process start time in jiffies since boot
}

Stats contains process statistics read from /proc.

func ReadStats

func ReadStats(pid int, tracker *CPUTracker) (*Stats, error)

ReadStats reads process statistics for a single PID. If tracker is non-nil, it's used to calculate CPU percentage between calls.

Jump to

Keyboard shortcuts

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