Class: Prometheus::ApiClient::Cadvisor::CadvisorClient

Inherits:
Prometheus::ApiClient::Client show all
Defined in:
lib/prometheus/api_client/cadvisor.rb

Overview

A client with special labels for cadvisor metrics

Direct Known Subclasses

Container, Node, Pod

Constant Summary

Constants inherited from Prometheus::ApiClient::Client

Prometheus::ApiClient::Client::DEFAULT_ARGS

Instance Method Summary collapse

Methods inherited from Prometheus::ApiClient::Client

#faraday_headers, #faraday_options, #faraday_proxy, #faraday_request, #faraday_ssl, #initialize, #label, #query, #query_range, #run_command, #targets

Constructor Details

This class inherits a constructor from Prometheus::ApiClient::Client

Instance Method Details

#get(command, options) ⇒ Object

Issues a get request to the low level client. Update the query options to use specific labels



28
29
30
31
# File 'lib/prometheus/api_client/cadvisor.rb', line 28

def get(command, options)
  options[:query] = update_query(options[:query], @labels)
  @client.get(command, options)
end

#update_query(query, labels) ⇒ Object

Add labels to simple query variables.

Example:

"cpu_usage" => "cpu_usage{labels...}"
"sum(cpu_usage)" => "sum(cpu_usage{labels...})"
"rate(cpu_usage[5m])" => "rate(cpu_usage{labels...}[5m])"

Note:

Not supporting more complex queries.


22
23
24
# File 'lib/prometheus/api_client/cadvisor.rb', line 22

def update_query(query, labels)
  query.sub(/(?<r>\[.+\])?(?<f>[)])?$/, "{#{labels}}\\k<r>\\k<f>")
end