divinity666 / ruby-grafana-reporter

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

to=/from= formats? #56

Open senpro-ingwersenk opened 2 weeks ago

senpro-ingwersenk commented 2 weeks ago

Hello there!

I am almost done writing the report automation; it took forever to get the information I wanted out of Grafana... Last step now is to set the start and end time of the time window for which the report should be generated.

I saw some descriptions here: https://github.com/divinity666/ruby-grafana-reporter/blob/master/lib/grafana_reporter/asciidoctor/help.rb#L156-L166

From looking at the logs, Grafana sends momentjs-ish timestamps:

D, [2024-09-16T07:36:06.937966 #7] DEBUG -- : query_parameters: {"from"=>["now-1h"], "to"=>["now"], "var-datasource"=>["senst-microsoft"], "var-bucket"=>["microsoft"], "var-host"=>["SENCS-SV-HV1"], "var-template"=>["senstMicrosoftWindowsServer"]}

When I pass time values myself, do I just pass them as ISO formatted values? My goal is to preset the start and end to the start and end of a month to generate monthly reports.

You can find my current client implementation here: https://github.com/senpro-it/grafana-report-generator/blob/master/grafana-ruby-reporter-client.go

It's far from done, but I am actively working on it. According to our ticketing system I already put roughly 50 hours into this, most of this however was prep and research. Still, I hope to finish this project soon. :)

Thank you and kind regards!

divinity666 commented 2 weeks ago

You can find the code for the datetime parsing here: https://github.com/divinity666/ruby-grafana-reporter/blob/f7abedc3878c092604be988dcc8728f2aac9f897/lib/grafana_reporter/abstract_query.rb#L342

You may provide UTC times or the grafana relative time expressions. For current month you can provide something like now-M/M or now-1M/M for previous month as to and from times.

Hope this helps.