smart

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package smart reads S.M.A.R.T. disk health via smartctl (smartmontools) through an injected exec.Runner.

r, _ := exec.NewRunner(exec.Direct) // smartctl needs root
c, err := smart.New(r)
if err != nil { ... }
devs, _ := c.Scan(ctx)
for _, d := range devs {
    info, _ := c.Device(ctx, d.Name)
    fmt.Println(info.Name, info.Healthy, info.TemperatureC)
}

smart is a single-implementation, read-only Collector (§3.8): smartctl is the one tool. It exposes an interface for shape-uniformity with the rest of the SDK. Probes escalate through the Runner (smartctl needs root to open a device).

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalidDevice = errors.New("smart: invalid device path")

ErrInvalidDevice is returned when a device path is unsafe to pass to smartctl (empty, not absolute, contains "..", or flag-shaped).

Functions

This section is empty.

Types

type Collector

type Collector interface {
	// Scan lists the devices smartctl can inspect.
	Scan(ctx context.Context) ([]ScanDevice, error)
	// Device returns the health summary for one device path.
	Device(ctx context.Context, dev string) (Device, error)
}

Collector is the S.M.A.R.T. read surface.

func New

func New(runner exec.Runner) (Collector, error)

New builds a smart Collector driven by runner. A nil runner is rejected. New is pure — it does not probe for smartctl (a missing binary surfaces at call time).

Example

ExampleNew scans for devices and prints each one's health.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/manchtools/power-manage-sdk/sys/exec"
	"github.com/manchtools/power-manage-sdk/sys/smart"
)

func main() {
	r, err := exec.NewRunner(exec.Direct) // smartctl needs root
	if err != nil {
		log.Fatal(err)
	}
	c, err := smart.New(r)
	if err != nil {
		log.Fatal(err)
	}
	devs, err := c.Scan(context.Background())
	if err != nil {
		log.Fatal(err)
	}
	for _, d := range devs {
		info, err := c.Device(context.Background(), d.Name)
		if err != nil {
			continue
		}
		fmt.Printf("%s healthy=%v %d°C\n", info.Name, info.Healthy, info.TemperatureC)
	}
}

type Device

type Device struct {
	Name         string // the device passed to Device()
	Model        string
	Serial       string
	Healthy      bool // smart_status.passed
	TemperatureC int  // temperature.current (0 if unreported)
	PowerOnHours int  // power_on_time.hours (0 if unreported)
}

Device is the parsed health summary for one device.

type ScanDevice

type ScanDevice struct {
	Name string // e.g. /dev/sda
	Type string // smartctl device type, e.g. "sat", "nvme"
}

ScanDevice is one entry from `smartctl --scan`.

Jump to

Keyboard shortcuts

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