Documentation
¶
Overview ¶
Package metrics scrapes an app's own metrics endpoint and parses the text exposition format into capped, validated samples.
Index ¶
- Variables
- func ErrorMessage(err error) string
- func NewClient(timeout time.Duration) *http.Client
- func ParseText(r io.Reader, lim Limits) ([]Sample, Stats)
- func Scrape(ctx context.Context, client *http.Client, target string, lim Limits) ([]Sample, Stats, error)
- func TargetURL(ip string, port int, path string) (string, error)
- func ValidName(s string) bool
- func ValidatePath(p string) error
- func ValidatePort(port int) error
- type Limits
- type Sample
- type Stats
- type StatusError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBodyTooLarge fails a scrape whose body is over the limit; nothing is stored. ErrBodyTooLarge = errors.New("metrics: response body exceeds the size limit") // ErrRedirect fails a scrape that answered with a redirect. ErrRedirect = errors.New("metrics: redirects are refused") // ErrBadTarget fails a target outside the app's private network. ErrBadTarget = errors.New("metrics: target is not an app network address") )
Functions ¶
func ErrorMessage ¶
ErrorMessage maps a scrape failure to a fixed message, so stored and shown errors never carry the container address or raw transport text.
func ParseText ¶
ParseText parses exposition text, dropping invalid lines and stopping at MaxSeries.
func Scrape ¶
func Scrape(ctx context.Context, client *http.Client, target string, lim Limits) ([]Sample, Stats, error)
Scrape fetches target and parses the body within lim.
func TargetURL ¶
TargetURL builds the scrape URL from the container's own network address only. A non-private address is refused so a bad lookup can never reach the outside.
func ValidatePath ¶
ValidatePath accepts a plain absolute path with no query, host or traversal parts.
Types ¶
type Limits ¶
type Limits struct {
Timeout time.Duration
MaxBodyBytes int64
MaxSeries int
MaxLabels int
// MaxLabelBytes caps the canonical label text of one whole scrape.
MaxLabelBytes int
}
Limits bound one scrape; every field comes from runtime settings.
type StatusError ¶
type StatusError struct{ Code int }
StatusError is a scrape that answered something other than 200.
func (StatusError) Error ¶
func (e StatusError) Error() string