@@ -10,26 +10,78 @@ module ApiClient
1010 class Client
1111 class RequestError < StandardError ; end
1212
13- def initialize ( args )
14- @client = Faraday . new ( args )
13+ # Create a Prometheus API client:
14+ #
15+ # @param [Hash] options
16+ # @option options [Hash] :url String base URL.
17+ # @option options [Hash] :params URI query unencoded key/value pairs.
18+ # @option options [Hash] :headers Unencoded HTTP header key/value pairs.
19+ # @option options [Hash] :request Request options.
20+ # @option options [Hash] :ssl SSL options.
21+ # @option options [Hash] :proxy Proxy options.
22+ #
23+ # A default client is created if options is omitted.
24+ def initialize ( options )
25+ @client = Faraday . new ( options )
1526 end
1627
28+ # Evaluates an instant query at a single point in time:
29+ #
30+ # @param [Hash] options
31+ # @option options [String] :query Prometheus expression query string.
32+ # @option options [String] :time <rfc3339 | unix_timestamp> Evaluation
33+ # timestamp. Optional.
34+ # @option options [String] :timeout Evaluation timeout. Optional.
35+ # Defaults to and is capped by the value of the -query.timeout flag.
36+ #
37+ # The current server time is used if the time parameter is omitted.
1738 def query ( options )
1839 run_command ( 'query' , options )
1940 end
2041
42+ # Evaluates an expression query over a range of time:
43+ #
44+ # @param [Hash] options
45+ # @option options [String] :query Prometheus expression query string.
46+ # @option options [String] :start <rfc3339 | unix_timestamp> Start
47+ # timestamp.
48+ # @option options [String] :end <rfc3339 | unix_timestamp> End timestamp.
49+ # @option options [String] :step <duration> Query resolution step width.
50+ # @option options [String] :timeout Evaluation timeout. Optional.
51+ # Defaults to and is capped by the value of the -query.timeout flag.
52+ #
53+ # The current server time is used if the time parameter is omitted.
2154 def query_range ( options )
2255 run_command ( 'query_range' , options )
2356 end
2457
25- def label ( tag , options = { } )
26- run_command ( "label/#{ tag } /values" , options )
58+ # Returns an overview of the current state of the Prometheus target
59+ # discovery:
60+ #
61+ # @param [Hash] options
62+ #
63+ # No options used.
64+ def targets ( options )
65+ run_command ( 'targets' , options )
2766 end
2867
68+ # Returns a list of label values for a provided label name:
69+ #
70+ # @param [String] label Label name
71+ # @param [Hash] options
72+ #
73+ # No options used.
74+ def label ( label , options = { } )
75+ run_command ( "label/#{ label } /values" , options )
76+ end
77+
78+ # Issues a get request to the low level client.
2979 def get ( command , options )
3080 @client . get ( command , options )
3181 end
3282
83+ # Issues a get request to the low level client, and evalueate the
84+ # response JSON.
3385 def run_command ( command , options )
3486 response = get ( command , options )
3587
0 commit comments