hostdiag

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 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 hostdiag answers a fixed set of read-only host questions for the web CLI console, in process. It never executes anything and takes no input beyond a subcommand name chosen from a closed list.

Index

Constants

View Source
const Command = "host"

Command is the console word that routes a line here.

View Source
const EnvSwitch = "APP_CLI_CONSOLE_HOST"

EnvSwitch turns host diagnostics off without turning off the console.

Variables

View Source
var ErrUnsupported = errors.New("not supported on this platform")

ErrUnsupported means the current OS has no implementation.

Functions

func Check

func Check(argv []string) (string, error)

Check validates a parsed line whose first word is Command and returns the subcommand.

func Enabled

func Enabled() bool

Enabled reports whether host diagnostics are allowed by the environment.

func FormatDF

func FormatDF(rows []DiskUsage) string

FormatDF renders disk usage rows; Used% matches df (used over used plus available).

func FormatFree

func FormatFree(m Meminfo) string

FormatFree renders a Meminfo as the free report.

func FormatLoad

func FormatLoad(l Loadavg, cpus int) string

FormatLoad renders a Loadavg.

func FormatService

func FormatService(s ServiceInfo) string

FormatService renders the service report.

func HumanDuration

func HumanDuration(d time.Duration) string

HumanDuration renders d as "3d 4h 5m", or seconds when under a minute.

func ParseOSRelease

func ParseOSRelease(text string) string

ParseOSRelease returns PRETTY_NAME, falling back to NAME VERSION.

func ParseUptime

func ParseUptime(text string) (time.Duration, error)

ParseUptime reads the first field of /proc/uptime as seconds since boot.

func ParseVMRSS

func ParseVMRSS(text string) (uint64, error)

ParseVMRSS reads VmRSS from /proc/self/status, in bytes.

func Run

func Run(sub string, info Info) (string, error)

Run produces the plain text report for a subcommand that passed Check.

func Sanitize

func Sanitize(s string) string

Sanitize drops escape and control characters, keeping newlines and tabs.

func Subcommands

func Subcommands() []string

Subcommands returns the closed list of host subcommands.

Types

type DiskUsage

type DiskUsage struct {
	Label, Path        string
	Total, Used, Avail uint64
}

DiskUsage is one statfs result, in bytes.

type Info

type Info struct {
	DataDir    string
	Version    string
	Supervised bool
}

Info is what the control plane itself supplies; none of it comes from the request.

type Loadavg

type Loadavg struct {
	One, Five, Fifteen string
	Runnable, Total    int
}

Loadavg is the parsed /proc/loadavg.

func ParseLoadavg

func ParseLoadavg(text string) (Loadavg, error)

ParseLoadavg reads "0.10 0.20 0.30 1/234 5678"; the last pid field is ignored.

type Meminfo

type Meminfo struct {
	Total, Available, SwapTotal, SwapFree uint64
}

Meminfo holds the /proc/meminfo fields the free report uses, in bytes.

func ParseMeminfo

func ParseMeminfo(text string) (Meminfo, error)

ParseMeminfo reads /proc/meminfo text; values there are in kB.

type ServiceInfo

type ServiceInfo struct {
	Version    string
	GoVersion  string
	Started    time.Time
	Now        time.Time
	Goroutines int
	RSS        uint64
	RSSKnown   bool
	Supervised bool
}

ServiceInfo describes this control plane process.

type UsageError

type UsageError struct{ Reason string }

UsageError is a refusal whose message is safe to show the operator.

func (*UsageError) Error

func (e *UsageError) Error() string

Jump to

Keyboard shortcuts

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