output

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatPromQLResult added in v0.5.0

func FormatPromQLResult(w io.Writer, warnOut io.Writer, format Format, parsed any) (bool, error)

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

func Print(w io.Writer, format Format, data any, columns []Column) error

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

type Column struct {
	Header string
	Field  string
}

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.

const (
	FormatTable Format = "table"
	FormatJSON  Format = "json"
	FormatYAML  Format = "yaml"
	FormatCSV   Format = "csv"
	FormatGraph Format = "graph"
	FormatStats Format = "stats"
)

func DetectFormat

func DetectFormat(outputFlag string) Format

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

type PromSample struct {
	Timestamp float64
	Value     float64
}

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": [...]
  }
}

type SeriesStats added in v0.5.0

type SeriesStats struct {
	Labels  string
	Samples int
	Min     float64
	Max     float64
	Avg     float64
	Current float64
	Start   time.Time
	End     time.Time
	Trend   string
}

SeriesStats holds computed statistics for a single time series.

Jump to

Keyboard shortcuts

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