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) Connections ¶ added in v0.7.0
func (c *Collector) Connections() ConnSnapshot
Connections reports long-lived connection stats for the current generation.
func (*Collector) Middleware ¶
Middleware returns a handler that measures method, normalized path, protocol, status, duration, and response body bytes.
func (*Collector) Reset ¶
Reset atomically starts a new generation, waits for requests that started in the old one to finish, and returns the completed old generation.
type ConnSnapshot ¶ added in v0.7.0
type ConnSnapshot struct {
Total int64 `json:"total"`
Active int64 `json:"active"`
AvgSeconds float64 `json:"avg_seconds"`
P95Seconds float64 `json:"p95_seconds"`
MaxSeconds float64 `json:"max_seconds"`
BytesRead int64 `json:"bytes_read"`
BytesWritten int64 `json:"bytes_written"`
}
ConnSnapshot summarizes long-lived connections (WebSocket upgrades and text/event-stream responses) which are excluded from the latency table so they cannot distort p95/avg. Active spans generations; the rest reset with the generation.
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.
type Rule ¶
Rule replaces matching text in a request path. Supplying path rules disables the built-in numeric and UUID segment normalization.
func ParseRules ¶ added in v0.7.0
ParseRules parses an ISUTOOLS_PATH_RULES spec: semicolon-separated "regex=replacement" pairs, split on the LAST '=' so regexes may contain '='. Example: "^/@[^/]+$=/@*;^/posts/[0-9]+$=/posts/*".