sysfs

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: Apache-2.0 Imports: 10 Imported by: 65

Documentation

Overview

Package sysfs provides functions to retrieve system and kernel metrics from the pseudo-filesystem sys.

Index

Constants

View Source
const DefaultMountPoint = fs.DefaultSysMountPoint

DefaultMountPoint is the common mount point of the sys filesystem.

Variables

This section is empty.

Functions

This section is empty.

Types

type CPU added in v0.0.5

type CPU string

CPU represents a path to a CPU located in /sys/devices/system/cpu/cpu[0-9]*

func (CPU) Number added in v0.0.5

func (c CPU) Number() string

Number returns the ID number of the given CPU

func (CPU) ThermalThrottle added in v0.0.5

func (c CPU) ThermalThrottle() (*CPUThermalThrottle, error)

ThermalThrottle gets the cpu throttle count information for a single CPU from /sys/devices/system/cpu/cpuN/thermal_throttle

func (CPU) Topology added in v0.0.5

func (c CPU) Topology() (*CPUTopology, error)

Topology gets the topology information for a single CPU from /sys/devices/system/cpu/cpuN/topology

type CPUThermalThrottle added in v0.0.5

type CPUThermalThrottle struct {
	CoreThrottleCount    uint64
	PackageThrottleCount uint64
}

CPUThermalThrottle contains data from /sys/devices/system/cpu/cpu[0-9]*/thermal_throttle

type CPUTopology added in v0.0.5

type CPUTopology struct {
	CoreID             string
	CoreSiblingsList   string
	PhysicalPackageID  string
	ThreadSiblingsList string
}

CPUTopology contains data located in /sys/devices/system/cpu/cpu[0-9]*/topology

type ClassCoolingDeviceStats added in v0.0.4

type ClassCoolingDeviceStats struct {
	Name     string // The name of the cooling device.
	Type     string // Type of the cooling device(processor/fan/...)
	MaxState int64  // Maximum cooling state of the cooling device
	CurState int64  // Current cooling state of the cooling device
}

ClassCoolingDeviceStats contains info from files in /sys/class/thermal/cooling_device[0-9]* for a single device. https://www.kernel.org/doc/Documentation/thermal/sysfs-api.txt

type ClassThermalZoneStats

type ClassThermalZoneStats struct {
	Name    string  // The name of the zone from the directory structure.
	Type    string  // The type of thermal zone.
	Temp    uint64  // Temperature in millidegree Celsius.
	Policy  string  // One of the various thermal governors used for a particular zone.
	Mode    *bool   // Optional: One of the predefined values in [enabled, disabled].
	Passive *uint64 // Optional: millidegrees Celsius. (0 for disabled, > 1000 for enabled+value)
}

ClassThermalZoneStats contains info from files in /sys/class/thermal/thermal_zone<zone> for a single <zone>. https://www.kernel.org/doc/Documentation/thermal/sysfs-api.txt

type ClockSource

type ClockSource struct {
	Name      string
	Available []string
	Current   string
}

ClockSource contains metrics related to the clock source

type FS

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

FS represents the pseudo-filesystem sys, which provides an interface to kernel data structures.

func NewDefaultFS added in v0.0.2

func NewDefaultFS() (FS, error)

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

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) CPUVulnerabilities added in v0.0.4

func (fs FS) CPUVulnerabilities() ([]Vulnerability, error)

CPUVulnerabilities retrieves a map of vulnerability names to their mitigations.

func (FS) CPUs added in v0.0.5

func (fs FS) CPUs() ([]CPU, error)

CPUs returns a slice of all CPUs in /sys/devices/system/cpu

func (FS) ClassCoolingDeviceStats added in v0.0.4

func (fs FS) ClassCoolingDeviceStats() ([]ClassCoolingDeviceStats, error)

func (FS) ClassThermalZoneStats added in v0.0.2

func (fs FS) ClassThermalZoneStats() ([]ClassThermalZoneStats, error)

ClassThermalZoneStats returns Thermal Zone metrics for all zones.

func (FS) ClockSources

func (fs FS) ClockSources() ([]ClockSource, error)

ClockSources returns clocksource information including current and available clocksources read from '/sys/devices/system/clocksource'

func (FS) InfiniBandClass added in v0.0.3

func (fs FS) InfiniBandClass() (InfiniBandClass, error)

InfiniBandClass returns info for all InfiniBand devices read from /sys/class/infiniband.

func (FS) NetClass added in v0.0.2

func (fs FS) NetClass() (NetClass, error)

NetClass returns info for all net interfaces (iface) read from /sys/class/net/<iface>.

func (FS) NetClassDevices

func (fs FS) NetClassDevices() ([]string, error)

NetClassDevices scans /sys/class/net for devices and returns them as a list of names.

func (FS) PowerSupplyClass added in v0.0.2

func (fs FS) PowerSupplyClass() (PowerSupplyClass, error)

PowerSupplyClass returns info for all power supplies read from /sys/class/power_supply.

func (FS) SystemCpufreq added in v0.0.2

func (fs FS) SystemCpufreq() ([]SystemCPUCpufreqStats, error)

SystemCpufreq returns CPU frequency metrics for all CPUs.

type InfiniBandClass added in v0.0.3

type InfiniBandClass map[string]InfiniBandDevice

InfiniBandClass is a collection of every InfiniBand device in /sys/class/infiniband.

The map keys are the names of the InfiniBand devices.

type InfiniBandCounters added in v0.0.3

type InfiniBandCounters struct {
	LegacyPortMulticastRcvPackets  *uint64 // counters_ext/port_multicast_rcv_packets
	LegacyPortMulticastXmitPackets *uint64 // counters_ext/port_multicast_xmit_packets
	LegacyPortRcvData64            *uint64 // counters_ext/port_rcv_data_64
	LegacyPortRcvPackets64         *uint64 // counters_ext/port_rcv_packets_64
	LegacyPortUnicastRcvPackets    *uint64 // counters_ext/port_unicast_rcv_packets
	LegacyPortUnicastXmitPackets   *uint64 // counters_ext/port_unicast_xmit_packets
	LegacyPortXmitData64           *uint64 // counters_ext/port_xmit_data_64
	LegacyPortXmitPackets64        *uint64 // counters_ext/port_xmit_packets_64

	LinkDowned               *uint64 // counters/link_downed
	LinkErrorRecovery        *uint64 // counters/link_error_recovery
	MulticastRcvPackets      *uint64 // counters/multicast_rcv_packets
	MulticastXmitPackets     *uint64 // counters/multicast_xmit_packets
	PortRcvConstraintErrors  *uint64 // counters/port_rcv_constraint_errors
	PortRcvData              *uint64 // counters/port_rcv_data
	PortRcvDiscards          *uint64 // counters/port_rcv_discards
	PortRcvErrors            *uint64 // counters/port_rcv_errors
	PortRcvPackets           *uint64 // counters/port_rcv_packets
	PortXmitConstraintErrors *uint64 // counters/port_xmit_constraint_errors
	PortXmitData             *uint64 // counters/port_xmit_data
	PortXmitDiscards         *uint64 // counters/port_xmit_discards
	PortXmitPackets          *uint64 // counters/port_xmit_packets
	PortXmitWait             *uint64 // counters/port_xmit_wait
	UnicastRcvPackets        *uint64 // counters/unicast_rcv_packets
	UnicastXmitPackets       *uint64 // counters/unicast_xmit_packets
}

InfiniBandCounters contains counter values from files in /sys/class/infiniband/<Name>/ports/<Port>/counters or /sys/class/infiniband/<Name>/ports/<Port>/counters_ext for a single port of one InfiniBand device.

type InfiniBandDevice added in v0.0.3

type InfiniBandDevice struct {
	Name            string
	BoardID         string // /sys/class/infiniband/<Name>/board_id
	FirmwareVersion string // /sys/class/infiniband/<Name>/fw_ver
	HCAType         string // /sys/class/infiniband/<Name>/hca_type
	Ports           map[uint]InfiniBandPort
}

InfiniBandDevice contains info from files in /sys/class/infiniband for a single InfiniBand device.

type InfiniBandPort added in v0.0.3

type InfiniBandPort struct {
	Name        string
	Port        uint
	State       string // String representation from /sys/class/infiniband/<Name>/ports/<Port>/state
	StateID     uint   // ID from /sys/class/infiniband/<Name>/ports/<Port>/state
	PhysState   string // String representation from /sys/class/infiniband/<Name>/ports/<Port>/phys_state
	PhysStateID uint   // String representation from /sys/class/infiniband/<Name>/ports/<Port>/phys_state
	Rate        uint64 // in bytes/second from /sys/class/infiniband/<Name>/ports/<Port>/rate
	Counters    InfiniBandCounters
}

InfiniBandPort contains info from files in /sys/class/infiniband/<Name>/ports/<Port> for a single port of one InfiniBand device.

type NetClass

type NetClass map[string]NetClassIface

NetClass is collection of info for every interface (iface) in /sys/class/net. The map keys are interface (iface) names.

type NetClassIface

type NetClassIface struct {
	Name             string // Interface name
	AddrAssignType   *int64 // /sys/class/net/<iface>/addr_assign_type
	AddrLen          *int64 // /sys/class/net/<iface>/addr_len
	Address          string // /sys/class/net/<iface>/address
	Broadcast        string // /sys/class/net/<iface>/broadcast
	Carrier          *int64 // /sys/class/net/<iface>/carrier
	CarrierChanges   *int64 // /sys/class/net/<iface>/carrier_changes
	CarrierUpCount   *int64 // /sys/class/net/<iface>/carrier_up_count
	CarrierDownCount *int64 // /sys/class/net/<iface>/carrier_down_count
	DevID            *int64 // /sys/class/net/<iface>/dev_id
	Dormant          *int64 // /sys/class/net/<iface>/dormant
	Duplex           string // /sys/class/net/<iface>/duplex
	Flags            *int64 // /sys/class/net/<iface>/flags
	IfAlias          string // /sys/class/net/<iface>/ifalias
	IfIndex          *int64 // /sys/class/net/<iface>/ifindex
	IfLink           *int64 // /sys/class/net/<iface>/iflink
	LinkMode         *int64 // /sys/class/net/<iface>/link_mode
	MTU              *int64 // /sys/class/net/<iface>/mtu
	NameAssignType   *int64 // /sys/class/net/<iface>/name_assign_type
	NetDevGroup      *int64 // /sys/class/net/<iface>/netdev_group
	OperState        string // /sys/class/net/<iface>/operstate
	PhysPortID       string // /sys/class/net/<iface>/phys_port_id
	PhysPortName     string // /sys/class/net/<iface>/phys_port_name
	PhysSwitchID     string // /sys/class/net/<iface>/phys_switch_id
	Speed            *int64 // /sys/class/net/<iface>/speed
	TxQueueLen       *int64 // /sys/class/net/<iface>/tx_queue_len
	Type             *int64 // /sys/class/net/<iface>/type
}

NetClassIface contains info from files in /sys/class/net/<iface> for single interface (iface).

type PowerSupply

type PowerSupply struct {
	Name                     string // Power Supply Name
	Authentic                *int64 // /sys/class/power_supply/<Name>/authentic
	Calibrate                *int64 // /sys/class/power_supply/<Name>/calibrate
	Capacity                 *int64 // /sys/class/power_supply/<Name>/capacity
	CapacityAlertMax         *int64 // /sys/class/power_supply/<Name>/capacity_alert_max
	CapacityAlertMin         *int64 // /sys/class/power_supply/<Name>/capacity_alert_min
	CapacityLevel            string // /sys/class/power_supply/<Name>/capacity_level
	ChargeAvg                *int64 // /sys/class/power_supply/<Name>/charge_avg
	ChargeControlLimit       *int64 // /sys/class/power_supply/<Name>/charge_control_limit
	ChargeControlLimitMax    *int64 // /sys/class/power_supply/<Name>/charge_control_limit_max
	ChargeCounter            *int64 // /sys/class/power_supply/<Name>/charge_counter
	ChargeEmpty              *int64 // /sys/class/power_supply/<Name>/charge_empty
	ChargeEmptyDesign        *int64 // /sys/class/power_supply/<Name>/charge_empty_design
	ChargeFull               *int64 // /sys/class/power_supply/<Name>/charge_full
	ChargeFullDesign         *int64 // /sys/class/power_supply/<Name>/charge_full_design
	ChargeNow                *int64 // /sys/class/power_supply/<Name>/charge_now
	ChargeTermCurrent        *int64 // /sys/class/power_supply/<Name>/charge_term_current
	ChargeType               string // /sys/class/power_supply/<Name>/charge_type
	ConstantChargeCurrent    *int64 // /sys/class/power_supply/<Name>/constant_charge_current
	ConstantChargeCurrentMax *int64 // /sys/class/power_supply/<Name>/constant_charge_current_max
	ConstantChargeVoltage    *int64 // /sys/class/power_supply/<Name>/constant_charge_voltage
	ConstantChargeVoltageMax *int64 // /sys/class/power_supply/<Name>/constant_charge_voltage_max
	CurrentAvg               *int64 // /sys/class/power_supply/<Name>/current_avg
	CurrentBoot              *int64 // /sys/class/power_supply/<Name>/current_boot
	CurrentMax               *int64 // /sys/class/power_supply/<Name>/current_max
	CurrentNow               *int64 // /sys/class/power_supply/<Name>/current_now
	CycleCount               *int64 // /sys/class/power_supply/<Name>/cycle_count
	EnergyAvg                *int64 // /sys/class/power_supply/<Name>/energy_avg
	EnergyEmpty              *int64 // /sys/class/power_supply/<Name>/energy_empty
	EnergyEmptyDesign        *int64 // /sys/class/power_supply/<Name>/energy_empty_design
	EnergyFull               *int64 // /sys/class/power_supply/<Name>/energy_full
	EnergyFullDesign         *int64 // /sys/class/power_supply/<Name>/energy_full_design
	EnergyNow                *int64 // /sys/class/power_supply/<Name>/energy_now
	Health                   string // /sys/class/power_supply/<Name>/health
	InputCurrentLimit        *int64 // /sys/class/power_supply/<Name>/input_current_limit
	Manufacturer             string // /sys/class/power_supply/<Name>/manufacturer
	ModelName                string // /sys/class/power_supply/<Name>/model_name
	Online                   *int64 // /sys/class/power_supply/<Name>/online
	PowerAvg                 *int64 // /sys/class/power_supply/<Name>/power_avg
	PowerNow                 *int64 // /sys/class/power_supply/<Name>/power_now
	PrechargeCurrent         *int64 // /sys/class/power_supply/<Name>/precharge_current
	Present                  *int64 // /sys/class/power_supply/<Name>/present
	Scope                    string // /sys/class/power_supply/<Name>/scope
	SerialNumber             string // /sys/class/power_supply/<Name>/serial_number
	Status                   string // /sys/class/power_supply/<Name>/status
	Technology               string // /sys/class/power_supply/<Name>/technology
	Temp                     *int64 // /sys/class/power_supply/<Name>/temp
	TempAlertMax             *int64 // /sys/class/power_supply/<Name>/temp_alert_max
	TempAlertMin             *int64 // /sys/class/power_supply/<Name>/temp_alert_min
	TempAmbient              *int64 // /sys/class/power_supply/<Name>/temp_ambient
	TempAmbientMax           *int64 // /sys/class/power_supply/<Name>/temp_ambient_max
	TempAmbientMin           *int64 // /sys/class/power_supply/<Name>/temp_ambient_min
	TempMax                  *int64 // /sys/class/power_supply/<Name>/temp_max
	TempMin                  *int64 // /sys/class/power_supply/<Name>/temp_min
	TimeToEmptyAvg           *int64 // /sys/class/power_supply/<Name>/time_to_empty_avg
	TimeToEmptyNow           *int64 // /sys/class/power_supply/<Name>/time_to_empty_now
	TimeToFullAvg            *int64 // /sys/class/power_supply/<Name>/time_to_full_avg
	TimeToFullNow            *int64 // /sys/class/power_supply/<Name>/time_to_full_now
	Type                     string // /sys/class/power_supply/<Name>/type
	UsbType                  string // /sys/class/power_supply/<Name>/usb_type
	VoltageAvg               *int64 // /sys/class/power_supply/<Name>/voltage_avg
	VoltageBoot              *int64 // /sys/class/power_supply/<Name>/voltage_boot
	VoltageMax               *int64 // /sys/class/power_supply/<Name>/voltage_max
	VoltageMaxDesign         *int64 // /sys/class/power_supply/<Name>/voltage_max_design
	VoltageMin               *int64 // /sys/class/power_supply/<Name>/voltage_min
	VoltageMinDesign         *int64 // /sys/class/power_supply/<Name>/voltage_min_design
	VoltageNow               *int64 // /sys/class/power_supply/<Name>/voltage_now
	VoltageOCV               *int64 // /sys/class/power_supply/<Name>/voltage_ocv
}

PowerSupply contains info from files in /sys/class/power_supply for a single power supply.

type PowerSupplyClass

type PowerSupplyClass map[string]PowerSupply

PowerSupplyClass is a collection of every power supply in /sys/class/power_supply.

The map keys are the names of the power supplies.

type RaplZone added in v0.0.6

type RaplZone struct {
	Name           string // name of RAPL zone from file "name"
	Index          int    // index (different value for duplicate names)
	Path           string // filesystem path of RaplZone
	MaxMicrojoules uint64 // max RAPL microjoule value
}

RaplZone stores the information for one RAPL power zone

func GetRaplZones added in v0.0.6

func GetRaplZones(fs FS) ([]RaplZone, error)

GetRaplZones returns a slice of RaplZones When RAPL files are not present, returns nil with error https://www.kernel.org/doc/Documentation/power/powercap/powercap.txt

func (RaplZone) GetEnergyMicrojoules added in v0.0.6

func (rz RaplZone) GetEnergyMicrojoules() (uint64, error)

GetEnergyMicrojoules returns the current microjoule value from the zone energy counter https://www.kernel.org/doc/Documentation/power/powercap/powercap.txt

type SystemCPUCpufreqStats

type SystemCPUCpufreqStats struct {
	Name                     string
	CpuinfoCurrentFrequency  *uint64
	CpuinfoMinimumFrequency  *uint64
	CpuinfoMaximumFrequency  *uint64
	CpuinfoTransitionLatency *uint64
	ScalingCurrentFrequency  *uint64
	ScalingMinimumFrequency  *uint64
	ScalingMaximumFrequency  *uint64
	AvailableGovernors       string
	Driver                   string
	Governor                 string
	RelatedCpus              string
	SetSpeed                 string
}

SystemCPUCpufreqStats contains stats from devices/system/cpu/cpu[0-9]*/cpufreq/...

type Vulnerability added in v0.0.4

type Vulnerability struct {
	CodeName   string
	State      string
	Mitigation string
}

Vulnerability represents a single vulnerability extracted from /sys/devices/system/cpu/vulnerabilities/

Jump to

Keyboard shortcuts

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