promclient

package
v1.31.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

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

func NewClient(baseURL string, timeout time.Duration) *Client

NewClient creates a new Client. If timeout is 0 or negative, defaultTimeout (30s) is used.

func (*Client) Alerts added in v1.20.0

func (c *Client) Alerts(ctx context.Context) ([]Alert, error)

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

func (c *Client) GetJSON(ctx context.Context, path string, dest any) error

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

func (c *Client) MetricNames(ctx context.Context) ([]string, error)

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.

func (*Client) QueryRange

func (c *Client) QueryRange(ctx context.Context, query string, start, end time.Time, step time.Duration) (*QueryRangeResponse, error)

QueryRange executes a range query against the Prometheus HTTP API v1. step must be >= 1µs and end must be after start.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL