uptime

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 8 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 uptime is the uptime behavior: how long the host has run since it booted.

Index

Constants

This section is empty.

Variables

View Source
var Behavior = behavior.Register(behavior.Define(
	"uptime", "Get the uptime of target hosts",
	behavior.Node,
	behavior.API,
	behavior.Area(area.Node),
	behavior.CLI,

	behavior.Platform(behavior.PlatformLinux, newReader),
	behavior.Platform(behavior.PlatformDarwin, newReader),
	behavior.RunsOnPlatform(behavior.PlatformDarwin, "sysctl"),
	behavior.Read("get", Get).
		Describe("Get the uptime of the host").
		Explain("Reads how long the host has run since it booted: /proc/uptime on Linux, "+
			"and the boot time that sysctl gives on macOS. The uptime is in days, hours "+
			"and minutes, and in seconds.").
		Example("A host up for a day, two hours and five minutes", GetInput{},
			Entry{Uptime: "1 day, 2 hours, 5 minutes", Seconds: 93900},
			behavior.Exists("/proc/uptime", "93900.42 180001.15\n"),
			behavior.Exists("/proc/stat", "btime 1767229145\n"),
			behavior.Prints("sysctl -n kern.boottime",
				"{ sec = 1767229145, usec = 0 } Thu Jan  1 00:59:05 2026"),
		),
))

Behavior is the uptime definition. The routes, the agent's dispatch, the CLI commands, the spec, the docs pages and the tests of every layer above the provider are built from it. osapi dsl behavior spec get lists every option.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Uptime  string `json:"uptime"  doc:"How long the host has run, in days, hours and minutes"`
	Seconds int    `json:"seconds" doc:"How long the host has run, in seconds"`
}

Entry is the host's uptime.

func Get

func Get(
	ctx context.Context,
	p Provider,
	_ GetInput,
) (Entry, error)

Get is how long the host has run.

type GetInput

type GetInput struct{}

GetInput is get's input, which has none.

type Provider

type Provider interface {
	Uptime(ctx context.Context) (time.Duration, error)
}

Provider is what each platform implements: how long the host has run. mocks/ generates its double for the methods' tests.

Directories

Path Synopsis
Package mocks holds the generated double of the uptime provider, for the methods' tests.
Package mocks holds the generated double of the uptime provider, for the methods' tests.

Jump to

Keyboard shortcuts

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