divinity666 / ruby-grafana-reporter

Reporting Service for Grafana
MIT License
66 stars 5 forks source link

Simple stat pannel with two queries - reported values are the same #49

Closed bolausson closed 1 month ago

bolausson commented 1 month ago

I partially managed to get a report - lets ignore tha fact that the image renderer plugin is not working (for whatever reason).

I created a simple stat panel to test ruby-grafana-reporter. It shows the energy consumption for two PDUs (left and right). The power consumption is slightly different, but the report generated by ruby-grafana-reporter show the same value for both queries.

Essentially I have two questions:

  1. Where are the numbers in the report comming from? 1716819000000 I can't correlate it to any of the numbers shown in this panel. If I generate consecutive reports, the number keeps increasing though.
  2. Why is it the same for both queries?
  3. Any idea why the "Sum" query is showing an error in the report?

Below are the screenshots of the dashboard and the panel: PDU-Dashboard_edit

Panel-20

This is a screenshot of the generated report: view_report

This is the generated PDF: view_report.pdf

Application call

Template file

grafana_panel_image:20[dashboard="ediskdcksqz28e",width="100%"]

== Left PDU grafana_panel_query_value:20[query="Left",dashboard="ediskdcksqz28e"]

== Right PDU grafana_panel_query_value:20[query="Right",dashboard="ediskdcksqz28e"]

== Sum grafana_panel_query_value:20[query="Sum",dashboard="ediskdcksqz28e"]


**Configuration file**
 - created with configuration wizard version: 
0.7.0 dev branch [32256e8]
 - relevant part of configuration file:

This configuration has been built with the configuration wizard.

grafana: default: host: https://172.16.0.102:3000 api_key: glsa_yyy_xxx

grafana-reporter: check-for-updates: 1 report-class: GrafanaReporter::Asciidoctor::Report templates-folder: ./templates reports-folder: ./reports report-retention: 24 webservice-port: 8815

default-document-attributes: imagesdir: ./images



**Environment:**
 - OS:
Ubuntu 22.04 
 - Grafana version:
v11.0.0 (277ef258d4
 - Environment:
Compiled from source using dev branch (added OpenSSL::SSL::VERIFY_NONE)
 - Ruby Version, if source or gem environment [e.g. 2.3.7]: 
ruby 3.0.2p107
gem 3.3.5
 - Reporter version [e.g. 0.3.0]:
 0.7.0 dev branch [32256e8]
divinity666 commented 1 month ago

Thanks for using the reporter!

Your first steps look good.

1) The value you are seeing here, is the timestamp value, which is also part of the query result. You will see more details, if you apply the ˋgrafana_panel_query_tableˋ function. Most likely, you can get your desired value by adding a ˋfilter_columns="time"ˋ (whereas ˋtimeˋ must match the column name of the time column; sometimes also ˋtimestampˋ is used) option to the ˋgrafana_panel_query_valueˋ. 2) The values are identical, because they reflect the timestamp, and not the value. 3) I don't have an idea. Can you maybe share the SUM query?

Lastly: the image rendering should work, if you installed the image rendering plugin. For advice, you might use the ˋShareˋ button of a panel on your dashboard. This will most likely state, that no plugin is installed. After you installed it, it should be working as well with the reporter.

divinity666 commented 1 month ago

Ah, I just saw the query for the Sum and it is refering to the other two queries. I am afraid, this is not yet supported by the reporter - sorry.

bolausson commented 1 month ago

Thanks a lot a) For this great tool! b) For the quick repsonse which pushed me in the right direction!

The grafana-image-renderer plugin was entirly my fault: a) I installed it as "root" and not as "grafana" so I had do fix the permissions b) I had to add "rendering_ignore_https_errors = true" under "[plugin.grafana-image-renderer]"

Based on your comments I was able to get a proper report. It was not very obvious that you have to "filter out" something if there is only one thing reported :)

Anyway I got a good template now:

$ cat templates/power_report_test.adoc 
// https://docs.asciidoctor.org/asciidoc/latest/
= Lab energy report

[.text-center]
{localdatetime}

== Rack 01

[cols="h,1"]
|===
|PDU|kWh

|Left
|grafana_panel_query_value:1[dashboard="fdn1njnosc83ke",query="Rack01Left",select_value="last",from="now/M",to="now",instant="true",format="%.2f,%.2f",filter_columns="Time"]

|Right
|grafana_panel_query_value:1[dashboard="fdn1njnosc83ke",query="Rack01Right",select_value="last",from="now/M",to="now",instant="true",format="%.2f,%.2f",filter_columns="Time"]

|Left + Right
|grafana_panel_query_value:1[dashboard="fdn1njnosc83ke",query="Rack01Sum",select_value="last",from="now/M",to="now",instant="true",format="%.2f,%.2f",filter_columns="Time"] 
|===

grafana_panel_image:1[dashboard="fdn1njnosc83ke",width="100%"]
grafana_panel_image:2[dashboard="fdn1njnosc83ke",width="100%"]

Or the sake of completeness, I attached the Grafana Dashboard and the two panels: Grafana-Dashboard Panel-1 Panel-2

And as well the template and the resulting PDF power_report_test.adoc.txt power_report_test.pdf

And this is the resulting report (screenshot for the PDF): power_report_test