GoshPosh / grafana-meta-queries

Grafana plugin for calculating time period metrics like week over week, month over month and year over year etc.
Apache License 2.0
284 stars 71 forks source link

Column with difference in Table panel #76

Closed SwathiMuppalla closed 5 years ago

SwathiMuppalla commented 5 years ago

@Gauravshah I have been using table plugin in grafana 6.2.5, Elasticsearch datasource. I have a situation where i have a template variable “Version” with data V1, V2, V3 …etc. for every version there is lots of data and i am querying to get total count of every versions data eg: V1 Total V2 Total A 10 A 20 B 20 B 15 C 30 C 25 Since I am having template variable “Version” If i try combining two versions i get V1,V2 | Total A | 30 B | 35 C | 55

But I am trying to create another column in table panel to subtract the values which i am not able to create. I need it like this V1,V2 | Total | Difference A | 30 | 10 B | 35 | 5 C | 55 | 5

Screenshot (46)

I need Difference column which gives value of (server1 - server3) How do i do this using metaqueries?

Gauravshah commented 5 years ago

Need to change panel data source to Meta queries and the do A['metric_name']-B['metric_name'] 65294887-9d43fa80-db2d-11e9-8082-e4244f15501b

Also if I think you will have to change your query to print values for each version and then do it

SwathiMuppalla commented 5 years ago

Hi, @Gauravshah Thanks for the response..I am using Elasticsearch and Grafana 6.2.5 version.
I did print values for two versions and used B['Count']-A['Count']. I get NAN. The query I used in elastic search A = version.keyword:"ABC" B = version.keyword:"XYZ" I am using table panel showing aggregation Total.

rasinhas commented 5 years ago

I believe you should use the expressions as B['B'] - A['A']. When using an elasticsearch datasource, you should use the query alias to form the expression (or you could change the aliases).

SwathiMuppalla commented 5 years ago

@Rasinhas Thank you so much. It's working. In the same way, I am trying to get the division B['B']/A['A']- It is not working. Could you help me out with the expression for the division?

Thanks

rasinhas commented 5 years ago

What is happening with the division? Is it showing NaN as well?

It should be working with B['B']/A['A']

SwathiMuppalla commented 5 years ago

@Rasinhas Yes, it is showing NAN. (B['B'] - A['A']) /100 = gives me value. (B['B] / 624) = works good. But B['B']/A['A'] = shows NAN

https://github.com/GoshPosh/grafana-meta-queries/issues/16 As per this comment https://github.com/GoshPosh/grafana-meta-queries/issues/16#issuecomment-422425695 I used A['A'] ? B['B']/A['A'] : 0 It works but shows wrong value.

rasinhas commented 5 years ago

I don't even know if Metaqueries supports ternary operations.

About the NaN, what is the table transform you are using? "Time series aggregations"? When you look at the table using the "Time series to columns" transform, does the data show correctly? For me it sometimes show NaN for the current interval, as the value of A is 0 when a new interval just starts. I believe the problem is that for "Time series aggregations" grafana simply sums the value of the metrics for each interval, and since NaN + integer = NaN, you will always get Value = NaN on the final table.

SwathiMuppalla commented 5 years ago

Yeah, I am using Time series aggregations. It's not working for Time series to columns too. As you said for Time series aggregations. Whenever a new interval starts the Value of A and B is 0.

Gauravshah commented 5 years ago

instead of interval auto try interval month to see if that answers, I think the issue is that aggregation behaves differently in meta queries vs elastic

SwathiMuppalla commented 5 years ago

@Gauravshah Hi Gaurav. Thanks for the suggestion. It works well when I give interval = 10000d

SwathiMuppalla commented 5 years ago

Need to change panel data source to Meta queries and the do A['metric_name']-B['metric_name'] 65294887-9d43fa80-db2d-11e9-8082-e4244f15501b

Also if I think you will have to change your query to print values for each version and then do it

Hi @Gauravshah, @Rasinhas Instead of printing the values of each version. Is there any way I could get every version dynamically in each query? Thanks

Gauravshah commented 5 years ago

@SwathiMuppalla Group by support needs to be completed https://github.com/GoshPosh/grafana-meta-queries/pull/63

SwathiMuppalla commented 5 years ago

Thanks @Gauravshah