promqlfmt

package module
v0.1.0 Latest Latest
Warning

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

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

README

promql-formatter-cli

A Go library and CLI for formatting (prettifying) PromQL queries.

It powers the promql-formatter Chrome extension and can also be used standalone.

Two backends are available:

Install

go install github.com/xhinliang/promql-formatter-cli/cmd/promql-formatter@latest

CLI usage

# format an argument (default backend: vic)
promql-formatter 'sum(rate(http_requests_total[1m])) by (job)'

# read from stdin, choose a backend
echo 'sum(rate(http_requests_total[1m])) by (job)' | promql-formatter --formatter main

Flags:

  • --formatter vic|main — choose the backend (default vic).
  • --version — print the version.

Library usage

import promqlfmt "github.com/xhinliang/promql-formatter-cli"

out, err := promqlfmt.Format(query, "vic") // or promqlfmt.FormatVic / promqlfmt.FormatMain

License

Apache-2.0. See LICENSE.

Acknowledgements

The main backend originates from the o11y.tools PromQL prettifier (Apache-2.0). The vic backend wraps VictoriaMetrics metricsql.

Documentation

Overview

Package promqlfmt formats PromQL queries.

Two backends are available:

  • "vic": VictoriaMetrics metricsql.Prettify (the default)
  • "main": a custom Prometheus-AST formatter with Grafana $variable support

Index

Constants

View Source
const (
	BackendVic  = "vic"
	BackendMain = "main"
)

Backend names accepted by Format.

Variables

This section is empty.

Functions

func Format

func Format(promql, backend string) (string, error)

Format formats promql using the named backend. An empty or unrecognized backend falls back to BackendVic.

func FormatMain

func FormatMain(promql string) (string, error)

formatPromql takes a PromQL query string and returns a "prettified" version.

func FormatVic

func FormatVic(promql string) (string, error)

Types

This section is empty.

Directories

Path Synopsis
cmd
promql-formatter command
Command promql-formatter formats a PromQL query taken from a positional argument or from stdin, using the "vic" backend by default.
Command promql-formatter formats a PromQL query taken from a positional argument or from stdin, using the "vic" backend by default.

Jump to

Keyboard shortcuts

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