Scale column values on a table in Grafana - grafana

I have a query in Prometheus QL which show values as a table in Grafana. My issue is that a value updated is in epoch time and in order to show human readable date I would need to multiply by 1000. There is a way to multiply value and then show? Not sure if it is possible somehow by tuning the below query or this feature is not supported at all in Grafana. I've already made some attempts but I had no luck.
This is my query:
min(helm_chart_info{chart=~"$chart", exported_namespace=~"$namespace", release=~"$release"}) by (chart, release, exported_namespace, updated, version) != 2

Related

Grafana / InfluxDB get last creation date and use an associated field to plot a graph

I have what seems like an achievable problem. But I'm struggling with it and walking into more complexity than I thought.
I've got data similar to the following
value creation_date creation_date_string environment
175000 1646209830086 2022-03-02T08:30:30.086Z integration
175000 1644576234409 2022-02-11T10:43:54.409Z production
175000 1646244958207 2022-03-02T18:15:58.207Z production
In Influx I want to select the newest (aka latest, aka last) creation_date for each environment and then plot its value.
The best I've come up with is
SELECT value, last(creation_date) FROM measurement WHERE $timeFilter GROUP BY environment
Which works but also shows the creation_date on the graph. I'd like to filter the creation_date and keep only the value. i.e. As I only need creation_date to select the row.
Is this possible in InfluxDB or via Grafana?

I can't show to Grafana what time field it should use for chart building

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.

Change the config settings per column in a Grafana table

I have a table in Grafana that has several columns and uses the gauge display mode. Setting the min/max values for these columns is troublesome. If the column is a percentage value the max is always known so can be hard coded as 100 or 1. But for example a column displaying database sizes the max is not known and will change.
I am running Grafana 8.1.2 so tried the new 'config from query results' transform for the first time. This works fine to alter the values of a single column but not for more than one.
Grafana Table
As you can see in the attached picture I have set the max for the database size using the new transform but I also need to be able to set the max for the log size column too.
The dashboard has 2 queries in it, both for MSSQLServer. Query A returns the results in a table format and Query B returns the config settings: query result
I've then got the transform set up as follows: transform set up
Is there a way to set the min\max settings for multiple columns using this new transform that I'm missing or some other technique to do it. Unfortunately (for me) Grafana seems to favour time series data so isn't as configurable for table data.

Tableau Target Vs. Actual - Can not get totals to show correctly

I am having trouble showing the correct totals in my tableau worksheet.
I have supervisors that are part of specific zones that need to complete a certain number of tests in different categories. For example, supervisor 15716 must complete 8 tests in category 1. I need to show the target, which is a number stored in the database and show the actual number of tests in that category that have been completed within a date range. I have it working, but Im not sure if I did it correctly because I can not show any totals.
System target - number stored in database
CountOfSheetID - calculated field
Percent Compliant - calculated field
Try this approach -
First define a calculated field called [Within Date Range?] as
[Date] >= [MyStartDate] AND [Date] <= [LastSelectedDayOfMonth]
and put that new field on the filter shelf, only including data where [Within Date Range?] is True. (You could also just filter the [Date] field if that is flexible enough for you)
The you don't need the CountofSheetId calculated field at all. If you want to know how many records have a non-null value for [SheetID] within your date range, you can simply drop [SheetID] on a shelf and choose to treat it as Measure with the aggregation function COUNT()
Then just build your visualization to show the counts you want (not percentages, the actual counts)
Finally, you can convert counts into Percentages by clicking on the pills for your Measures and choosing Percentage under Quick Table Calcs. You'll want to experiment with the "Compute Using" setting to tell Tableau how to compute your percentages -- i.e. define percentage of "what".
Percentages are implemented as table calcs in Tableau. Read the help to understand table calcs, especially the description of partitioning and addressing.

Prometheus query equivalent to SQL DISTINCT

I have multiple Prometheus instances providing the same metric, such as:
my_metric{app="foo", state="active", instance="server-1"} 20
my_metric{app="foo", state="inactive", instance="server-1"} 30
my_metric{app="foo", state="active", instance="server-2"} 20
my_metric{app="foo", state="inactive", instance="server-2"} 30
Now I want to display this metric in a Grafana singlestat widget. When I use the following query...
sum(my_metric{app="foo", state="active"})
...it, of course, sums up all values and returns 40. So I tell Prometheus to sum it by instance...
sum(my_metric{app="foo", state="active"}) by (instance)
...which results in a "Multiple Series Error" in Grafana. Is there a way to tell Prometheus/Grafana to only use the first of the results?
I don't know of a distinct, but I think this would work too:
topk(1, my_metric{app="foo", state="active"} by (instance))
Check out the second to last example in here:
https://prometheus.io/docs/prometheus/latest/querying/examples/
One way I just found is to additionally do an average over all values:
avg(sum(my_metric{app="foo", state="active"}) by(instance))
If you need to return an arbitrary time series out of multiple matching time series, then this can be done with topk() or bottomk() functions. For example, the following query returns a single time series with the maximum value out of multiple time series which match my_metric{app="foo", state="active"}:
topk(1, my_metric{app="foo", state="active"})
You need to set instant query option in Grafana when using topk(). Otherwise topk(1, ...) may return multiple time series when it is used for building a graph with range query. This is because topk(1, ...) selects a single time series with the max value individually per each point on the graph. Different points on the graph may have different time series with the max value. There is a workaround, which allows returning a single series out of many series on a graph in alternative Prometheus-like systems such as VictoriaMetrics. It provides topk_* and bottomk_* functions for this purpose. See, for example, topk_last or topk_avg.
Note that topk() has no common grounds with DISTINCT from SQL. If you need to select distinct label values with PromQL, then you need to use count(...) by (label). It will return unique label values for the given label alongside the number of unique time series per each label value. For example, count(my_metric) by (app) will return unique app label names for time series with my_metric name. This is roughly equivalent to the following SQL with DISTINCT clause:
SELECT DISTINCT app FROM my_metric
See count() docs for details.