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 ¶
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 ¶
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.
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.
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.
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.