os

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package os collects operating system configuration data.

This collector gathers detailed OS-level configuration that affects GPU performance and Kubernetes operation. It captures kernel parameters, loaded modules, GRUB boot settings, and OS release information.

Collected Data

The collector returns a measurement with 4 subtypes:

1. grub - Boot loader configuration:

  • intel_iommu, amd_iommu: IOMMU settings for device passthrough
  • iommu: IOMMU mode (pt, off, etc.)
  • hugepages: Huge pages configuration
  • numa_balancing: NUMA balancing settings
  • security settings (selinux, apparmor)

2. sysctl - Kernel runtime parameters:

  • All parameters from /proc/sys tree
  • Network settings (tcp, udp, ip)
  • Memory management (vm)
  • Filesystem settings (fs)
  • Kernel core settings

3. kmod - Loaded kernel modules:

  • Module names
  • Module parameters
  • Dependency information

4. release - OS identification:

  • ID: OS identifier (ubuntu, rhel, etc.)
  • VERSION_ID: OS version (24.04, 9, etc.)
  • PRETTY_NAME: Human-readable name
  • VERSION_CODENAME: Release codename

Usage

Create and use the collector:

collector := os.NewCollector()
measurements, err := collector.Collect(ctx)
if err != nil {
    log.Fatal(err)
}

for _, m := range measurements {
    fmt.Printf("Type: %s\n", m.Type)
    for _, subtype := range m.Subtypes {
        fmt.Printf("  %s: %d settings\n", subtype.Name, len(subtype.Data))
    }
}

Data Sources

The collector reads from:

  • /etc/default/grub: GRUB configuration
  • /proc/cmdline: Kernel boot parameters (overrides GRUB)
  • /proc/sys: Runtime kernel parameters (recursively)
  • /proc/modules: Loaded kernel modules
  • /etc/os-release: Operating system identification

Context Support

The collector respects context cancellation for graceful shutdown:

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

measurements, err := collector.Collect(ctx)

Error Handling

The collector continues on non-critical errors (missing files, permission denied) and returns partial results. Only systemic failures return errors.

Example scenarios:

  • Missing /etc/default/grub: Skips GRUB settings, continues
  • Permission denied on /proc/sys: Returns available parameters
  • Missing /etc/os-release: Returns error (critical file)

Performance

The collector performs file I/O operations synchronously. Typical execution time is < 100ms on modern systems. For optimal performance, use appropriate context timeouts.

Use in Recipes

Recipe generation uses OS collector data for:

  • Kernel parameter validation and tuning
  • Module dependency verification
  • OS version-specific optimizations
  • Boot parameter recommendations

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector struct {
}

Collector collects operating system configuration including: - GRUB bootloader parameters from /proc/cmdline - Loaded kernel modules from /proc/modules - Sysctl parameters from /proc/sys

Example (CollectRelease)

ExampleCollector_collectRelease demonstrates how the release collector works

ctx := context.TODO()
collector := &Collector{}

measurement, err := collector.Collect(ctx)
if err != nil {
	// Handle error (e.g., /etc/os-release not found)
	return
}

// Find the release subtype
for _, subtype := range measurement.Subtypes {
	if subtype.Name == "release" {
		// Access OS release information
		if osName, exists := subtype.Data["NAME"]; exists {
			_ = osName.Any() // Get the OS name
		}
		if osID, exists := subtype.Data["ID"]; exists {
			_ = osID.Any() // Get the OS ID
		}
		break
	}
}

func (*Collector) Collect

func (c *Collector) Collect(ctx context.Context) (*measurement.Measurement, error)

Collect gathers all OS-level configurations and returns them as a single measurement with subtypes: grub, sysctl, kmod, and release. Individual sub-collectors degrade gracefully — if any sub-collector fails, a warning is logged and that subtype is skipped.

Jump to

Keyboard shortcuts

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