variable
Example usage:
local g = import 'g.libsonnet';
local var = g.dashboard.variable;
local customVar =
var.custom.new(
'myOptions',
values=['a', 'b', 'c', 'd'],
)
+ var.custom.generalOptions.withDescription(
'This is a variable for my custom options.'
)
+ var.custom.selectionOptions.withMulti();
local queryVar =
var.query.new('queryOptions')
+ var.query.queryTypes.withLabelValues(
'up',
'instance',
)
+ var.query.withDatasource(
type='prometheus',
uid='mimir-prod',
)
+ var.query.selectionOptions.withIncludeAll();
g.dashboard.new('my dashboard')
+ g.dashboard.withVariables([
customVar,
queryVar,
])
Index
obj adhocobj constantobj customobj datasourceobj intervalobj queryobj textbox
Fields
obj adhoc
fn adhoc.new
adhoc.new(name, type, uid)
PARAMETERS:
- name (
string) - type (
string) - uid (
string)
new creates an adhoc template variable for datasource with type and uid.
fn adhoc.newFromDatasourceVariable
adhoc.newFromDatasourceVariable(name, variable)
PARAMETERS:
- name (
string) - variable (
object)
Same as new but selecting the datasource from another template variable.
obj adhoc.generalOptions
fn adhoc.generalOptions.withCurrent
adhoc.generalOptions.withCurrent(key, value="<same-as-key>")
PARAMETERS:
- key (
any) - value (
any)- default value:
"<same-as-key>"
- default value:
withCurrent sets the currently selected value of a variable. If key and value are different, both need to be given.
fn adhoc.generalOptions.withDescription
adhoc.generalOptions.withDescription(value)
PARAMETERS:
- value (
string)
Description of variable. It can be defined but null.
fn adhoc.generalOptions.withLabel
adhoc.generalOptions.withLabel(value)
PARAMETERS:
- value (
string)
Optional display name
fn adhoc.generalOptions.withName
adhoc.generalOptions.withName(value)
PARAMETERS:
- value (
string)
Name of variable
obj adhoc.generalOptions.showOnDashboard
fn adhoc.generalOptions.showOnDashboard.withLabelAndValue
adhoc.generalOptions.showOnDashboard.withLabelAndValue()
fn adhoc.generalOptions.showOnDashboard.withNothing
adhoc.generalOptions.showOnDashboard.withNothing()
fn adhoc.generalOptions.showOnDashboard.withValueOnly
adhoc.generalOptions.showOnDashboard.withValueOnly()
obj constant
fn constant.new
constant.new(name, value)
PARAMETERS:
- name (
string) - value (
string)
new creates a hidden constant template variable.
obj constant.generalOptions
fn constant.generalOptions.withCurrent
constant.generalOptions.withCurrent(key, value="<same-as-key>")
PARAMETERS:
- key (
any) - value (
any)- default value:
"<same-as-key>"
- default value:
withCurrent sets the currently selected value of a variable. If key and value are different, both need to be given.
fn constant.generalOptions.withDescription
constant.generalOptions.withDescription(value)
PARAMETERS:
- value (
string)
Description of variable. It can be defined but null.
fn constant.generalOptions.withLabel
constant.generalOptions.withLabel(value)
PARAMETERS:
- value (
string)
Optional display name
fn constant.generalOptions.withName
constant.generalOptions.withName(value)
PARAMETERS:
- value (
string)
Name of variable
obj constant.generalOptions.showOnDashboard
fn constant.generalOptions.showOnDashboard.withLabelAndValue
constant.generalOptions.showOnDashboard.withLabelAndValue()
fn constant.generalOptions.showOnDashboard.withNothing
constant.generalOptions.showOnDashboard.withNothing()
fn constant.generalOptions.showOnDashboard.withValueOnly
constant.generalOptions.showOnDashboard.withValueOnly()
obj custom
fn custom.new
custom.new(name, values)
PARAMETERS:
- name (
string) - values (
array)
new creates a custom template variable.
The values array accepts an object with key/value keys, if it's not an object then it will be added as a string.
Example:
[
{ key: 'mykey', value: 'myvalue' },
'myvalue',
12,
]
#### obj custom.generalOptions
##### fn custom.generalOptions.withCurrent
```jsonnet
custom.generalOptions.withCurrent(key, value="<same-as-key>")
PARAMETERS:
- key (
any) - value (
any)- default value:
"<same-as-key>"
- default value:
withCurrent sets the currently selected value of a variable. If key and value are different, both need to be given.
fn custom.generalOptions.withDescription
custom.generalOptions.withDescription(value)
PARAMETERS:
- value (
string)
Description of variable. It can be defined but null.
fn custom.generalOptions.withLabel
custom.generalOptions.withLabel(value)
PARAMETERS:
- value (
string)
Optional display name
fn custom.generalOptions.withName
custom.generalOptions.withName(value)
PARAMETERS:
- value (
string)
Name of variable
obj custom.generalOptions.showOnDashboard
fn custom.generalOptions.showOnDashboard.withLabelAndValue
custom.generalOptions.showOnDashboard.withLabelAndValue()
fn custom.generalOptions.showOnDashboard.withNothing
custom.generalOptions.showOnDashboard.withNothing()
fn custom.generalOptions.showOnDashboard.withValueOnly
custom.generalOptions.showOnDashboard.withValueOnly()
obj custom.selectionOptions
fn custom.selectionOptions.withIncludeAll
custom.selectionOptions.withIncludeAll(value=true, customAllValue)
PARAMETERS:
- value (
bool)- default value:
true
- default value:
- customAllValue (
string)
withIncludeAll enables an option to include all variables.
Optionally you can set a customAllValue.
fn custom.selectionOptions.withMulti
custom.selectionOptions.withMulti(value=true)
PARAMETERS:
- value (
bool)- default value:
true
- default value:
Enable selecting multiple values.
obj datasource
fn datasource.new
datasource.new(name, type)
PARAMETERS:
- name (
string) - type (
string)
new creates a datasource template variable.
fn datasource.withRegex
datasource.withRegex(value)
PARAMETERS:
- value (
string)
withRegex filter for which data source instances to choose from in the variable value list. Example: /^prod/
obj datasource.generalOptions
fn datasource.generalOptions.withCurrent
datasource.generalOptions.withCurrent(key, value="<same-as-key>")
PARAMETERS:
- key (
any) - value (
any)- default value:
"<same-as-key>"
- default value:
withCurrent sets the currently selected value of a variable. If key and value are different, both need to be given.
fn datasource.generalOptions.withDescription
datasource.generalOptions.withDescription(value)
PARAMETERS:
- value (
string)
Description of variable. It can be defined but null.
fn datasource.generalOptions.withLabel
datasource.generalOptions.withLabel(value)
PARAMETERS:
- value (
string)
Optional display name
fn datasource.generalOptions.withName
datasource.generalOptions.withName(value)
PARAMETERS:
- value (
string)
Name of variable
obj datasource.generalOptions.showOnDashboard
fn datasource.generalOptions.showOnDashboard.withLabelAndValue
datasource.generalOptions.showOnDashboard.withLabelAndValue()
fn datasource.generalOptions.showOnDashboard.withNothing
datasource.generalOptions.showOnDashboard.withNothing()
fn datasource.generalOptions.showOnDashboard.withValueOnly
datasource.generalOptions.showOnDashboard.withValueOnly()
obj datasource.selectionOptions
fn datasource.selectionOptions.withIncludeAll
datasource.selectionOptions.withIncludeAll(value=true, customAllValue)
PARAMETERS:
- value (
bool)- default value:
true
- default value:
- customAllValue (
string)
withIncludeAll enables an option to include all variables.
Optionally you can set a customAllValue.
fn datasource.selectionOptions.withMulti
datasource.selectionOptions.withMulti(value=true)
PARAMETERS:
- value (
bool)- default value:
true
- default value:
Enable selecting multiple values.
obj interval
fn interval.new
interval.new(name, values)
PARAMETERS:
- name (
string) - values (
array)
new creates an interval template variable.
fn interval.withAutoOption
interval.withAutoOption(count, minInterval)
PARAMETERS:
- count (
number) - minInterval (
string)
withAutoOption adds an options to dynamically calculate interval by dividing time range by the count specified.
`minInterval' has to be either unit-less or end with one of the following units: "y, M, w, d, h, m, s, ms".
obj interval.generalOptions
fn interval.generalOptions.withCurrent
interval.generalOptions.withCurrent(key, value="<same-as-key>")
PARAMETERS:
- key (
any) - value (
any)- default value:
"<same-as-key>"
- default value:
withCurrent sets the currently selected value of a variable. If key and value are different, both need to be given.
fn interval.generalOptions.withDescription
interval.generalOptions.withDescription(value)
PARAMETERS:
- value (
string)
Description of variable. It can be defined but null.
fn interval.generalOptions.withLabel
interval.generalOptions.withLabel(value)
PARAMETERS:
- value (
string)
Optional display name
fn interval.generalOptions.withName
interval.generalOptions.withName(value)
PARAMETERS:
- value (
string)
Name of variable
obj interval.generalOptions.showOnDashboard
fn interval.generalOptions.showOnDashboard.withLabelAndValue
interval.generalOptions.showOnDashboard.withLabelAndValue()
fn interval.generalOptions.showOnDashboard.withNothing
interval.generalOptions.showOnDashboard.withNothing()
fn interval.generalOptions.showOnDashboard.withValueOnly
interval.generalOptions.showOnDashboard.withValueOnly()
obj query
fn query.new
query.new(name, query="")
PARAMETERS:
- name (
string) - query (
string)- default value:
""
- default value:
Create a query template variable.
query argument is optional, this can also be set with query.queryTypes.
fn query.withDatasource
query.withDatasource(type, uid)
PARAMETERS:
- type (
string) - uid (
string)
Select a datasource for the variable template query.
fn query.withDatasourceFromVariable
query.withDatasourceFromVariable(variable)
PARAMETERS:
- variable (
object)
Select the datasource from another template variable.
fn query.withRegex
query.withRegex(value)
PARAMETERS:
- value (
string)
withRegex can extract part of a series name or metric node segment. Named capture groups can be used to separate the display text and value (see examples).
fn query.withSort
query.withSort(i=0, type="alphabetical", asc=true, caseInsensitive=false)
PARAMETERS:
- i (
number)- default value:
0
- default value:
- type (
string)- default value:
"alphabetical"
- default value:
- asc (
bool)- default value:
true
- default value:
- caseInsensitive (
bool)- default value:
false
- default value:
Choose how to sort the values in the dropdown.
This can be called as withSort(<number>) to use the integer values for each option. Ifi==0` then it will be ignored and the other arguments will take precedence.
The numerical values are:
- 1 - Alphabetical (asc)
- 2 - Alphabetical (desc)
- 3 - Numerical (asc)
- 4 - Numerical (desc)
- 5 - Alphabetical (case-insensitive, asc)
- 6 - Alphabetical (case-insensitive, desc)
obj query.generalOptions
fn query.generalOptions.withCurrent
query.generalOptions.withCurrent(key, value="<same-as-key>")
PARAMETERS:
- key (
any) - value (
any)- default value:
"<same-as-key>"
- default value:
withCurrent sets the currently selected value of a variable. If key and value are different, both need to be given.
fn query.generalOptions.withDescription
query.generalOptions.withDescription(value)
PARAMETERS:
- value (
string)
Description of variable. It can be defined but null.
fn query.generalOptions.withLabel
query.generalOptions.withLabel(value)
PARAMETERS:
- value (
string)
Optional display name
fn query.generalOptions.withName
query.generalOptions.withName(value)
PARAMETERS:
- value (
string)
Name of variable
obj query.generalOptions.showOnDashboard
fn query.generalOptions.showOnDashboard.withLabelAndValue
query.generalOptions.showOnDashboard.withLabelAndValue()
fn query.generalOptions.showOnDashboard.withNothing
query.generalOptions.showOnDashboard.withNothing()
fn query.generalOptions.showOnDashboard.withValueOnly
query.generalOptions.showOnDashboard.withValueOnly()
obj query.queryTypes
fn query.queryTypes.withLabelValues
query.queryTypes.withLabelValues(label, metric="")
PARAMETERS:
- label (
string) - metric (
string)- default value:
""
- default value:
Construct a Prometheus template variable using label_values().
fn query.queryTypes.withQueryResult
query.queryTypes.withQueryResult(query)
PARAMETERS:
- query (
string)
Construct a Prometheus template variable using query_result().
obj query.refresh
fn query.refresh.onLoad
query.refresh.onLoad()
Refresh label values on dashboard load.
fn query.refresh.onTime
query.refresh.onTime()
Refresh label values on time range change.
obj query.selectionOptions
fn query.selectionOptions.withIncludeAll
query.selectionOptions.withIncludeAll(value=true, customAllValue)
PARAMETERS:
- value (
bool)- default value:
true
- default value:
- customAllValue (
string)
withIncludeAll enables an option to include all variables.
Optionally you can set a customAllValue.
fn query.selectionOptions.withMulti
query.selectionOptions.withMulti(value=true)
PARAMETERS:
- value (
bool)- default value:
true
- default value:
Enable selecting multiple values.
obj textbox
fn textbox.new
textbox.new(name, default="")
PARAMETERS:
- name (
string) - default (
string)- default value:
""
- default value:
new creates a textbox template variable.
obj textbox.generalOptions
fn textbox.generalOptions.withCurrent
textbox.generalOptions.withCurrent(key, value="<same-as-key>")
PARAMETERS:
- key (
any) - value (
any)- default value:
"<same-as-key>"
- default value:
withCurrent sets the currently selected value of a variable. If key and value are different, both need to be given.
fn textbox.generalOptions.withDescription
textbox.generalOptions.withDescription(value)
PARAMETERS:
- value (
string)
Description of variable. It can be defined but null.
fn textbox.generalOptions.withLabel
textbox.generalOptions.withLabel(value)
PARAMETERS:
- value (
string)
Optional display name
fn textbox.generalOptions.withName
textbox.generalOptions.withName(value)
PARAMETERS:
- value (
string)
Name of variable
obj textbox.generalOptions.showOnDashboard
fn textbox.generalOptions.showOnDashboard.withLabelAndValue
textbox.generalOptions.showOnDashboard.withLabelAndValue()
fn textbox.generalOptions.showOnDashboard.withNothing
textbox.generalOptions.showOnDashboard.withNothing()
fn textbox.generalOptions.showOnDashboard.withValueOnly
textbox.generalOptions.showOnDashboard.withValueOnly()