procfs

package
v2.1.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2015 License: Apache-2.0, Apache-2.0 Imports: 13 Imported by: 0

README

procfs

This procfs package provides functions to retrieve system, kernel and process metrics from the pseudo-filesystem proc.

WARNING: This package is a work in progress. Its API may still break in backwards-incompatible ways without warnings. Use it at your own risk.

GoDoc Build Status

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

View Source
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

func NewFS(mountPoint string) (FS, error)

NewFS returns a new FS mounted under the given mountPoint. It will error if the mount point can't be read.

func (FS) AllProcs

func (fs FS) AllProcs() (Procs, error)

AllProcs returns a list of all currently avaible processes.

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

func (fs FS) NewIPVSStats() (IPVSStats, error)

NewIPVSStats reads the IPVS statistics from the specified `proc` filesystem.

func (FS) NewProc

func (fs FS) NewProc(pid int) (Proc, error)

NewProc returns a process for the given pid.

func (FS) NewStat

func (fs FS) NewStat() (Stat, error)

NewStat returns an information about current kernel/system statistics.

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`.

func NewIPVSStats

func NewIPVSStats() (IPVSStats, error)

NewIPVSStats reads the IPVS statistics.

type Proc

type Proc struct {
	// The process ID.
	PID int
	// contains filtered or unexported fields
}

Proc provides information about a running process.

func NewProc

func NewProc(pid int) (Proc, error)

NewProc returns a process for the given pid under /proc.

func Self

func Self() (Proc, error)

Self returns a process for the current process.

func (Proc) CmdLine

func (p Proc) CmdLine() ([]string, error)

CmdLine returns the command line of a process.

func (Proc) Executable

func (p Proc) Executable() (string, error)

Executable returns the absolute path of the executable command of a process.

func (Proc) FileDescriptors

func (p Proc) FileDescriptors() ([]uintptr, error)

FileDescriptors returns the currently open file descriptors of a process.

func (Proc) FileDescriptorsLen

func (p Proc) FileDescriptorsLen() (int, error)

FileDescriptorsLen returns the number of currently open file descriptors of a process.

func (Proc) NewIO

func (p Proc) NewIO() (ProcIO, error)

NewIO creates a new ProcIO instance from a given Proc instance.

func (Proc) NewLimits

func (p Proc) NewLimits() (ProcLimits, error)

NewLimits returns the current soft limits of the process.

func (Proc) NewStat

func (p Proc) NewStat() (ProcStat, error)

NewStat returns the current status information 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 {
	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) CPUTime

func (s ProcStat) CPUTime() float64

CPUTime returns the total CPU user and system time in seconds.

func (ProcStat) ResidentMemory

func (s ProcStat) ResidentMemory() int

ResidentMemory returns the resident memory size in bytes.

func (ProcStat) StartTime

func (s ProcStat) StartTime() (float64, error)

StartTime returns the unix timestamp of the process in seconds.

func (ProcStat) VirtualMemory

func (s ProcStat) VirtualMemory() int

VirtualMemory returns the virtual memory size in bytes.

type Procs

type Procs []Proc

Procs represents a list of Proc structs.

func AllProcs

func AllProcs() (Procs, error)

AllProcs returns a list of all currently avaible processes under /proc.

func (Procs) Len

func (p Procs) Len() int

func (Procs) Less

func (p Procs) Less(i, j int) bool

func (Procs) Swap

func (p Procs) Swap(i, j int)

type Stat

type Stat struct {
	// Boot time in seconds since the Epoch.
	BootTime int64
}

Stat represents kernel/system statistics.

func NewStat

func NewStat() (Stat, error)

NewStat returns kernel/system statistics read from /proc/stat.

Jump to

Keyboard shortcuts

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