Class: Grafana::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/grafana/client.rb

Constant Summary collapse

Error =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(api_url:, token:) ⇒ Client

Returns a new instance of Client.

Parameters:

  • api_url (String)

    Base URL of the Grafana instance

  • token (String)

    Admin-level API token for instance


9
10
11
12
# File 'lib/grafana/client.rb', line 9

def initialize(api_url:, token:)
  @api_url = api_url
  @token = token
end

Instance Method Details

#get_dashboard(uid:) ⇒ Object

Parameters:

  • uid (String)

    Unique identifier for a Grafana dashboard


15
16
17
# File 'lib/grafana/client.rb', line 15

def get_dashboard(uid:)
  http_get("#{@api_url}/api/dashboards/uid/#{uid}")
end

#get_datasource(name:) ⇒ Object

Parameters:

  • name (String)

    Unique identifier for a Grafana datasource


20
21
22
23
24
# File 'lib/grafana/client.rb', line 20

def get_datasource(name:)
  # CGI#escape formats strings such that the Grafana endpoint
  # will not recognize the dashboard name. Prefer Addressable::URI#encode_component.
  http_get("#{@api_url}/api/datasources/name/#{Addressable::URI.encode_component(name)}")
end

#proxy_datasource(datasource_id:, proxy_path:, query: {}) ⇒ Object

Parameters:

  • datasource_id (String)

    Grafana ID for the datasource

  • proxy_path (String)

    Path to proxy - ex) 'api/v1/query_range'


28
29
30
# File 'lib/grafana/client.rb', line 28

def proxy_datasource(datasource_id:, proxy_path:, query: {})
  http_get("#{@api_url}/api/datasources/proxy/#{datasource_id}/#{proxy_path}", query: query)
end