|
| 1 | +# encoding: UTF-8 |
| 2 | + |
| 3 | +require 'prometheus/api_client' |
| 4 | +require 'webmock' |
| 5 | +require 'vcr' |
| 6 | + |
| 7 | +VCR.configure do |c| |
| 8 | + c.cassette_library_dir = 'spec/vcr_cassettes' |
| 9 | + c.hook_into :webmock |
| 10 | +end |
| 11 | + |
| 12 | +describe Prometheus::ApiClient::Cadvisor do |
| 13 | + token = 'topSecret' |
| 14 | + url = 'https://prometheus.example.com:443' |
| 15 | + instance = 'example.com' |
| 16 | + |
| 17 | + describe 'Node' do |
| 18 | + it 'reads metrics' do |
| 19 | + VCR.use_cassette('prometheus/api_client/cadvisor_node') do # , record: :new_episodes) do |
| 20 | + prometheus = Prometheus::ApiClient::Cadvisor::Node.new( |
| 21 | + instance: instance, |
| 22 | + url: url, |
| 23 | + credentials: { token: token }, |
| 24 | + options: { verify_ssl: OpenSSL::SSL::VERIFY_NONE }, |
| 25 | + ) |
| 26 | + |
| 27 | + response = prometheus.query( |
| 28 | + query: 'sum(container_cpu_usage_seconds_total)', |
| 29 | + time: '2017-08-07T06:10:30.781Z', |
| 30 | + ) |
| 31 | + |
| 32 | + expect(response).to be_a(Hash) |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + it 'reads metrics range' do |
| 37 | + VCR.use_cassette('prometheus/api_client/cadvisor_node') do # , record: :new_episodes) do |
| 38 | + prometheus = Prometheus::ApiClient::Cadvisor::Node.new( |
| 39 | + instance: instance, |
| 40 | + url: url, |
| 41 | + credentials: { token: token }, |
| 42 | + options: { verify_ssl: OpenSSL::SSL::VERIFY_NONE }, |
| 43 | + ) |
| 44 | + |
| 45 | + response = prometheus.query_range( |
| 46 | + query: 'sum(container_cpu_usage_seconds_total)', |
| 47 | + start: '2017-08-07T06:10:30.781Z', |
| 48 | + end: '2017-08-07T06:14:30.781Z', |
| 49 | + step: '120s', |
| 50 | + ) |
| 51 | + |
| 52 | + expect(response).to be_a(Hash) |
| 53 | + end |
| 54 | + end |
| 55 | + end |
| 56 | +end |
0 commit comments