Grafana InfluxDB SingleStat Date Calculation [duplicate] - influxdb

Is it possible to use the time field in a single stat panel in grafana?
I understand you cannot only query the time field in influxdb, but I can get the time of the stat I'm interested in like so:
select time, last(context_id) from "data_context"
And just need a way to show the time field from the execution of the query.

This is quiet often asked on stack overflow, but it is not possible at the moment. But there are open Feature requests for this on github:
[Feature request] Show timestamp on SingleStat #6710
Showing time from InfluxDB query in Singlestat panel #2764

Related

How do you add a query for data grouped by a regex in influxdb to grafana?

So my main goal is to build a graph that charts how much data I've went through in a month in grafana (I'm on a comcast line).
Month is not a time period however that influxdb's GROUP BY time() function supports. The documentation I looked at. From here it looks like the longest time period is a week, likely because it doesn't change like a month does.
However I noticed that all my time stamps use the same format (it would be weird if they didn't I guess). I know that influxdb supports regex FROM and WHERE statements, but does it support GROUP BY? If it did, I could use something like "/-([^-]+)-/" to query timestamps like 2016-12-18T08:25:50Z and group by that? Or does influxdb support nested queries?
edit: looks like I was looking at .9. I edited to 1.1 but didn't edit anything about my question.
GROUP BY time() queries group query results by a user-specified time interval
I'm not really sure how that would work for a month considering that my length of time changes?
No version of InfluxDB supports GROUP BY <regular expression>, but as on 1.2 subqueries will be supported.

Use time field from influxdb in grafana single stat

Is it possible to use the time field in a single stat panel in grafana?
I understand you cannot only query the time field in influxdb, but I can get the time of the stat I'm interested in like so:
select time, last(context_id) from "data_context"
And just need a way to show the time field from the execution of the query.
This is quiet often asked on stack overflow, but it is not possible at the moment. But there are open Feature requests for this on github:
[Feature request] Show timestamp on SingleStat #6710
Showing time from InfluxDB query in Singlestat panel #2764

How to show the most recent timestamp for an InfluxDB measurement in Grafana table (or singlestat)?

I'm using Telegraf/InfluxDB/Grafana to register and view metrics for my servers. Occasionally one of these components crash and metrics stop flowing into InfluxDB.
To be able to notice when this happens (on top of using Monit to restart the service) I would like to create a Grafana dashboard where I have a singlestat panel for each host that shows the most recent timestamp (or better, how much time has passed) since the last metric was received. I'd also like to colorize the background of the singlestat depending on how long it's been. I would like to be able to do this for any InfluxDB metric, as different metrics can have different reasons for lagging behind.
Right now, I've tried something like this in InfluxQL, but I just get an error that at least one non-time field must be present in the query:
SELECT last(time) FROM "system" WHERE "load1" > -1 GROUP BY "host"
If I try to change it to this I get a "Multiple series error":
SELECT last(time), last("load1") FROM "system" GROUP BY "host"
Is what I'm trying to do not easily doable or am I missing something obvious?
...the query syntax was taken from somewhere in this issue.
I haven't yet looked at the singlestat panel, but I suggest creating a 'scripted dashboard'.
Start by manually creating a singlestat dash with a dummy number. Then export it to see what the json looks like.
Then, recreate that same json, with the live result from the above query, using a scripted dashboard.
Look in grafana's /public/dashboards for 'scripted.js' or 'scripted_templated.js'. Make a copy of one of those in the same folder, then hack away to generate your json. Here and here and here are some nice examples for the javascript magic to submit the query to influxdb and parse the result into the json for your singlestat dash. Good luck.

Getting count to work with Grafana

I have an InfluxDB query that works:
select count("cars") from "bridge_activity" where time > now() - 1m group by count
When I enter this query into Grafana on a dashboard, nothing shows up. I've been sure to zoom out enough that the time period in question is visible.
What I'm trying to do is, keep track of the number of cars that have gone over the bridge, over the past minute. I'd like to use this as a measurement of relative activity for the bridge.
What am I doing wrong on the Grafana dashboard?
Remove the group by count if you just want a value for a singlestat panel.
If you're looking to graph the number of cars over time, then you need a query like SELECT count("cars") from "bridge_activity" GROUP BY time(1m)
https://docs.influxdata.com/influxdb/v1.0/query_language/data_exploration/#group-by-time-intervals

InfluxDB - Query milliseconds since last data point in a time series

Is it possible to write a InfluxDB query that will give me the number of milliseconds since the last entry in a time series? I'd like to add a single-stat panel in Grafana displaying how old the data is.
I don't think it is possible since you are not able to query the time alone. A influxdb query needs at least one non-time field in a query. You could workaround that by double saving the time in a extra field which you are able to query alone.
But you still want to use now() - "the extra time field". But as far as I found out you also can't use now() inside grafana.
Update: there is a [Feature-Request] now on grafanas github. Make sure to vote it up so it gets implemented one day: https://github.com/grafana/grafana/issues/6710
Update 2: The feature got finaly implemented -> See my answer here: How to show "33 minutes ago" on Grafana dashboard with InfluxDB?

Resources