Documentation
¶
Overview ¶
Package httpstats provides bounded, in-memory HTTP request measurements. It deliberately records URL paths, never query strings.
Index ¶
Constants ¶
const ( // DefaultMaxKeys is the maximum number of distinct HTTP identities held by // a Collector. New identities past the limit are merged into OverflowPath. DefaultMaxKeys = 10000 // OverflowPath identifies observations merged after the key limit. OverflowPath = "(other)" )
Variables ¶
var Default = New()
Default is used by the package-level Middleware helper.
Functions ¶
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector owns HTTP measurements and generation boundaries. Reset swaps in a fresh table and waits for requests already in flight, then returns their completed generation.
func (*Collector) Middleware ¶
Middleware returns a handler that measures method, normalized path, protocol, status, duration, and response body bytes.
type Entry ¶
type Entry struct {
Key string `json:"key"`
Method string `json:"method"`
Path string `json:"path"`
Protocol string `json:"protocol"`
Status int `json:"status"`
Count int64 `json:"count"`
Total time.Duration `json:"total_ns"`
Avg time.Duration `json:"avg_ns"`
Max time.Duration `json:"max_ns"`
P95 time.Duration `json:"p95_ns"`
TotalBytes int64 `json:"total_bytes"`
AvgBytes int64 `json:"avg_bytes"`
}
Entry is one aggregated HTTP identity. Duration fields are encoded as integer nanoseconds in JSON. P95 is the upper bound of a log2 bucket.
type Option ¶
type Option func(*config)
Option configures a Collector.
func WithMaxKeys ¶
WithMaxKeys changes the distinct-key limit. A value of zero merges every observation into the overflow entry. Negative values are ignored.
func WithPathRules ¶
WithPathRules replaces the built-in path normalization with rules applied in order. Rules with a nil Pattern are ignored.