Templating variables for metrics dashboards

原文:https://docs.gitlab.com/ee/operations/metrics/dashboards/templating_variables.html

Templating variables for metrics dashboards

在 GitLab 13.0 中引入 .

模板变量可用于使指标仪表板更加通用.

templating仪表板 YAML 中的顶级键. 在templating下的variables键中定义变量. variables键的值应为哈希, variables下的每个键在仪表板上定义一个模板变量,并且可以包含字母数字和下划线字符.

可以使用使用变量中所述的语法在同一仪表板的 Prometheus 查询中使用变量 .

text variable type

警告:此变量类型是alpha功能,如有更改,恕不另行通知!

对于仪表板 YAML 中定义的每个text变量,仪表板 UI 上都会有一个自由文本框,您可以为每个变量输入一个值.

text变量类型支持简单和完整的语法.

Simple syntax

本示例创建一个名为variable1 ,其默认值为default value

  1. templating:
  2. variables:
  3. variable1: 'default value' # `text` type variable with `default value` as its default.

Full syntax

本示例创建一个名为variable1 ,其默认值为default . UI 上文本框的标签将为label键的值:

  1. templating:
  2. variables:
  3. variable1: # The variable name that can be used in queries.
  4. label: 'Variable 1' # (Optional) label that will appear in the UI for this text box.
  5. type: text
  6. options:
  7. default_value: 'default' # (Optional) default value.

custom variable type

警告:此变量类型是alpha功能,如有更改,恕不另行通知!

仪表板 YAML 中定义的每个custom变量都会在仪表板 UI 上创建一个下拉选择器,允许您为每个变量选择一个值.

custom变量类型支持简单和完整的语法.

Simple syntax

本示例创建一个名为variable1 ,其默认值为value1 . 仪表板界面将显示一个下拉列表,其中包含value1value2value3作为选择.

  1. templating:
  2. variables:
  3. variable1: ['value1', 'value2', 'value3']

Full syntax

本示例创建一个名为variable1 ,其默认值为value_option_2 . UI 上文本框的标签将为label键的值. 仪表板界面将显示一个下拉列表,其中包含Option 1Option 2 .

如果从下拉列表中选择Option 1 ,则变量将被替换为value option 1 . 同样,如果选择Option 2 ,则变量将替换为value_option_2

  1. templating:
  2. variables:
  3. variable1: # The variable name that can be used in queries.
  4. label: 'Variable 1' # (Optional) label that will appear in the UI for this dropdown.
  5. type: custom
  6. options:
  7. values:
  8. - value: 'value option 1' # The value that will replace the variable in queries.
  9. text: 'Option 1' # (Optional) Text that will appear in the UI dropdown.
  10. - value: 'value_option_2'
  11. text: 'Option 2'
  12. default: true # (Optional) This option should be the default value of this variable.

metric_label_values variable type

警告:此变量类型是alpha功能,如有更改,恕不另行通知!

Full syntax

本示例创建一个名为variable2 . 下拉列表的值将是up{env="production"}描述的 Prometheus 系列中backend标签的所有不同值.

  1. templating:
  2. variables:
  3. variable2: # The variable name that can be interpolated in queries.
  4. label: 'Variable 2' # (Optional) label that will appear in the UI for this dropdown.
  5. type: metric_label_values
  6. options:
  7. series_selector: 'up{env="production"}'
  8. label: 'backend'