I've been work on Loki for centralized logging with Grafana. I want to 'Explore' log by query without using time control on top of the Grafana. I wonder if its possible to add range time manually by query (not the time control provided by grafana)?
It's probably like
{job=docker-container} |~ "error" | startsAt = formatTime | endsAt = formatTime
I didn't found any variables that can describe control time range though, also for the labels
Related
I have a Postgresql DataSource with the following table:
It's kinda logs. All I want is to show on a chart how many successful records (with http_status == 200) do I have per each hour. Sounds simple, right? I wrote this query:
SELECT
count(http_status) AS "suuccess_total_count_per_hour",
date_trunc('hour', created_at) "log_date"
FROM logs
WHERE
http_status = 200
GROUP BY log_date
ORDER BY log_date
It gives me the following result:
Looks good to me. I'm going ahead and trying to put it into Grafana:
Ok, I get it, I have to help Grafana to understand where is the field for time count.
I go to Query Builder and I see that it breaks me query at all. And since that moment I got lost completely. Here is the Query Builder screen:
How to explain to Grafana what do I want? I want just a simple chart like:
Sorry for the rough picture, but I think you got the idea. Thanks for any help.
Your time column (e.g. created_at) should be TIMESTAMP WITH TIME ZONE type*
Use time condition, Grafana has macro so it will be easy, e.g. WHERE $__timeFilter(created_at)
You want to have hourly grouping, so you need to write select for that. Again Grafana has macro: $__timeGroupAlias(created_at,1h,0)
So final Grafana SQL query (not tested, so it may need some minor tweaks):
SELECT
$__timeGroupAlias(created_at,1h,0),
count(*) AS value,
'succcess_total_count_per_hour' as metric
FROM logs
WHERE
$__timeFilter(created_at)
AND http_status = 200
GROUP BY 1
ORDER BY 1
*See Grafana doc: https://grafana.com/docs/grafana/latest/datasources/postgres/
There are documented macros. There are also macros for the case, when your time column is UNIX timestamp.
I am trying to create a dashboard. Able to generate Bar Gauge from the Prometheus data for simple query sum by (namespace) (kube_pod_container_status_running)
I want to display only Namespace rather than {namespace="kube-system"}, so was playing with Visualization > Field > Title for a while, but was not able to figure out.
Any Idea How can just display kube-system instead of {namespace="kube-system"} and make the list in sorted order, because everytime when i refresh the dashboard, it reshuffles the order.
What I need here ?
https://grafana.com/docs/grafana/latest/features/datasources/prometheus/
Legend format
Controls the name of the time series, using name or pattern. For example {{hostname}} will be replaced with label value for the label hostname.
=> configure Legend format in the Queries section and add {{namespace}} there.
I'm not sure about sort. You may try Prometheus sort/sort_desc function to sort query result.
assume next 2 prometheus timeseries:
service_deployed{service} timestamp
service_available{service} timestamp
A set of specific metrics with matching labels would be:
service_deployed{service='provision-service'} 12345678.0
service_available{service='provision-service'} 12345900.0
which in effect say that there is a newer 'provision-service' (as its available timestamp is greater than the deployed one).
Now imagine I'd like to present these 2 in one table in Grafana. Something like:
| Service | Deployed | Available |
| provision-service| 12345678.0 | 12345900.0|
Also assume that I cannot use the latest Grafana (>5.0) that seems to be able to combine tables so I'll have to do this using promQL. How would you go about combining these metrics?
Thanks
I am trying to use the SingleStat Plugin of Grafana to add an online/offline indicator to one of my dashboards.
So what I have so far is this with an influxdb datasource:
What I am missing is the option to define a timerange for this query. Lets say I want the count() of the last 30min. If the count is 0 I know that the server is offline. If the count is > 0 he is online. (For example my server adds a new entry every 20min. So if I donĀ“t have an entry in the last 30min I know he must be offline)
So is it possible to get define a query with a timerange? When yes how ?
UPDATE
This is what I have so far now. But I get an error now which says a.form is undefined. Alos if I have a entry in the last 35min it doesnst switch to online.
The singlestat panel uses, by default, the timerange of the dashboard it is placed on.
For your case, make use of the 'override relative time' on the Time range tab and set it to "30m".
When using the count as you described, turn coloring on and set the threshold to 1. This will change the coloring when no entry is present (count is 0) in the last 30 minutes.
After installed Heapster in my kubernetes cluster, I can access Grafana but the graph are empty.
I can build a new graph with special value, e.g. "cpu/limits"; but if the pre-defined graph used $interval, the graph can not display; for example,
SELECT mean(value) FROM "cpu/limit_gauge" WHERE "container_name" = 'machine' AND $timeFilter GROUP BY time($interval), "hostname"
https://grafana.com/docs/grafana/latest/variables/variable-types/add-interval-variable/
$interval is a built in automatic variable in grafana , and is automatically set based on time range
the graph are empty? maybe your query is wrong
For future readers -
I want to add that sometimes the "group-by" "fill" option, which is NULL by default, can cause no values to be displayed depending on the resolution.
If you have a query you think should work, but still see no data, try changing the fill value to another setting that you think works (ie: none) and see if data shows up.
Grafana tries to use that configuration to fill in for missing data, and occasionally, depending on your interval and data collection rate, you might end up with oddness.