How to filter grafana dashboard with greater than and less than operators?

£可爱£侵袭症+ 提交于 2021-01-28 01:44:41

问题


I'm working on a project where I'm using Grafana and InfluxdB. I was able to get all the required values to grafana.

In my response I have a filed with value less than and greater than zero. I want to add a filter where user can select the type of operation.

Any recommendation on how to crack this.

So far I have tried..

I created a Variable (constant value 0, which i tried to use in my dashboard query with less than or greater than operator. As soon as I select my variable, the operator gets changed to 'equal to' or 'not equal to'.

By providing the value directly in the query works fine.

Query reflected Using the variable which i created as constant

SELECT "servicename" AS "Service Name", "topic" AS "Topic", "type" AS "Type", "count" AS "Count" FROM "KafkaLag" WHERE ("servicename" =~ /^$servicename$/ AND "topic" =~ /^$topic$/ AND "type" =~ /^$type$/ AND "count" =~ /^$Greater_than_zero$/) AND $timeFilter ORDER BY time DESC

Query reflected using value directly without any variable

SELECT "servicename" AS "Service Name", "topic" AS "Topic", "type" AS "Type", "count" AS "Count" FROM "KafkaLag" WHERE ("servicename" =~ /^$servicename$/ AND "topic" =~ /^$topic$/ AND "type" =~ /^$type$/ AND "count" > 0) AND $timeFilter ORDER BY time DESC

From the below table I need a way to put a dynamic filter on field_2 where I can get greater than zero values when required.

time | field_1 | field_2 
  t1 |   v1    |    0 
  t1 |   v2    |    2 
  t2 |   v3    |    0 
  t2 |   v4    |    12

回答1:


select * from <table/measurement name> where field_2 > 0;

This query will filter data as per you need.




回答2:


This may be late answer but this is how I have done it earlier. Create a variable count, type "custom". Then, use that variable as below in query-

SELECT "service_name" FROM service  WHERE ("count" >=$count) AND $timeFilter


来源:https://stackoverflow.com/questions/56648433/how-to-filter-grafana-dashboard-with-greater-than-and-less-than-operators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!