A variable in Perses is a dynamic configuration element that allows you to create interactive and reusable dashboards. Variables act as parameters that can be modified by users to filter data, change query scopes, or customize dashboard views without editing the underlying dashboard configuration.
Perses supports several types of variables to meet different use cases:
- Text Variable – for static string values that can be constant or user-editable.
- List Variable – for dynamic dropdown selections, powered by plugins.
Variables are generally defined as part of a dashboard, but you also have the option to configure them at higher scopes for reusability. More details about scopes at Datasource & Variable scopes.
Once defined, variables can be used in places like:
- Query expressions.
- Other variables to create cascading dropdowns where one variable filters another.
- Panel titles and descriptions.
Variables can be referenced using one of the following syntax:
$variableName${variableName}${variableName:format}: this allows to define custom interpolation formats.
The format syntax ${variableName:format} allows you to define custom interpolation. The following formats are supported:
-
default format
pair: ['perses', 'prometheus'] "${pair}" => "(perses|prometheus)" -
csv: Comma-separated valuessuperheroes: ['perses', 'prometheus'] "Who saves the monitoring world? ${superheroes:csv}!" => "Who saves the monitoring world? perses,prometheus!" -
distributed: Distributed format for key=value pairsmetrics: ['perses', 'prometheus'] "The dream team: ${metrics:distributed}" => "The dream team: perses,metrics=prometheus" -
doublequote: Double-quoted stringsdatabases: ['perses', 'prometheus'] "My favorite tools are ${databases:doublequote}" => "My favorite tools are \"perses\",\"prometheus\"" -
glob: Glob pattern matchingservices: ['perses', 'prometheus'] "Find all services: ${services:glob}" => "Find all services: {perses,prometheus}" -
json: JSON array formatplatforms: ['perses', 'prometheus'] "Available platforms: ${platforms:json}" => "Available platforms: [\"perses\",\"prometheus\"]" -
lucene: Lucene query syntaxtools: ['perses', 'prometheus'] "${tools:lucene}" => "(perses OR prometheus)" -
percentencode: Percent-encoded (URL-encoded) formatnames: ['perses the great', 'prometheus & fire'] "search?q=${names:percentencode}" => "search?q=perses%20the%20great,prometheus%20%26%20fire" -
pipe: Pipe-separated valuesmonitoring_stack: ['perses', 'prometheus'] "The ultimate stack: ${monitoring_stack:pipe}" => "The ultimate stack: perses|prometheus" -
raw: Raw format (no escaping)raw_data: ['perses*', 'prometheus+'] "${raw_data:raw}" => "perses*prometheus+" -
regex: Regular expression formatpatterns: ['perses.chart', 'prometheus'] "${patterns:regex}" => "(perses\.chart|prometheus)" -
singlequote: Single-quoted stringsfavorites: ['perses', 'prometheus'] "My picks: ${favorites:singlequote}" => "My picks: 'perses','prometheus'" -
sqlstring: SQL string formattools: ['perses', 'prometheus'] "SELECT * FROM tools WHERE name IN (${tools:sqlstring})" => "SELECT * FROM tools WHERE name IN ('perses','prometheus')" -
text: Plain text formatprojects: ['perses', 'prometheus'] "Working on ${projects:text} rocks!" => "Working on perses + prometheus rocks!" -
queryparam: Query parameter formatfilters: ['perses', 'prometheus'] "/api/data?filter=${filters:queryparam}" => "/api/data?filter=perses&filter=prometheus"
