Documentation
¶
Overview ¶
Package vminfo provides host runtime inspection helpers for the vminfo CLI and for external Go programs that need lightweight system snapshots.
Index ¶
- Constants
- Variables
- func CollectAll(ctx context.Context, opts Options) (StaticInfo, RuntimeStats, error)
- func TerminateProcess(ctx context.Context, pid int32) error
- type AppMetadata
- type DNSResult
- type DiskIOStats
- type IPInfo
- type InterfaceIO
- type Options
- type PingOptions
- type PingResult
- type PortResult
- type ProcessInfo
- type RuntimeStats
- type Snapshot
- type StaticInfo
- type TempReading
Constants ¶
const ( AppName = "vminfo" DefaultDescription = "Host runtime information toolkit" DefaultRepositoryURL = "https://github.com/cloudapp3/vminfo" DefaultHomepageURL = DefaultRepositoryURL DefaultSchemaVersion = "v1" )
const DefaultIPLookupServer = "https://ip.bestcheapvps.org"
DefaultIPLookupServer is the default IP geo/ASN lookup service.
const DefaultSampleInterval = time.Second
DefaultSampleInterval is the fallback sampling interval used by runtime collection helpers when Options.SampleInterval is not set.
Variables ¶
var ( // Version is the application version injected at build time. Version = "dev" // Commit is the source revision injected at build time. Commit = "none" // BuildTime is the build timestamp injected at build time. BuildTime = "unknown" // Channel is the release channel injected at build time. Channel = "dev" Repository = DefaultRepositoryURL Homepage = DefaultHomepageURL License = "MIT" Description = DefaultDescription )
Functions ¶
func CollectAll ¶
func CollectAll(ctx context.Context, opts Options) (StaticInfo, RuntimeStats, error)
CollectAll returns both static host details and sampled runtime metrics. Uses cached static data; reads only dynamic data (mem/swap) fresh each call.
Types ¶
type AppMetadata ¶
type AppMetadata struct {
Name string `json:"name"`
Version string `json:"version"`
Commit string `json:"commit,omitempty"`
BuildTime string `json:"build_time,omitempty"`
Channel string `json:"channel,omitempty"`
Repository string `json:"repository,omitempty"`
Homepage string `json:"homepage,omitempty"`
License string `json:"license,omitempty"`
Description string `json:"description,omitempty"`
SchemaVersion string `json:"schema_version,omitempty"`
}
AppMetadata describes build and repository metadata for the vminfo CLI.
func Metadata ¶
func Metadata() AppMetadata
Metadata returns normalized application metadata for CLI and embedding use.
type DNSResult ¶ added in v0.2.1
type DNSResult struct {
Domain string `json:"domain"`
Addrs []string `json:"addrs,omitempty"`
Server string `json:"server,omitempty"`
ElapsedMs float64 `json:"elapsed_ms"`
Err string `json:"error,omitempty"`
}
DNSResult is the outcome of a DNS lookup performed by ResolveDNS.
func ResolveDNS ¶ added in v0.2.1
ResolveDNS looks up domain's host addresses. If server is empty it uses the system default resolver; otherwise it queries the given DNS server (accepts "1.1.1.1" or "1.1.1.1:53"; a bare host defaults to port 53).
type DiskIOStats ¶
type DiskIOStats struct {
Name string `json:"name"`
ReadBytes uint64 `json:"read_bytes"`
WriteBytes uint64 `json:"write_bytes"`
ReadSpeed uint64 `json:"read_speed,omitempty"`
WriteSpeed uint64 `json:"write_speed,omitempty"`
ReadCount uint64 `json:"read_count,omitempty"`
WriteCount uint64 `json:"write_count,omitempty"`
IOPS uint64 `json:"iops,omitempty"`
}
DiskIOStats holds per-device disk I/O statistics.
type IPInfo ¶ added in v0.2.1
type IPInfo struct {
IP string `json:"ip"`
Country string `json:"country,omitempty"`
CountryCode string `json:"country_code,omitempty"`
Region string `json:"region,omitempty"`
City string `json:"city,omitempty"`
Postal string `json:"postal,omitempty"`
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
Timezone string `json:"timezone,omitempty"`
ASN string `json:"asn,omitempty"`
Org string `json:"org,omitempty"`
ISP string `json:"isp,omitempty"`
Prefix string `json:"prefix,omitempty"`
IsTor bool `json:"is_tor,omitempty"`
IsProxy bool `json:"is_proxy,omitempty"`
IsVPN bool `json:"is_vpn,omitempty"`
IsDatacenter bool `json:"is_datacenter,omitempty"`
ThreatScore int `json:"threat_score,omitempty"`
ElapsedMs float64 `json:"elapsed_ms,omitempty"`
Err string `json:"error,omitempty"`
}
IPInfo holds geo/ASN/risk info for an IP, as returned by the lookup service.
func LookupIP ¶ added in v0.2.1
LookupIP queries the IP lookup service at server (default DefaultIPLookupServer). If ip is empty the service returns the caller's own public IP info; otherwise it returns info for ip. This is an explicit, user-triggered outbound request (privacy: disclosed in --help and output).
type InterfaceIO ¶
type InterfaceIO struct {
Name string `json:"name"`
RxSpeed uint64 `json:"rx_speed,omitempty"`
TxSpeed uint64 `json:"tx_speed,omitempty"`
IPv4 string `json:"ipv4,omitempty"`
RxBytes uint64 `json:"rx_bytes,omitempty"`
TxBytes uint64 `json:"tx_bytes,omitempty"`
RxErrors uint64 `json:"rx_errors,omitempty"`
TxErrors uint64 `json:"tx_errors,omitempty"`
RxDrops uint64 `json:"rx_drops,omitempty"`
TxDrops uint64 `json:"tx_drops,omitempty"`
// Per-second rates derived from consecutive samples; zero until the
// second sample arrives. Used by health scoring so a long-lived
// cumulative counter does not cause persistent false alarms.
RxErrRate float64 `json:"rx_err_rate,omitempty"`
TxErrRate float64 `json:"tx_err_rate,omitempty"`
RxDropRate float64 `json:"rx_drop_rate,omitempty"`
TxDropRate float64 `json:"tx_drop_rate,omitempty"`
}
InterfaceIO holds per-interface network I/O stats.
type PingOptions ¶ added in v0.2.1
type PingOptions struct {
Mode string // "tcp" (default) or "icmp"
Count int // number of probes (default 4)
Timeout time.Duration // per-probe timeout (default 1s)
Port int // tcp mode target port (default 80)
}
PingOptions controls a Ping probe sequence.
type PingResult ¶ added in v0.2.1
type PingResult struct {
Host string `json:"host"`
Mode string `json:"mode"`
Port int `json:"port,omitempty"`
Sent int `json:"sent"`
Lost int `json:"lost"`
LossPercent float64 `json:"loss_percent"`
RTTs []float64 `json:"rtts_ms,omitempty"`
MinMs float64 `json:"min_ms,omitempty"`
AvgMs float64 `json:"avg_ms,omitempty"`
MaxMs float64 `json:"max_ms,omitempty"`
Err string `json:"error,omitempty"`
}
PingResult is the outcome of a Ping probe sequence.
func Ping ¶ added in v0.2.1
func Ping(ctx context.Context, host string, opts PingOptions) PingResult
Ping probes host Count times. Mode "tcp" (default) does TCP-dial RTTs and is cross-platform / unprivileged; Mode "icmp" sends ICMP Echo via golang.org/x/net (unprivileged udp4: needs net.ipv4.ping_group_range on Linux, unsupported on Windows).
type PortResult ¶ added in v0.2.1
type PortResult struct {
Host string `json:"host"`
Port int `json:"port"`
Open bool `json:"open"`
ElapsedMs float64 `json:"elapsed_ms"`
Err string `json:"error,omitempty"`
}
PortResult is the outcome of a TCP connectivity probe performed by CheckPort.
type ProcessInfo ¶
type ProcessInfo struct {
PID int32 `json:"pid"`
PPID int32 `json:"ppid,omitempty"`
Name string `json:"name,omitempty"`
Command string `json:"command,omitempty"`
User string `json:"user,omitempty"`
State string `json:"state,omitempty"`
CPUPercent float64 `json:"cpu_percent,omitempty"`
MemoryPercent float32 `json:"memory_percent,omitempty"`
RSSBytes uint64 `json:"rss_bytes,omitempty"`
Threads int32 `json:"threads,omitempty"`
Nice int32 `json:"nice,omitempty"`
Uptime uint64 `json:"uptime,omitempty"`
StartedAtUnix int64 `json:"started_at_unix,omitempty"`
}
ProcessInfo describes one local process entry returned by ListProcesses.
func ListProcesses ¶
func ListProcesses(ctx context.Context) ([]ProcessInfo, error)
ListProcesses returns local processes on Linux and an unsupported error on other platforms.
type RuntimeStats ¶
type RuntimeStats struct {
CPU float64 `json:"cpu"`
CPUPerCore []float64 `json:"cpu_per_core,omitempty"`
CPUCount int `json:"cpu_count,omitempty"`
CPUFreqMHz float64 `json:"cpu_freq_mhz,omitempty"`
MemUsed uint64 `json:"mem_used,omitempty"`
SwapUsed uint64 `json:"swap_used,omitempty"`
DiskUsed uint64 `json:"disk_used,omitempty"`
NetIn uint64 `json:"net_in,omitempty"`
NetOut uint64 `json:"net_out,omitempty"`
NetInSpeed uint64 `json:"net_in_speed,omitempty"`
NetOutSpeed uint64 `json:"net_out_speed,omitempty"`
Load1 float64 `json:"load1,omitempty"`
Load5 float64 `json:"load5,omitempty"`
Load15 float64 `json:"load15,omitempty"`
TCPCount uint32 `json:"tcp_count,omitempty"`
TCPStates map[string]uint32 `json:"tcp_states,omitempty"`
UDPCount uint32 `json:"udp_count,omitempty"`
ConntrackCount uint32 `json:"conntrack_count,omitempty"`
ConntrackMax uint32 `json:"conntrack_max,omitempty"`
ProcessCount uint32 `json:"process_count,omitempty"`
Uptime uint64 `json:"uptime,omitempty"`
DiskIO []DiskIOStats `json:"disk_io,omitempty"`
Temps []TempReading `json:"temps,omitempty"`
Interfaces []InterfaceIO `json:"interfaces,omitempty"`
}
RuntimeStats contains sampled runtime metrics for the local host.
func CollectStats ¶
func CollectStats(ctx context.Context, opts Options) (RuntimeStats, error)
CollectStats samples runtime metrics using the provided options. Uses cached static data; reads only dynamic data (mem/swap) fresh each call.
type Snapshot ¶
type Snapshot struct {
Static StaticInfo `json:"static"`
Stats RuntimeStats `json:"stats"`
}
Snapshot combines static host metadata with sampled runtime metrics.
type StaticInfo ¶
type StaticInfo struct {
OS string `json:"os"`
Platform string `json:"platform,omitempty"`
OSVersion string `json:"os_version,omitempty"`
Kernel string `json:"kernel,omitempty"`
Arch string `json:"arch,omitempty"`
Hostname string `json:"hostname,omitempty"`
CPUModel string `json:"cpu_model,omitempty"`
CPUCores uint32 `json:"cpu_cores,omitempty"`
MemTotal uint64 `json:"mem_total,omitempty"`
SwapTotal uint64 `json:"swap_total,omitempty"`
DiskTotal uint64 `json:"disk_total,omitempty"`
Virtualization string `json:"virtualization,omitempty"`
}
StaticInfo contains host properties that change rarely across samples.
func CollectStatic ¶
func CollectStatic(ctx context.Context) (StaticInfo, error)
CollectStatic reads one set of static host details.



