vps

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 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 vps connects to a user's server over SSH and reads its state on demand — no agent installed on the box, just standard commands whose output is parsed into metrics. It also runs arbitrary commands for the VPS-manager tool.

Index

Constants

This section is empty.

Variables

View Source
var ErrHostKeyChanged = errors.New("host key changed since it was first trusted — possible MITM, or the server was rebuilt; remove and re-add it if you trust the change")

ErrHostKeyChanged is returned when a host presents a key different from the pinned one — a possible man-in-the-middle, or a legitimately rebuilt server.

Functions

func Ping

func Ping(ctx context.Context, t Target) (who string, seenHostKey string, err error)

Ping confirms a host is reachable and authenticates, returning the remote user@hostname it landed on (proof it really connected) plus the host key seen.

func Run

func Run(ctx context.Context, t Target, command string) (string, string, error)

Run opens a connection, runs one command, and returns its combined output plus the host key the server presented (for TOFU pinning). A non-zero exit is returned with the output so the caller sees stderr rather than a bare error.

Types

type Metrics

type Metrics struct {
	Reachable bool   `json:"reachable"`
	Error     string `json:"error,omitempty"`

	Hostname string `json:"hostname"`
	OS       string `json:"os"`
	Kernel   string `json:"kernel"`
	Uptime   string `json:"uptime"`

	CPUCores   int     `json:"cpu_cores"`
	CPUPercent float64 `json:"cpu_percent"` // 0..100, from load1/cores as a rough gauge
	Load1      float64 `json:"load1"`
	Load5      float64 `json:"load5"`
	Load15     float64 `json:"load15"`

	MemTotalMB int     `json:"mem_total_mb"`
	MemUsedMB  int     `json:"mem_used_mb"`
	MemPercent float64 `json:"mem_percent"`

	SwapTotalMB int     `json:"swap_total_mb"`
	SwapUsedMB  int     `json:"swap_used_mb"`
	SwapPercent float64 `json:"swap_percent"`

	DiskTotalGB float64 `json:"disk_total_gb"`
	DiskUsedGB  float64 `json:"disk_used_gb"`
	DiskPercent float64 `json:"disk_percent"`

	Processes int      `json:"processes"`
	TopProc   []string `json:"top_proc"` // "pid cpu% mem% command", a few rows
}

Metrics is a point-in-time snapshot of a host, read on demand.

func Collect

func Collect(ctx context.Context, t Target) (Metrics, string)

Collect reads a fresh snapshot over one SSH connection, and returns the host key the server presented (for TOFU pinning). It never returns an error for an unreachable host — that is expressed in Metrics.Reachable/Error so the caller can render a card either way.

type Process

type Process struct {
	PID     int     `json:"pid"`
	User    string  `json:"user"`
	CPU     float64 `json:"cpu"`
	Mem     float64 `json:"mem"`
	Command string  `json:"command"`
}

Process is one row from the remote process table.

func Processes

func Processes(ctx context.Context, t Target) ([]Process, string, error)

Processes lists the running processes on a host, busiest CPU first, plus the host key seen. Runs a single ps over one connection.

type Target

type Target struct {
	Host       string
	Port       int
	Username   string
	AuthMethod string // password|key
	Password   string
	PrivateKey string
	Passphrase string
	// KnownHostKey is the server's pinned SSH public key (authorized_keys format,
	// e.g. "ssh-ed25519 AAAA..."). Empty means first use: any key is accepted and
	// returned via the connection's SeenHostKey for the caller to pin. Non-empty
	// means the presented key MUST match, or the dial fails — this is what stops
	// a MITM from harvesting the credentials.
	KnownHostKey string
}

Target is everything needed to dial one host.

Jump to

Keyboard shortcuts

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