Template reference

    Prometheus supports templating in the annotations and labels of alerts, as well as in served console pages. Templates have the ability to run queries against the local database, iterate over data, use conditionals, format data, etc. The Prometheus templating language is based on the system.

    The primary data structure for dealing with time series data is the sample, defined as:

    The metric name of the sample is encoded in a special label in the Labels map.

    []sample means a list of samples.

    In addition to the default functions provided by Go templating, Prometheus provides functions for easier processing of query results in templates.

    If functions are used in a pipeline, the pipeline value is passed as the last argument.

    first, label and value are intended to make query results easily usable in pipelines.

    Numbers

    Humanizing functions are intended to produce reasonable output for consumption by humans, and are not guaranteed to return the same results between Prometheus versions.

    Others

    , .Labels, and .ExternalLabels contain the alert value, the alert labels, and the globally configured external labels, respectively. They are also exposed as the $value, $labels, and $externalLabels variables for convenience.

    Console templates

    Consoles are exposed on /consoles/, and sourced from the directory pointed to by the -web.console.templates flag.

    Console templates are rendered with , which provides auto-escaping. To bypass the auto-escaping use the safe* functions.,

    URL parameters are available as a map in .Params. To access multiple URL parameters by the same name, .RawParams is a map of the list values for each parameter. The URL path is available in .Path, excluding the prefix. The globally configured external labels are available as .ExternalLabels. There are also convenience variables for all four: $rawParams, $params, $path, and $externalLabels.