File tree Expand file tree Collapse file tree
lib/prometheus/api_client Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# encoding: UTF-8
22
3+ require 'json'
34require 'faraday'
45
56module Prometheus
67 # Client is a ruby implementation for a Prometheus compatible api_client.
78 module ApiClient
89 # Client contains the implementation for a Prometheus compatible api_client.
910 class Client
11+ class RequestError < StandardError ; end
12+
1013 def initialize ( args )
1114 @client = Faraday . new ( args )
1215 end
1316
14- def get ( args )
15- @client . get ( args )
17+ def query ( options )
18+ run_command ( 'query' , options )
19+ end
20+
21+ def query_range ( options )
22+ run_command ( 'query_range' , options )
23+ end
24+
25+ def label ( tag , options )
26+ run_command ( "label/#{ tag } /values" , options )
27+ end
28+
29+ def get ( command , options )
30+ @client . get ( command , options )
31+ end
32+
33+ def run_command ( command , options )
34+ response = get ( command , options )
35+
36+ result = JSON . parse ( response . body ) [ "data" ]
37+ rescue
38+ fail RequestError , "Bad response from server"
1639 end
1740 end
1841 end
Original file line number Diff line number Diff line change 22
33module Prometheus
44 module ApiClient
5- VERSION = '0.0.3 '
5+ VERSION = '0.1.0 '
66 end
77end
You can’t perform that action at this time.
0 commit comments