output

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 MarshalYAML added in v0.18.0

func MarshalYAML(v any) ([]byte, error)

MarshalYAML encodes v as YAML, and writes each multi-line string value as a literal block ("key: |").

yaml.v3 writes a multi-line string as a literal block only when no line ends in a space. For other strings it writes one double-quoted line with "\n" escapes. Source code often has such lines, and a quoted line of code cannot be read or edited in the file that the create and update commands read back. The YAML specification permits trailing spaces in a literal block, so this function writes those blocks itself. The decoded value does not change.

Some strings stay quoted, because a literal block cannot hold them exactly: a carriage return or other control character, a Unicode line separator, or text whose first line with content starts with a space or tab or comes after a line of only spaces.

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