debian-mirror-gitlab/doc/operations/metrics/dashboards/variables.md

79 lines
2.9 KiB
Markdown
Raw Normal View History

2020-07-28 23:09:34 +05:30
---
stage: Monitor
2022-04-04 11:22:00 +05:30
group: Respond
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2020-07-28 23:09:34 +05:30
---
2022-03-02 08:16:31 +05:30
# Using variables (DEPRECATED) **(FREE)**
> [Deprecated](https://gitlab.com/gitlab-org/gitlab/-/issues/346541) in GitLab 14.7.
WARNING:
This feature is in its end-of-life process. It is [deprecated](https://gitlab.com/gitlab-org/gitlab/-/issues/346541)
2022-06-21 17:19:12 +05:30
in GitLab 14.7, and is planned for removal in GitLab 16.0.
2020-07-28 23:09:34 +05:30
2020-10-24 23:57:45 +05:30
## Query variables
2020-07-28 23:09:34 +05:30
2021-11-18 22:05:49 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/20793) in GitLab 12.7.
Variables can be specified using double curly braces, such as `"{{ci_environment_slug}}"`.
2020-07-28 23:09:34 +05:30
Support for the `"%{ci_environment_slug}"` format was
[removed](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/31581) in GitLab 13.0.
2021-02-22 17:27:13 +05:30
Queries that continue to use the old format display no data.
2020-07-28 23:09:34 +05:30
## Predefined variables
2021-09-30 23:02:18 +05:30
GitLab supports a limited set of [CI/CD variables](../../../ci/variables/index.md)
2021-01-03 14:25:43 +05:30
in the Prometheus query. This is particularly useful for identifying a specific
environment, for example with `ci_environment_slug`. Variables for Prometheus queries
must be lowercase. The supported variables are:
2020-07-28 23:09:34 +05:30
2020-11-24 15:15:51 +05:30
- `environment_filter`
2020-07-28 23:09:34 +05:30
- `ci_environment_slug`
- `kube_namespace`
- `ci_project_name`
- `ci_project_namespace`
- `ci_project_path`
- `ci_environment_name`
- `__range`
2023-03-04 22:38:38 +05:30
### `environment_filter`
2020-11-24 15:15:51 +05:30
`environment_filter` is automatically expanded to `container_name!="POD",environment="ENVIRONMENT_NAME"`
where `ENVIRONMENT_NAME` is the name of the current environment.
For example, a Prometheus query like `container_memory_usage_bytes{ {{environment_filter}} }`
becomes `container_memory_usage_bytes{ container_name!="POD",environment="production" }`.
2023-03-04 22:38:38 +05:30
### `__range`
2020-07-28 23:09:34 +05:30
The `__range` variable is useful in Prometheus
[range vector selectors](https://prometheus.io/docs/prometheus/latest/querying/basics/#range-vector-selectors).
Its value is the total number of seconds in the dashboard's time range.
For example, if the dashboard time range is set to 8 hours, the value of
`__range` is `28800s`.
## User-defined variables
[Variables can be defined](../../../operations/metrics/dashboards/yaml.md#templating-templating-properties) in a custom dashboard YAML file.
2021-01-29 00:20:46 +05:30
Variable names are case-sensitive.
2020-10-24 23:57:45 +05:30
## Query variables from URL
2020-07-28 23:09:34 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/214500) in GitLab 13.0.
GitLab supports setting custom variables through URL parameters. Surround the variable
name with double curly braces (`{{example}}`) to interpolate the variable in a query:
```plaintext
avg(sum(container_memory_usage_bytes{container_name!="{{pod}}"}) by (job)) without (job) /1024/1024/1024'
```
The URL for this query would be:
```plaintext
2021-11-18 22:05:49 +05:30
https://gitlab.com/<user>/<project>/-/environments/<environment_id>/metrics?dashboard=.gitlab%2Fdashboards%2Fcustom.yml&pod=POD
2020-07-28 23:09:34 +05:30
```