How can I show InfluxDb tags only for todays date?

Viewed 4402

I am having trouble getting this query in InfluxDb to work properly. Wondering if someone can help.

I want to show tag values but only for the current days data. I have this

SHOW TAG VALUES FROM table WITH KEY = "name"

This list shows all values from the full measurement. I want to only show values for data that was inserted today.

I've tried

  SHOW TAG VALUES FROM table WITH KEY = "name" where date='2018-10-23'
  SHOW TAG VALUES FROM table WITH KEY = "name" where time='2018-10-23'

as well as some other variations but can't seem to get this right. Does anyone know how to properly form this query?

I am using this as a variable inside Grafana.

Thanks

4 Answers

For select time you mast define time range, start and end. This is working solution.

SHOW TAG VALUES FROM table WITH KEY = "name" where time>='2020-04-26T00:00:00Z' AND time<'2020-04-27T00:00:00Z'

how about use subquery? instead of "show tag values" like this

# show tag values from with key = “TAGName” where condition
select TagName from (select field, TagName from Measurement where condition)

it return timestamp with tag values

Can't upvote answer https://stackoverflow.com/a/58404465/18224224 but this solution has worked for me.

select "tag_name" from (select "field_value", "tag_name" from "table" WHERE "tag_name_filter" = 'tag_value_filter' AND  $timeFilter group by "tag_name" LIMIT 1)

$timefilter variable will automatically use dashboard time range selected if variable uses refresh : on time range change

Grafana Dashboard variables screenshot

Grafana Dashboard variables screenshot with different time range selected in dashboard

Related