ruby-grafana-reporter 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +185 -180
- data/lib/VERSION.rb +2 -2
- data/lib/grafana/abstract_datasource.rb +32 -12
- data/lib/grafana/errors.rb +1 -9
- data/lib/grafana/grafana.rb +3 -7
- data/lib/grafana/graphite_datasource.rb +6 -0
- data/lib/grafana/prometheus_datasource.rb +6 -0
- data/lib/grafana/sql_datasource.rb +6 -0
- data/lib/grafana/unsupported_datasource.rb +7 -0
- data/lib/grafana/webrequest.rb +1 -1
- data/lib/grafana_reporter/abstract_query.rb +20 -62
- data/lib/grafana_reporter/abstract_report.rb +66 -15
- data/lib/grafana_reporter/alerts_table_query.rb +5 -5
- data/lib/grafana_reporter/annotations_table_query.rb +4 -4
- data/lib/grafana_reporter/application/application.rb +10 -16
- data/lib/grafana_reporter/application/webservice.rb +34 -10
- data/lib/grafana_reporter/asciidoctor/alerts_table_include_processor.rb +5 -5
- data/lib/grafana_reporter/asciidoctor/annotations_table_include_processor.rb +5 -5
- data/lib/grafana_reporter/asciidoctor/panel_image_block_macro.rb +2 -1
- data/lib/grafana_reporter/asciidoctor/panel_image_inline_macro.rb +7 -5
- data/lib/grafana_reporter/asciidoctor/panel_property_inline_macro.rb +2 -1
- data/lib/grafana_reporter/asciidoctor/panel_query_table_include_processor.rb +6 -5
- data/lib/grafana_reporter/asciidoctor/panel_query_value_inline_macro.rb +5 -5
- data/lib/grafana_reporter/asciidoctor/processor_mixin.rb +43 -2
- data/lib/grafana_reporter/asciidoctor/report.rb +17 -41
- data/lib/grafana_reporter/asciidoctor/sql_table_include_processor.rb +4 -4
- data/lib/grafana_reporter/asciidoctor/sql_value_inline_macro.rb +4 -4
- data/lib/grafana_reporter/configuration.rb +14 -2
- data/lib/grafana_reporter/console_configuration_wizard.rb +2 -10
- data/lib/grafana_reporter/demo_report_wizard.rb +16 -2
- data/lib/grafana_reporter/erb/report.rb +43 -0
- data/lib/grafana_reporter/errors.rb +9 -1
- data/lib/grafana_reporter/help.rb +1 -5
- data/lib/grafana_reporter/logger/{two_way_logger.rb → two_way_delegate_logger.rb} +0 -0
- data/lib/grafana_reporter/panel_image_query.rb +2 -2
- data/lib/grafana_reporter/query_value_query.rb +4 -4
- data/lib/ruby_grafana_extension.rb +8 -0
- data/lib/ruby_grafana_reporter.rb +13 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 799071f1a4ed0795aeb9dbdc7fe175d3e023f4d0de3844f0ae57e85343ab47b4
|
4
|
+
data.tar.gz: 6524d4a07cd49c6622d69507e0ee6c3a37c18c358f8a3dc63b56848255c38e4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f52466eb19bc813271c4f67818414f578750f2a7d9254244cb5213be47ffa50e8a1849788935211391b606cc944a84b9bef6b46aec583185bbe94958d2e080a5
|
7
|
+
data.tar.gz: 4eae953b1ad50b9d188d66f3f7bf0c9c6184ff3009da077f2ed07c0d082d7b3d7be75c362143033b27b8256482886e797c78ab750bdde5a85cf198ea8b4fe540
|
data/README.md
CHANGED
@@ -1,180 +1,185 @@
|
|
1
|
-
[](https://github.com/divinity666/ruby-grafana-reporter/blob/master/LICENSE)
|
2
|
-
[](https://travis-ci.org/github/divinity666/ruby-grafana-reporter?branch=master)
|
3
|
-
[](https://coveralls.io/github/divinity666/ruby-grafana-reporter?branch=master)
|
4
|
-
[](https://badge.fury.io/rb/ruby-grafana-reporter)
|
5
|
-
|
6
|
-
# Ruby Grafana Reporter
|
7
|
-
Reporting Service for Grafana
|
8
|
-
|
9
|
-
## Table of Contents
|
10
|
-
|
11
|
-
* [About the project](#about-the-project)
|
12
|
-
* [Features](#features)
|
13
|
-
* [Quick Start](#quick-start)
|
14
|
-
* [Grafana integration](#grafana-integration)
|
15
|
-
* [Webservice overview](#webservice-overview)
|
16
|
-
* [Roadmap](#roadmap)
|
17
|
-
* [Donations](#donations)
|
18
|
-
|
19
|
-
## About the project
|
20
|
-
|
21
|
-
Did you ever want to create (professional) reports based on Grafana dashboards?
|
22
|
-
I did so in order to being able to automatically get monthly reports of my
|
23
|
-
home's energy usage. That's how it started.
|
24
|
-
|
25
|
-
## Features
|
26
|
-
|
27
|
-
* Build
|
28
|
-
(other formats supported
|
29
|
-
*
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
*
|
34
|
-
database queries
|
35
|
-
*
|
36
|
-
|
37
|
-
|
38
|
-
*
|
39
|
-
*
|
40
|
-
|
41
|
-
*
|
42
|
-
* Solid as a rock, also in case of template errors and whatever else may happen
|
43
|
-
* Full [API documentation](https://rubydoc.info/gems/ruby-grafana-reporter) available
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
**
|
66
|
-
|
67
|
-
*
|
68
|
-
* `
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
* `gem install ruby-grafana-reporter`
|
74
|
-
* `ruby-grafana-reporter -w`
|
75
|
-
|
76
|
-
**
|
77
|
-
|
78
|
-
*
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
*
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
a variable
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
##
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
1
|
+
[](https://github.com/divinity666/ruby-grafana-reporter/blob/master/LICENSE)
|
2
|
+
[](https://travis-ci.org/github/divinity666/ruby-grafana-reporter?branch=master)
|
3
|
+
[](https://coveralls.io/github/divinity666/ruby-grafana-reporter?branch=master)
|
4
|
+
[](https://badge.fury.io/rb/ruby-grafana-reporter)
|
5
|
+
|
6
|
+
# Ruby Grafana Reporter
|
7
|
+
Reporting Service for Grafana
|
8
|
+
|
9
|
+
## Table of Contents
|
10
|
+
|
11
|
+
* [About the project](#about-the-project)
|
12
|
+
* [Features](#features)
|
13
|
+
* [Quick Start](#quick-start)
|
14
|
+
* [Grafana integration](#grafana-integration)
|
15
|
+
* [Webservice overview](#webservice-overview)
|
16
|
+
* [Roadmap](#roadmap)
|
17
|
+
* [Donations](#donations)
|
18
|
+
|
19
|
+
## About the project
|
20
|
+
|
21
|
+
Did you ever want to create (professional) reports based on Grafana dashboards?
|
22
|
+
I did so in order to being able to automatically get monthly reports of my
|
23
|
+
home's energy usage. That's how it started.
|
24
|
+
|
25
|
+
## Features
|
26
|
+
|
27
|
+
* Build reports based on [grafana](https://github.com/grafana/grafana) dashboards, PDF
|
28
|
+
(default) and many other formats supported
|
29
|
+
* Easy-to-use configuration wizard, including fully automated functionality to create a
|
30
|
+
demo report
|
31
|
+
* Include dynamic content from grafana (find here a reference for all
|
32
|
+
[asciidcotor reporter calls](FUNCTION_CALLS.md)):
|
33
|
+
* panels as images
|
34
|
+
* tables based on grafana panel queries or custom database queries (no images!)
|
35
|
+
* single values to be integrated in text, based on grafana panel queries or custom
|
36
|
+
database queries
|
37
|
+
* Multi purpose use of the reporter
|
38
|
+
* webservice to be called directly from grafana
|
39
|
+
* standalone command line tool, e.g. to be automated with `cron` or `bash` scrips
|
40
|
+
* seemlessly runs from asciidocotor docker container without further dependencies
|
41
|
+
* Webhook callbacks before, on cancel and on finishing callbacks (see configuration file)
|
42
|
+
* Solid as a rock, also in case of template errors and whatever else may happen
|
43
|
+
* Full [API documentation](https://rubydoc.info/gems/ruby-grafana-reporter) available
|
44
|
+
|
45
|
+
Functionalities are provided as shown here:
|
46
|
+
|
47
|
+
Database | Image rendering | Panel-based rendering | Query-based rendering
|
48
|
+
------------------------- | :-------: | :-----------: | :------------:
|
49
|
+
all SQL based datasources | supported | supported | supported
|
50
|
+
Graphite | supported | supported | supported
|
51
|
+
Prometheus | supported | supported | supported
|
52
|
+
other datasources | supported | not-supported | not-supported
|
53
|
+
|
54
|
+
## Quick Start
|
55
|
+
|
56
|
+
You don't have a grafana setup runnning already? No worries, just configure
|
57
|
+
`https://play.grafana.org` in the configuration wizard and see the magic
|
58
|
+
happen!
|
59
|
+
|
60
|
+
If your grafana setup requires a login, you'll have to setup an api key for
|
61
|
+
the reporter. Please follow the steps
|
62
|
+
[described here](https://github.com/divinity666/ruby-grafana-reporter/issues/2#issuecomment-811836757)
|
63
|
+
first.
|
64
|
+
|
65
|
+
**Windows:**
|
66
|
+
|
67
|
+
* [Download latest Windows executable](https://github.com/divinity666/ruby-grafana-reporter/releases/latest)
|
68
|
+
* `ruby-grafana-reporter -w`
|
69
|
+
|
70
|
+
**Raspberry Pi:**
|
71
|
+
|
72
|
+
* `sudo apt-get install ruby`
|
73
|
+
* `gem install ruby-grafana-reporter`
|
74
|
+
* `ruby-grafana-reporter -w`
|
75
|
+
|
76
|
+
**Ruby environment:**
|
77
|
+
|
78
|
+
* `gem install ruby-grafana-reporter`
|
79
|
+
* `ruby-grafana-reporter -w`
|
80
|
+
|
81
|
+
**Docker environment** (advanced users):
|
82
|
+
|
83
|
+
* [Download latest single-rb file](https://github.com/divinity666/ruby-grafana-reporter/releases/latest)
|
84
|
+
to an empty folder
|
85
|
+
* create a configuration file by calling `ruby ruby-grafana-reporter -w` (if in doubt,
|
86
|
+
run the command within your docker container)
|
87
|
+
* create file `/<<path-to-single-rb-file-folder>>/startup.sh` with the following
|
88
|
+
content:
|
89
|
+
|
90
|
+
```
|
91
|
+
cd /documents
|
92
|
+
ruby bin/ruby-grafana-reporter
|
93
|
+
```
|
94
|
+
* add asciidoctor your compose yaml:
|
95
|
+
|
96
|
+
```
|
97
|
+
asciidoctor:
|
98
|
+
image: asciidoctor/docker-asciidoctor
|
99
|
+
container_name: asciidoctor
|
100
|
+
hostname: asciidoctor
|
101
|
+
volumes:
|
102
|
+
- /<<path-to-single-rb-file-folder>>:/documents
|
103
|
+
command:
|
104
|
+
sh /documents/startup.sh
|
105
|
+
restart: unless-stopped
|
106
|
+
```
|
107
|
+
* start/restart the asciidoctor docker container
|
108
|
+
|
109
|
+
## Grafana integration
|
110
|
+
|
111
|
+
The key feature of the report is, that it can easily be integrated with grafana.
|
112
|
+
|
113
|
+
For accessing the reporter from grafana, you need to simply add a link to your
|
114
|
+
grafana dashboard:
|
115
|
+
|
116
|
+
* Open the dashboard configuration
|
117
|
+
* Select `Links`
|
118
|
+
* Select `Add`
|
119
|
+
* Fill out as following:
|
120
|
+
* Type: `link`
|
121
|
+
* Url: `http://<<your-server-url>>:<<your-webservice-port>>/render?var-template=demo_report`
|
122
|
+
* Title: `Demo Report`
|
123
|
+
* Select `Time range`
|
124
|
+
* Select `Variable values`
|
125
|
+
* Select `Add`
|
126
|
+
|
127
|
+
Now go back to your dashboard and click the newly generated `Demo Report`
|
128
|
+
link on it. Now the renderer should start it's task and show you the expected
|
129
|
+
results.
|
130
|
+
|
131
|
+
Please note, that the reporter won't automatically refresh your screen to update
|
132
|
+
the progress. Simply hit `F5` to refresh your browser. After the report has been
|
133
|
+
successfully built, it will show the PDF after the next refresh automatically.
|
134
|
+
|
135
|
+
You want to select a template in grafana, which shall then be rendered?
|
136
|
+
Piece of cake: Just add a dashboard variable to your grafana dashboard named
|
137
|
+
`template` and let the user select or enter a template name. To make use of it,
|
138
|
+
you should change the link of the `Demo Report` link to
|
139
|
+
`http://<<your-server-url>>:<<your-webservice-port>>/render?`. On
|
140
|
+
hitting the new link in the dashboard, grafana will add the selected template as
|
141
|
+
a variable and forward it to the reporter.
|
142
|
+
|
143
|
+
## Webservice overview
|
144
|
+
|
145
|
+
Running the reporter as a webservice provides the following URLs
|
146
|
+
|
147
|
+
/overview - for all running or retained renderings
|
148
|
+
/render - for rendering a template, 'var-template' is the only mandatory GET parameter
|
149
|
+
/view_report - for viewing the status or receving the result of a specific rendering, is automatically called after a successfull /render call
|
150
|
+
/cancel_report - for cancelling the rendering of a specific report, normally not called manually, but on user interaction in the /view_report or /overview URL
|
151
|
+
|
152
|
+
The main endpoint to call for report generation is configured in the previous chapter [Grafana integration](#grafana-integration).
|
153
|
+
|
154
|
+
However, if you would like to see, currently running report generations and previously generated reports, you may want to call the endpoint `/overview`.
|
155
|
+
|
156
|
+
## Roadmap
|
157
|
+
|
158
|
+
This is just a collection of things, I am heading for in future, without a schedule.
|
159
|
+
|
160
|
+
* Support all grafana datasources
|
161
|
+
* Solve code TODOs
|
162
|
+
* Become [rubocop](https://rubocop.org/) ready
|
163
|
+
|
164
|
+
## Contributing
|
165
|
+
|
166
|
+
If you'd like to contribute, please fork the repository and use a feature
|
167
|
+
branch. Pull requests are warmly welcome.
|
168
|
+
|
169
|
+
## Licensing
|
170
|
+
|
171
|
+
The code in this project is licensed under MIT license.
|
172
|
+
|
173
|
+
## Acknowledgements
|
174
|
+
* [asciidoctor](https://github.com/asciidoctor/asciidoctor)
|
175
|
+
* [asciidoctor-pdf](https://github.com/asciidoctor/asciidoctor-pdf)
|
176
|
+
* [grafana](https://github.com/grafana/grafana)
|
177
|
+
|
178
|
+
Inspired by [Izak Marai's grafana reporter](https://github.com/IzakMarais/reporter)
|
179
|
+
|
180
|
+
## Donations
|
181
|
+
|
182
|
+
If this project saves you as much time as I hope it does, and if you'd like to
|
183
|
+
support my work, feel free donate. :)
|
184
|
+
|
185
|
+
[](https://www.paypal.com/donate?hosted_button_id=35LH6JNLPHPHQ)
|
data/lib/VERSION.rb
CHANGED
@@ -6,33 +6,53 @@ module Grafana
|
|
6
6
|
class AbstractDatasource
|
7
7
|
attr_reader :model
|
8
8
|
|
9
|
+
@@subclasses = []
|
10
|
+
|
11
|
+
# Registers the subclass as datasource, which is asked by {#accepts?}, if it can handle a datasource
|
12
|
+
# model.
|
13
|
+
# @param subclass [Class] class inheriting from this abstract class
|
14
|
+
def self.inherited(subclass)
|
15
|
+
@@subclasses << subclass
|
16
|
+
end
|
17
|
+
|
18
|
+
# Overwrite this method, to specify if the current datasource implementation handles the given model.
|
19
|
+
# This method is called by {#build_instance} to determine, if the current datasource implementation
|
20
|
+
# can handle the given grafana model. By default this method returns false.
|
21
|
+
# @param model [Hash] grafana specification of the datasource to check
|
22
|
+
# @return [Boolean] True if fits, false otherwise
|
23
|
+
def self.handles?(_model)
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
9
27
|
# Factory method to build a datasource from a given datasource Hash description.
|
10
28
|
# @param ds_model [Hash] grafana specification of a single datasource
|
11
29
|
# @return [AbstractDatasource] instance of a fitting datasource implementation
|
12
30
|
def self.build_instance(ds_model)
|
13
31
|
raise InvalidDatasourceQueryProvidedError, ds_model unless ds_model.is_a?(Hash)
|
14
|
-
raise InvalidDatasourceQueryProvidedError, ds_model unless ds_model['meta']
|
15
|
-
raise InvalidDatasourceQueryProvidedError, ds_model unless ds_model['meta']['id']
|
16
|
-
raise InvalidDatasourceQueryProvidedError, ds_model unless ds_model['meta']['category']
|
17
|
-
|
18
|
-
return SqlDatasource.new(ds_model) if ds_model['meta']['category'] == 'sql'
|
19
32
|
|
20
|
-
|
21
|
-
when 'graphite'
|
22
|
-
return GraphiteDatasource.new(ds_model)
|
23
|
-
|
24
|
-
when 'prometheus'
|
25
|
-
return PrometheusDatasource.new(ds_model)
|
33
|
+
raise InvalidDatasourceQueryProvidedError, ds_model unless ds_model['meta'].is_a?(Hash)
|
26
34
|
|
35
|
+
@@subclasses.each do |datasource_class|
|
36
|
+
return datasource_class.new(ds_model) if datasource_class.handles?(ds_model)
|
27
37
|
end
|
28
38
|
|
29
|
-
|
39
|
+
UnsupportedDatasource.new(ds_model)
|
30
40
|
end
|
31
41
|
|
32
42
|
def initialize(model)
|
33
43
|
@model = model
|
34
44
|
end
|
35
45
|
|
46
|
+
# @return [String] category of the datasource, e.g. `tsdb` or `sql`
|
47
|
+
def category
|
48
|
+
@model['meta']['category']
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [String] type of the datasource, e.g. `mysql`
|
52
|
+
def type
|
53
|
+
@model['type'] || @model['meta']['id']
|
54
|
+
end
|
55
|
+
|
36
56
|
# @return [String] name of the datasource
|
37
57
|
def name
|
38
58
|
@model['name']
|