Documentation
¶
Overview ¶
Package observe samples a load run into time series: the server's /metrics, the disk its state occupies, JetStream stream state, pprof profiles, and the load generator's own health, which decides whether the run is valid.
Series names are the contract the report reads. A series with a label carries it in braces after the name, as name{label}: a queue, a usage pool, a JetStream stream (or stream/consumer), or an HTTP route pattern.
server.cpu_cores server.rss_bytes server.goroutines server.open_fds
server.gc_pause_p99_s server.heap_bytes
sched.queue_depth{queue} sched.idle_workers workers.online
usage.claims{pool} http.p95_s{route}
disk.sqlite_db_bytes disk.sqlite_wal_bytes disk.nats_bytes pg.db_bytes
js.bytes{stream} js.msgs{stream} js.pending{stream/consumer}
gen.cpu_cores gen.goroutines gen.sched_lag_p99_s
A measurement that cannot be taken is not an error: it is listed, with the reason, by Observer.Unavailable.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Interval is the sampling period; 5 s when zero.
Interval time.Duration
// ProfileEvery is the period of heap and goroutine profiles. Zero takes
// them only at the start and the end of the run.
ProfileEvery time.Duration
// ProfileDir is where profiles are written. Empty disables profiling.
ProfileDir string
// PostgresDSN, when set, adds pg.db_bytes: the size of the server's
// PostgreSQL database.
PostgresDSN string
}
Config configures an Observer.
type Observer ¶
type Observer struct {
// contains filtered or unexported fields
}
Observer samples a target into a recorder.
func (*Observer) CPUProfile ¶
CPUProfile fetches a CPU profile of d from the server into Config.ProfileDir. It blocks for d. A server without pprof is recorded as unavailable and returned as an error.
func (*Observer) Run ¶
Run samples until ctx ends: once immediately, then every Config.Interval, then once more after ctx ends. It returns nil when ctx ends, whether or not every measurement could be taken (see Unavailable); it returns an error only when the observer cannot be set up at all.
func (*Observer) SelfHealth ¶
func (o *Observer) SelfHealth() *SelfHealth
SelfHealth returns the generator's health record, which Run fills.
func (*Observer) Unavailable ¶
Unavailable lists the measurements that could not be taken, each as "<measurement>: <reason>", sorted and without duplicates.
type SelfHealth ¶
type SelfHealth struct {
// contains filtered or unexported fields
}
SelfHealth accumulates the generator's own CPU and schedule lag and decides whether the run it observed was valid. It is safe for concurrent use.
func (*SelfHealth) Record ¶
func (h *SelfHealth) Record(t time.Time, cpuCores, lagP99 float64)
Record adds one interval: the generator's CPU use in cores and the p99 lateness of its timers in seconds.
func (*SelfHealth) Valid ¶
func (h *SelfHealth) Valid(steadyFrom, until time.Time) (valid bool, reason string)
Valid reports whether the generator kept up, judged over the samples taken from steadyFrom up to and including until (a zero until has no end) on this machine's cores. A run passes the end of its measured window as until, so that samples taken while it tears down (a burst of work over a short last interval) do not count. A run is invalid when CPU use exceeded 85% of the cores, or p99 schedule lag exceeded one second, in more than 10% of those samples. The reason is empty for a valid run, and names every threshold hit, and by how much, for an invalid one. With no samples to judge it reports valid and says so.