如何在查询中使用选定的时间段? [英] How to use the selected period of time in a query?

查看:117
本文介绍了如何在查询中使用选定的时间段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Grafana与Prometheus结合使用,我想构建查询,具体取决于在屏幕右上角选择的选定时间段.

I'm using Grafana with Prometheus and I'd like to build a query that depends on the selected period of time selected in the upper right corner of the screen.

查询字段中是否有任何变量(或类似的东西)要使用?

Is there any variable (or something like that) to use in the query field?

换句话说,如果我选择24小时,我想在查询中使用该数据.

In other words, If I select 24hs I'd like to use that data in the query.

推荐答案

我知道两种方法:

  1. 您可以使用 $ __ interval 变量,例如这个:

increase(http_requests_total[$__interval])

缺点是$ __ interval变量的值可以通过图形的分辨率进行调整,但这在某些情况下也可能会有所帮助.

There is a drawback that the $__interval variable's value is adjusted by resolution of the graph, but this may also be helpful in some situations.

  1. 这种方法应该更适合您的情况:

转到仪表板的模板化设置,创建类型为时间间隔.启用自动选项",将步数"调整为等于1.然后,确保在仪表板顶部的相应下拉列表中选择了自动".

Go to Dashboard's Templating settings, create new variable with the type of Interval. Enable "Auto Option", adjust "Step count" to be equal 1. Then ensure that the "auto" is selected in corresponding drop-down list at the top of the dashboard.

假设您将其命名为timeRange,则查询将如下所示:

Let's assume you name it timeRange, then the query will look like this:

increase(http_requests_total[$timeRange])

此变量将不会通过图形分辨率进行调整,如果您选择过去10小时",其值将为10h.

This variable will not be adjusted by graph resolution and if you select "Last 10 hours" its value will be 10h.

这篇关于如何在查询中使用选定的时间段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆