Class: Grafana::GraphiteDatasource
- Inherits:
-
AbstractDatasource
- Object
- AbstractDatasource
- Grafana::GraphiteDatasource
- Defined in:
- lib/grafana/graphite_datasource.rb
Overview
Implements the interface to graphite datasources.
Instance Attribute Summary
Attributes inherited from AbstractDatasource
Class Method Summary collapse
Instance Method Summary collapse
- #default_variable_format ⇒ Object
- #raw_query_from_panel_model(panel_query_target) ⇒ Object
-
#request(query_description) ⇒ Object
:raw_query
needs to contain a Graphite query as String.
Methods inherited from AbstractDatasource
build_instance, #category, #id, inherited, #initialize, #name, #replace_variables, #type, #uid
Constructor Details
This class inherits a constructor from Grafana::AbstractDatasource
Class Method Details
.handles?(model) ⇒ Boolean
7 8 9 10 |
# File 'lib/grafana/graphite_datasource.rb', line 7 def self.handles?(model) tmp = new(model) tmp.type == 'graphite' end |
Instance Method Details
#default_variable_format ⇒ Object
40 41 42 |
# File 'lib/grafana/graphite_datasource.rb', line 40 def default_variable_format 'glob' end |
#raw_query_from_panel_model(panel_query_target) ⇒ Object
35 36 37 |
# File 'lib/grafana/graphite_datasource.rb', line 35 def raw_query_from_panel_model(panel_query_target) panel_query_target['target'] end |
#request(query_description) ⇒ Object
:raw_query
needs to contain a Graphite query as String
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/grafana/graphite_datasource.rb', line 14 def request(query_description) raise MissingSqlQueryError if query_description[:raw_query].nil? request = { body: URI.encode_www_form('from': DateTime.strptime(query_description[:from], '%Q').strftime('%H:%M_%Y%m%d'), 'until': DateTime.strptime(query_description[:to], '%Q').strftime('%H:%M_%Y%m%d'), 'format': 'json', 'target': replace_variables(query_description[:raw_query], query_description[:variables])), content_type: 'application/x-www-form-urlencoded', request: Net::HTTP::Post } webrequest = query_description[:prepared_request] webrequest.relative_url = "/api/datasources/proxy/#{id}/render" webrequest..merge!(request) result = webrequest.execute(query_description[:timeout]) preformat_response(result.body) end |