Documentation
¶
Overview ¶
Package view serves a read-only dashboard of the usage snapshots written by `agent-pro usage collect`. It reads the store, never writes to it.
Index ¶
- Constants
- Variables
- func Chartable(name string) bool
- func Handler(store *usage.Store, opts Options) http.Handler
- func ParseRange(value string) (time.Duration, error)
- func Serve(ctx context.Context, store *usage.Store, opts Options) error
- func Step(name string) bool
- type MetricInfo
- type Options
- type Point
- type Series
Constants ¶
const ( // MetricPrimaryPercent overlays each provider's own quota percentage, which // every provider names differently. MetricPrimaryPercent = "primary_percent" // MetricSessionsTotal is the count of sessions found on disk per provider. MetricSessionsTotal = "sessions_total" )
Metric names the dashboard adds to the keys stored in a snapshot.
const (
DefaultPort = 8080
)
DefaultPort is the first port `usage view` tries. A busy port is skipped for up to viewPortAttempts ports.
const DefaultSince = 7 * 24 * time.Hour
DefaultSince is the chart range used when --since is not given.
const RecentLimit = 50
RecentLimit is how many newest snapshots /api/summary carries for its table.
const SchemaID = "agent-pro/usage-view/v1"
SchemaID is the schema of the dashboard's JSON API.
Variables ¶
var DefaultMetrics = []string{MetricPrimaryPercent, MetricSessionsTotal}
DefaultMetrics are charted when a request names no metric.
Functions ¶
func Handler ¶
Handler serves the dashboard page and its read-only JSON API over one store. The store is re-read per request, so a new collect shows up on the next poll.
func ParseRange ¶
ParseRange parses a chart range: a duration such as 90m, 24h, 7d or 2w.
Types ¶
type MetricInfo ¶
type MetricInfo struct {
Name string `json:"name"`
// Kind is percent, counter or number; KindTime marks a timestamp.
Kind string `json:"kind"`
Unit string `json:"unit,omitempty"`
// Providers are the providers that reported this metric, sorted.
Providers []string `json:"providers"`
// Count is how many stored records carry a value for it.
Count int `json:"count"`
// Chartable is false for values that are timestamps, not magnitudes.
Chartable bool `json:"chartable"`
}
MetricInfo describes one metric the dashboard can chart.
func Metrics ¶
func Metrics(records []usage.StoredRecord) []MetricInfo
Metrics lists every chartable metric found in the records, the two derived ones first, then the raw snapshot keys alphabetically.
type Options ¶
type Options struct {
// Port is the preferred listen port; zero or negative binds any free port.
Port int
// PortExplicit records that --port was given, so falling back to the next
// free port is worth a warning.
PortExplicit bool
// Since is the default chart range.
Since time.Duration
// StaticDir serves dashboard.html from disk instead of the embedded copy.
StaticDir string
// Open opens the dashboard in a browser once it is listening.
Open bool
// JSON prints one machine-readable line for the bound URL instead of the
// human summary.
JSON bool
// Stdout receives the result lines. Defaults to os.Stdout.
Stdout io.Writer
// Stderr receives warnings and the stop hint. Defaults to os.Stderr.
Stderr io.Writer
// Now overrides the clock, for tests.
Now func() time.Time
}
Options configures the read-only dashboard server.
type Series ¶
type Series struct {
Provider string `json:"provider"`
Points []Point `json:"points"`
Latest float64 `json:"latest"`
Min float64 `json:"min"`
Max float64 `json:"max"`
}
Series is one provider's points for one metric, ascending by time.
func BuildSeries ¶
BuildSeries pivots stored records into per-provider series for one metric. Records arrive newest first (store order) and each series is returned ascending by time, so a chart can draw it directly.