Documentation
¶
Overview ¶
Package report turns hub records into tool output. It is pure: callers pass the records and the current time in.
Index ¶
- Constants
- Variables
- func Label(s hub.System) string
- func ParseMetrics(raw []string) ([]Metric, []Source, error)
- func Resolve(systems []hub.System, ref string) (hub.System, error)
- func TokenWarning(now, expires time.Time) []string
- type AmbiguousError
- type Battery
- type Cert
- type Code
- type ContainerRow
- type Containers
- type Core
- type Counts
- type DetailInput
- type DetailOptions
- type DetailResult
- type Disk
- type FailingAttr
- type Filesystem
- type FleetInput
- type FleetOptions
- type FleetResult
- type GPURow
- type GPUs
- type HistoryInput
- type HistoryOptions
- type HistoryResult
- type Interface
- type ListCounts
- type Memory
- type Metric
- type MetricKind
- type MonitorRow
- type Network
- type PackageRow
- type PoolRow
- type Problem
- type Read
- type Row
- type Scrub
- type Section
- type SeriesItem
- type ServiceCounts
- type ServiceRow
- type Services
- type SmartRow
- type SortKey
- type Source
- type Summary
- type Swap
- type SystemHistory
- type SystemRef
- type Updates
- type UpdatesSection
- type VdevRow
- type Window
- type WindowRef
Constants ¶
const ( MaxHistorySystems = 5 MaxMetrics = 6 MaxPoints = 60 )
History limits.
const ( DefaultLimit = 25 MaxLimit = 200 )
List limits for containers and services.
const DefaultWindow = "24h"
DefaultWindow is used when the caller names none.
Variables ¶
var Sections = []Section{SectionSummary, SectionCore, SectionNetwork, SectionDisk, SectionGPU, SectionContainers, SectionServices, SectionUpdates}
Sections lists every section system_detail accepts.
var Sorts = []SortKey{SortCPU, SortMem, SortName}
Sorts lists every sort system_detail accepts.
var Windows = []Window{ {"1h", hub.Stat1m, time.Hour, time.Minute}, {"12h", hub.Stat10m, 12 * time.Hour, 10 * time.Minute}, {"24h", hub.Stat20m, 24 * time.Hour, 20 * time.Minute}, {"7d", hub.Stat120m, 7 * 24 * time.Hour, 2 * time.Hour}, {"30d", hub.Stat480m, 30 * 24 * time.Hour, 8 * time.Hour}, }
Windows lists the ranges metric_history accepts, shortest first.
Functions ¶
func Label ¶ added in v0.2.0
Label names a system with its ID. A pick list answer is matched back by it.
func ParseMetrics ¶
ParseMetrics checks the requested metrics and returns them with the sources they need. It runs before any hub read.
func Resolve ¶
Resolve finds the system ref names: an exact ID, else a case-insensitive exact name, else a unique case-insensitive name prefix.
func TokenWarning ¶
TokenWarning returns the warning for a token that has expired or expires within 30 days, or nil. A zero expires means unknown.
Types ¶
type AmbiguousError ¶
AmbiguousError means a name matched more than one system.
func (*AmbiguousError) Error ¶
func (e *AmbiguousError) Error() string
type Battery ¶
type Battery struct {
Pct int `json:"pct"`
State string `json:"state"` // unknown, empty, full, charging, discharging or idle
}
Battery is the host's main battery.
type Cert ¶
type Cert struct {
DaysLeft int `json:"days_left"` // negative once expired
Issuer string `json:"issuer,omitempty"`
}
Cert is an HTTPS target's certificate.
type Code ¶ added in v0.2.0
type Code string
Code names a kind of problem. Rows list them in the order of these constants: buildRow and structural add them in it.
const ( CodeStatusDown Code = "status_down" CodeStatusPaused Code = "status_paused" CodeStatusPending Code = "status_pending" CodeStale Code = "stale" CodeServiceFailed Code = "service_failed" CodeContainerUnhealthy Code = "container_unhealthy" CodeContainerGone Code = "container_gone" CodeSmartFailed Code = "smart_failed" CodeSmartWarning Code = "smart_warning" CodePoolDegraded Code = "pool_degraded" CodeMonitorFailing Code = "monitor_failing" CodeCertExpired Code = "cert_expired" CodeCertExpiring Code = "cert_expiring" CodeSecurityUpdates Code = "security_updates" )
The problem codes.
type ContainerRow ¶
type ContainerRow struct {
Name string `json:"name"`
Image string `json:"image"`
Status string `json:"status"` // Docker's text, e.g. "Up 3 days"
Health string `json:"health"` // none, starting, healthy, unhealthy or unknown
CPUPct *float64 `json:"cpu_pct,omitempty"`
MemBytes uint64 `json:"mem_bytes"`
NetBytesPerS uint64 `json:"net_bytes_per_s"`
AgeS int64 `json:"age_s"`
Problems []Code `json:"problems,omitempty"`
}
ContainerRow is one running container.
type Containers ¶
type Containers struct {
Counts *ListCounts `json:"counts,omitempty"`
Unhealthy *int `json:"unhealthy,omitempty"`
Rows []ContainerRow `json:"rows,omitempty"`
Gone []string `json:"gone,omitempty"` // stopped within the last hour
Absent []string `json:"absent,omitempty"`
}
Containers is Beszel's Containers tab: running containers only.
type Core ¶
type Core struct {
SampledAgoS *int64 `json:"sampled_ago_s,omitempty"`
CPUPct *float64 `json:"cpu_pct,omitempty"`
CPUBreakdownPct map[string]float64 `json:"cpu_breakdown_pct,omitempty"`
CPUCoresPct []uint16 `json:"cpu_cores_pct,omitempty"`
LoadAvg []float64 `json:"load_avg,omitempty"`
Mem *Memory `json:"mem,omitempty"`
Swap *Swap `json:"swap,omitempty"`
TempsC map[string]float64 `json:"temps_c,omitempty"`
FansRPM map[string]uint16 `json:"fans_rpm,omitempty"`
Battery *Battery `json:"battery,omitempty"`
Absent []string `json:"absent,omitempty"` // "part: why it is missing"
}
Core is Beszel's Core tab: CPU, load, memory, swap and sensors.
type Counts ¶
type Counts struct {
Total int `json:"total"`
Up int `json:"up"`
Down int `json:"down"`
Paused int `json:"paused"`
Pending int `json:"pending"`
Unknown int `json:"unknown,omitempty"` // a status Beszel does not define
WithProblems int `json:"with_problems"`
}
Counts tallies systems by status.
type DetailInput ¶
type DetailInput struct {
FleetInput
System hub.System
Details Read[*hub.SystemDetails] // nil when the hub has none
Latest Read[*hub.SystemStats] // newest stats sample; nil when there is none
Packages Read[*hub.PackageUpdates] // live from the agent
}
DetailInput is everything system_detail reads for one system, already fetched. FleetInput carries the problem sources the summary needs; its Systems is unused.
type DetailOptions ¶
type DetailOptions struct {
Sections []Section // empty means summary only
// The list knobs shape containers and services only.
Filter string // case-insensitive substring of a name or container image; "" keeps all
ProblemsOnly bool
Sort SortKey // SortCPU when ""
Limit int // rows per list beyond problem rows; 0 means DefaultLimit
}
DetailOptions picks what system_detail returns.
type DetailResult ¶
type DetailResult struct {
AsOf time.Time `json:"as_of"`
System SystemRef `json:"system"`
Warnings []string `json:"warnings,omitempty"`
Hints []string `json:"hints,omitempty"` // which list knob to change when rows were cut or nothing matched
Summary *Summary `json:"summary,omitempty"`
Core *Core `json:"core,omitempty"`
Network *Network `json:"network,omitempty"`
Disk *Disk `json:"disk,omitempty"`
GPU *GPUs `json:"gpu,omitempty"`
Containers *Containers `json:"containers,omitempty"`
Services *Services `json:"services,omitempty"`
Updates *UpdatesSection `json:"updates,omitempty"`
}
DetailResult is the system_detail output. Only requested sections are set.
func Detail ¶
func Detail(in DetailInput, o DetailOptions) (DetailResult, error)
Detail builds the system_detail result for in.System.
type Disk ¶
type Disk struct {
SampledAgoS *int64 `json:"sampled_ago_s,omitempty"`
Filesystems []Filesystem `json:"filesystems,omitempty"`
Pools []PoolRow `json:"pools,omitempty"`
Smart []SmartRow `json:"smart,omitempty"`
Absent []string `json:"absent,omitempty"` // "part: why it is missing"
}
Disk is Beszel's Disk tab: filesystems, I/O, storage pools and SMART. SMART and pools are stored results, so they are shown even when the system is down; filesystems and I/O are live.
type FailingAttr ¶
type FailingAttr struct {
Name string `json:"name"`
WhenFailed string `json:"when_failed"`
Raw string `json:"raw,omitempty"`
}
FailingAttr is a SMART attribute that has failed.
type Filesystem ¶
type Filesystem struct {
Name string `json:"name"` // "/" for the root disk
TotalGiB *float64 `json:"total_gib,omitempty"`
UsedGiB *float64 `json:"used_gib,omitempty"`
Pct *float64 `json:"pct,omitempty"`
ReadBytesPerS uint64 `json:"read_bytes_per_s"`
WriteBytesPerS uint64 `json:"write_bytes_per_s"`
IOUtilPct *float64 `json:"io_util_pct,omitempty"`
}
Filesystem is the root disk or an extra filesystem. Beszel stores sizes as GiB with 2 decimals, so they stay in GiB rather than imply byte precision.
type FleetInput ¶
type FleetInput struct {
Now time.Time
HubVersion string
TokenExpiresAt time.Time
Systems []hub.System // the systems to report
Services Read[[]hub.Service]
Containers Read[[]hub.Container]
Smart Read[[]hub.SmartDevice]
Pools Read[[]hub.ZfsPool]
Monitors Read[[]hub.Monitor]
// RecentContainers is each up system's 10m container rows from the
// last hour, by system ID.
RecentContainers map[string]Read[[]hub.ContainerStats]
// LastSeen is when each system that is not up last sent data, by ID:
// its newest stats row. Zero means none in Beszel's 30-day retention; a
// missing entry or failed read means unknown, and systems.updated stands in.
LastSeen map[string]Read[time.Time]
}
FleetInput is everything fleet_status reads, already fetched.
type FleetOptions ¶
type FleetOptions struct {
ProblemsOnly bool // drop rows without problems; counts still cover all
}
FleetOptions narrows the result.
type FleetResult ¶
type FleetResult struct {
AsOf time.Time `json:"as_of"`
Counts Counts `json:"counts"`
Warnings []string `json:"warnings,omitempty"`
Systems []Row `json:"systems"`
}
FleetResult is the fleet_status output.
func Fleet ¶
func Fleet(in FleetInput, o FleetOptions) FleetResult
Fleet builds the fleet_status result.
type GPURow ¶
type GPURow struct {
ID string `json:"id"`
Name string `json:"name"`
UsagePct *float64 `json:"usage_pct,omitempty"`
MemUsedBytes *uint64 `json:"mem_used_bytes,omitempty"`
MemTotalBytes *uint64 `json:"mem_total_bytes,omitempty"`
PowerW *float64 `json:"power_w,omitempty"`
}
GPURow is one GPU. Fields the agent does not report are omitted.
type GPUs ¶
type GPUs struct {
SampledAgoS *int64 `json:"sampled_ago_s,omitempty"`
GPUs []GPURow `json:"gpus,omitempty"`
Absent []string `json:"absent,omitempty"` // "part: why it is missing"
}
GPUs is Beszel's GPU tab.
type HistoryInput ¶
type HistoryInput struct {
Now time.Time
TokenExpiresAt time.Time
Window Window
Systems []SystemHistory // the requested systems, in request order
Monitors Read[[]hub.Monitor]
}
HistoryInput is everything metric_history reads, already fetched.
type HistoryOptions ¶
HistoryOptions picks the metrics and the point count.
type HistoryResult ¶
type HistoryResult struct {
AsOf time.Time `json:"as_of"`
Window WindowRef `json:"window"`
Warnings []string `json:"warnings,omitempty"`
Hints []string `json:"hints,omitempty"`
Series []SeriesItem `json:"series"`
}
HistoryResult is the metric_history output.
func History ¶
func History(in HistoryInput, o HistoryOptions) (HistoryResult, error)
History builds the metric_history result.
type Interface ¶
type Interface struct {
Name string `json:"name"`
SentBytesPerS uint64 `json:"sent_bytes_per_s"`
RecvBytesPerS uint64 `json:"recv_bytes_per_s"`
TotalSentBytes uint64 `json:"total_sent_bytes"` // since the interface came up
TotalRecvBytes uint64 `json:"total_recv_bytes"`
}
Interface is one network interface's traffic.
type ListCounts ¶
type ListCounts struct {
Total int `json:"total"`
Shown int `json:"shown"`
Truncated bool `json:"truncated"` // limit cut rows
}
ListCounts says how much of a list is shown. Total counts every row on the server, before filter and problems_only.
type Memory ¶
type Memory struct {
TotalBytes uint64 `json:"total_bytes"`
UsedBytes uint64 `json:"used_bytes"`
CacheBytes uint64 `json:"cache_bytes"`
ZFSArcBytes uint64 `json:"zfs_arc_bytes,omitempty"`
Pct *float64 `json:"pct,omitempty"`
}
Memory is RAM use in bytes.
type Metric ¶
type Metric struct {
Raw string
Kind MetricKind
Target string
}
Metric is one requested metric: a kind and an optional target.
type MetricKind ¶ added in v0.2.0
type MetricKind string
MetricKind is what metric_history reads; container and monitor need a target.
const ( MetricCPU MetricKind = "cpu" MetricIOWait MetricKind = "cpu_iowait" MetricMem MetricKind = "mem" MetricSwap MetricKind = "swap" MetricDisk MetricKind = "disk" MetricDiskIO MetricKind = "disk_io" MetricNet MetricKind = "net" MetricLoad MetricKind = "load" MetricTemp MetricKind = "temp" MetricGPU MetricKind = "gpu" MetricContainer MetricKind = "container" MetricMonitor MetricKind = "monitor" )
The metric kinds metric_history accepts.
type MonitorRow ¶
type MonitorRow struct {
Target string `json:"target"`
Protocol string `json:"protocol"` // icmp, tcp, http or dns
Port int `json:"port,omitempty"`
Enabled bool `json:"enabled"`
IntervalS int `json:"interval_s,omitempty"`
LatencyMs *float64 `json:"latency_ms,omitempty"`
LatencyAvg1hMs *float64 `json:"latency_avg_1h_ms,omitempty"`
LatencyMax1hMs *float64 `json:"latency_max_1h_ms,omitempty"`
Loss1hPct *float64 `json:"loss_1h_pct,omitempty"`
Cert *Cert `json:"cert,omitempty"` // absent when unknown, not when fine
CheckedAgoS *int64 `json:"checked_ago_s,omitempty"`
Problems []Code `json:"problems,omitempty"`
}
MonitorRow is one network monitor: a probe the agent runs to a target.
type Network ¶
type Network struct {
SampledAgoS *int64 `json:"sampled_ago_s,omitempty"`
SentBytesPerS *uint64 `json:"sent_bytes_per_s,omitempty"`
RecvBytesPerS *uint64 `json:"recv_bytes_per_s,omitempty"`
Interfaces []Interface `json:"interfaces,omitempty"`
WiFiRSSIdBm map[string]int8 `json:"wifi_rssi_dbm,omitempty"`
Monitors []MonitorRow `json:"monitors,omitempty"`
Absent []string `json:"absent,omitempty"` // "part: why it is missing"
}
Network is Beszel's Network tab: traffic, WiFi and network monitors.
type PackageRow ¶
type PackageRow struct {
Name string `json:"name"`
Current string `json:"current,omitempty"` // empty when the manager does not say
Available string `json:"available"`
Security bool `json:"security,omitempty"`
}
PackageRow is one pending update.
type PoolRow ¶
type PoolRow struct {
Name string `json:"name"`
Health string `json:"health"`
Status string `json:"status,omitempty"` // zpool status message
SizeBytes uint64 `json:"size_bytes"`
AllocBytes uint64 `json:"alloc_bytes"`
FreeBytes uint64 `json:"free_bytes"`
RawSizes bool `json:"raw_sizes,omitempty"` // sizes are physical, not usable space
Scrub *Scrub `json:"scrub,omitempty"`
BadVdevs []VdevRow `json:"bad_vdevs,omitempty"` // only devices with errors or not ONLINE
CheckedAgoS *int64 `json:"checked_ago_s,omitempty"`
Problems []Code `json:"problems,omitempty"`
}
PoolRow is a ZFS or btrfs pool.
type Problem ¶
type Problem struct {
Code Code `json:"code"`
Detail string `json:"detail"`
Section Section `json:"section"`
Count int `json:"count,omitempty"`
}
Problem is one kind of fault on a system.
type Read ¶ added in v0.2.0
Read is one hub read: what it returned, or why it failed. The zero Read is a read not made, and reads as empty.
type Row ¶
type Row struct {
Name string `json:"name"`
Status hub.Status `json:"status"`
AgeS *int64 `json:"age_s,omitempty"`
LastSeenAgoS *int64 `json:"last_seen_ago_s,omitempty"`
CPUPct *float64 `json:"cpu_pct,omitempty"`
MemPct *float64 `json:"mem_pct,omitempty"`
DiskPct *float64 `json:"disk_pct,omitempty"`
DiskWorst string `json:"disk_worst,omitempty"`
TempHottestC *float64 `json:"temp_hottest_c,omitempty"`
LoadPerThread *float64 `json:"load_per_thread,omitempty"`
NetBytesPerS *uint64 `json:"net_bytes_per_s,omitempty"`
UptimeS *uint64 `json:"uptime_s,omitempty"`
Agent string `json:"agent,omitempty"`
Updates *Updates `json:"updates,omitempty"`
Problems []Problem `json:"problems,omitempty"`
}
Row is one system. Live metrics are present only while the system is up.
type Section ¶ added in v0.2.0
type Section string
Section is a part of system_detail's answer.
const ( SectionSummary Section = "summary" SectionCore Section = "core" SectionNetwork Section = "network" SectionDisk Section = "disk" SectionGPU Section = "gpu" SectionContainers Section = "containers" SectionServices Section = "services" SectionUpdates Section = "updates" )
Sections of system_detail, in the order of Beszel's system page tabs.
type SeriesItem ¶
type SeriesItem struct {
System string `json:"system"`
Metric string `json:"metric"`
Part string `json:"part,omitempty"` // sent, recv, read, write, cpu or mem
Unit string `json:"unit"`
Avg *float64 `json:"avg,omitempty"`
MinBucketAvg *float64 `json:"min_bucket_avg,omitempty"`
Peak *float64 `json:"peak,omitempty"`
MaxBucketAvg *float64 `json:"max_bucket_avg,omitempty"`
HighAgoS *int64 `json:"high_ago_s,omitempty"` // age of the bucket holding the high point
Last *float64 `json:"last,omitempty"`
LastAgoS *int64 `json:"last_ago_s,omitempty"`
LossPct *float64 `json:"loss_pct,omitempty"` // monitors only
Buckets int `json:"buckets"`
ExpectedBuckets int `json:"expected_buckets"`
CoveragePct float64 `json:"coverage_pct"`
Note string `json:"note,omitempty"`
Points [][2]float64 `json:"points,omitempty"` // [age_s, value], oldest first
}
SeriesItem summarises one metric on one system. Peak is a true per-minute maximum and is set only where Beszel stores one; MaxBucketAvg is the highest bucket average otherwise.
type ServiceCounts ¶
ServiceCounts counts systemd units.
type ServiceRow ¶
type ServiceRow struct {
Name string `json:"name"`
State string `json:"state"` // active, inactive, failed, activating, deactivating or reloading
Sub string `json:"sub"` // dead, running, exited, failed or unknown
CPUPct *float64 `json:"cpu_pct,omitempty"`
MemBytes uint64 `json:"mem_bytes"`
MemPeakBytes uint64 `json:"mem_peak_bytes"`
Problems []Code `json:"problems,omitempty"`
}
ServiceRow is one systemd unit.
type Services ¶
type Services struct {
Counts *ListCounts `json:"counts,omitempty"`
Failed *int `json:"failed,omitempty"`
Rows []ServiceRow `json:"rows,omitempty"`
Absent []string `json:"absent,omitempty"`
}
Services is Beszel's Services tab: systemd units.
type SmartRow ¶
type SmartRow struct {
Name string `json:"name"`
Model string `json:"model,omitempty"`
Type string `json:"type,omitempty"`
State hub.SmartState `json:"state"`
CapacityBytes uint64 `json:"capacity_bytes,omitempty"`
TempC *float64 `json:"temp_c,omitempty"`
PowerOnHours uint64 `json:"power_on_hours,omitempty"`
PowerCycles uint64 `json:"power_cycles,omitempty"`
FailingAttributes []FailingAttr `json:"failing_attributes,omitempty"`
CheckedAgoS *int64 `json:"checked_ago_s,omitempty"`
Problems []Code `json:"problems,omitempty"`
}
SmartRow is one drive's SMART summary.
type SortKey ¶ added in v0.2.0
type SortKey string
SortKey orders containers and services after their problem rows.
type Summary ¶
type Summary struct {
OS string `json:"os,omitempty"`
Kernel string `json:"kernel,omitempty"`
Hostname string `json:"hostname,omitempty"`
Arch string `json:"arch,omitempty"`
CPUModel string `json:"cpu_model,omitempty"`
Cores int `json:"cores,omitempty"`
Threads int `json:"threads,omitempty"`
MemTotalBytes uint64 `json:"mem_total_bytes,omitempty"`
Agent string `json:"agent,omitempty"`
UptimeS *uint64 `json:"uptime_s,omitempty"`
CPUPct *float64 `json:"cpu_pct,omitempty"`
MemPct *float64 `json:"mem_pct,omitempty"`
DiskPct *float64 `json:"disk_pct,omitempty"`
DiskWorst string `json:"disk_worst,omitempty"`
TempHottestC *float64 `json:"temp_hottest_c,omitempty"`
LoadAvg []float64 `json:"load_avg,omitempty"` // 1, 5 and 15 minutes
LoadPerThread *float64 `json:"load_per_thread,omitempty"`
NetBytesPerS *uint64 `json:"net_bytes_per_s,omitempty"`
GPUPct *float64 `json:"gpu_pct,omitempty"`
Battery *Battery `json:"battery,omitempty"`
Services *ServiceCounts `json:"services,omitempty"`
Updates *Updates `json:"updates,omitempty"`
Problems []Problem `json:"problems,omitempty"`
}
Summary is Beszel's info bar plus the fleet row's numbers and problems. Live numbers are present only while the system is up.
type SystemHistory ¶ added in v0.2.0
type SystemHistory struct {
System hub.System
Stats Read[[]hub.SystemStats]
Containers Read[[]hub.ContainerStats]
MonitorStats Read[[]hub.MonitorStats]
}
SystemHistory is one system's rows in the window, oldest first. Only the sources the metrics need are read.
type SystemRef ¶
type SystemRef struct {
Name string `json:"name"`
Status hub.Status `json:"status"`
AgeS *int64 `json:"age_s,omitempty"`
LastSeenAgoS *int64 `json:"last_seen_ago_s,omitempty"`
}
SystemRef names the system and how fresh its data is.
type UpdatesSection ¶
type UpdatesSection struct {
Total *int `json:"total,omitempty"`
Security *int `json:"security,omitempty"` // absent when the package manager does not flag security updates
Manager string `json:"manager,omitempty"`
CheckedAgoS *int64 `json:"checked_ago_s,omitempty"`
Packages []PackageRow `json:"packages,omitempty"` // security updates first, then by name
Absent []string `json:"absent,omitempty"`
}
UpdatesSection is Beszel's pending package updates for one system. The list is a live answer from the agent, which serves its last hourly check.
type VdevRow ¶
type VdevRow struct {
Name string `json:"name"`
State string `json:"state"`
ReadErrors uint64 `json:"read_errors"`
WriteErrors uint64 `json:"write_errors"`
ChecksumErrors uint64 `json:"checksum_errors"`
}
VdevRow is a pool device with a fault.
type Window ¶
Window is one metric_history time range, read from the stats type Beszel's own charts use for it (site utils.ts).
func FindWindow ¶
FindWindow returns the window named name; "" means DefaultWindow.