Documentation
¶
Index ¶
- type Alert
- type Client
- func (c *Client) Alerts(ctx context.Context) ([]Alert, error)
- func (c *Client) GetJSON(ctx context.Context, path string, dest any) error
- func (c *Client) MetricNames(ctx context.Context) ([]string, error)
- func (c *Client) QueryRange(ctx context.Context, query string, start, end time.Time, step time.Duration) (*QueryRangeResponse, error)
- type QueryRangeResponse
- type SeriesResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alert ¶ added in v1.20.0
type Alert struct {
Labels map[string]string `json:"labels"`
Annotations map[string]string `json:"annotations"`
State string `json:"state"` // "firing"|"pending"|"inactive"
ActiveAt string `json:"activeAt"`
Value string `json:"value"`
}
Alert represents a single Prometheus alerting rule result from /api/v1/alerts.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a minimal HTTP client for the Prometheus query API.
func NewClient ¶
NewClient creates a new Client. If timeout is 0 or negative, defaultTimeout (30s) is used.
func (*Client) Alerts ¶ added in v1.20.0
Alerts queries /api/v1/alerts and returns all alert instances regardless of state. Callers should filter by State == "firing" for actionable alerts.
func (*Client) GetJSON ¶ added in v1.20.0
GetJSON performs a GET request to the given path (relative to baseURL), decodes the JSON response body into dest, and returns any error. Delegates to httputil.Client to avoid duplicating http+json plumbing.
func (*Client) MetricNames ¶ added in v1.20.0
MetricNames fetches the list of all metric names from Prometheus (/api/v1/label/__name__/values). Returns empty slice on error. This is the single source of truth for metric name discovery — callers should fetch once and pass the result to discover* filter functions.
type QueryRangeResponse ¶
type QueryRangeResponse struct {
Status string `json:"status"`
Data struct {
ResultType string `json:"resultType"`
Result []SeriesResult `json:"result"`
} `json:"data"`
}
QueryRangeResponse is the top-level response from the Prometheus /api/v1/query_range endpoint.
type SeriesResult ¶
type SeriesResult struct {
Metric map[string]string `json:"metric"`
// Values contains [timestamp, value] pairs where timestamp is a float64
// and value is a string-encoded float.
Values [][2]any `json:"values"`
}
SeriesResult holds one time series from a matrix query result.