Documentation
¶
Index ¶
- func FormatPromQLResult(w io.Writer, warnOut io.Writer, format Format, parsed any) (bool, error)
- func Print(w io.Writer, format Format, data any, columns []Column) error
- func PrintGraph(w io.Writer, series []PromSeries) error
- func PrintStats(w io.Writer, series []PromSeries) error
- type Column
- type Format
- type PromSample
- type PromSeries
- type SeriesStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatPromQLResult ¶ added in v0.5.0
FormatPromQLResult detects the Prometheus result type from a parsed response and renders it as a human-readable table (or CSV). If the response does not look like a Prometheus result, it returns false and the caller should fall back to generic formatting.
Any warnings present in the response are written to warnOut (typically stderr) so they remain visible even when the main output is piped.
Supported resultTypes: vector, matrix, scalar, string.
func Print ¶
Print writes data in the requested format to w. For table and CSV, data must be a slice; single objects can be wrapped in a one-element slice. If table or CSV is requested but no columns are defined (e.g. for free-form map[string]interface{} responses), Print falls back to JSON so the user sees something useful rather than a blank screen.
func PrintGraph ¶ added in v0.5.0
func PrintGraph(w io.Writer, series []PromSeries) error
PrintGraph renders one or more Prometheus time series as a terminal line chart using braille characters (via ntcharts). It writes the chart to w, using terminal width/height for sizing when available.
func PrintStats ¶ added in v0.5.0
func PrintStats(w io.Writer, series []PromSeries) error
PrintStats renders one or more Prometheus time series as a compact statistical summary designed for consumption by AI agents and scripts. Each series gets one line with labels, sample count, min/max/avg/current values, and a trend indicator.
Types ¶
type Column ¶
Column describes one column of a table/CSV. Field is the Go struct field name (case-insensitive match).
type Format ¶
type Format string
Format identifies an output format.
func DetectFormat ¶
DetectFormat returns the format to use given the value of an --output flag. If the flag is non-empty it wins. Otherwise we pick `table` for TTYs and `json` for non-TTY output (pipes, files).
type PromSample ¶ added in v0.5.0
PromSample is a single data point in a time series.
type PromSeries ¶ added in v0.5.0
type PromSeries struct {
// Labels is the metric label set (e.g. {handler="/api/v1/query"}).
Labels map[string]string
// Values is the ordered list of (timestamp, value) pairs.
Values []PromSample
}
PromSeries represents a single time series from a Prometheus matrix result.
func ParsePromResponse ¶ added in v0.5.0
func ParsePromResponse(parsed any) ([]PromSeries, error)
ParsePromResponse extracts time series data from a parsed Prometheus API response body. It handles both "matrix" (range query) and "vector" (instant query) result types.
The expected structure is:
{
"status": "success",
"data": {
"resultType": "matrix" | "vector",
"result": [...]
}
}