influxdb-cli 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99c5faca92da1f2362bcd999e8007d92d3b91e82
4
- data.tar.gz: 7eee7f66b1b30f644d1a9b29c51142bdb909e989
3
+ metadata.gz: f7a4f8e0419999de09aa047254204462f8150b6d
4
+ data.tar.gz: f468e14d522630cc1e4b6de1970e3484ba2b8051
5
5
  SHA512:
6
- metadata.gz: 7839991a77721868443e099662cf3aec93a14a883158594c09584fbb7dbff239b2a7c86649558a1eeb359654950d522a61898b55cbec6a15d3b26086be0fd4b3
7
- data.tar.gz: 0b9b02d642bbe109775e395499ac63e01030ca426d3b28aa813f6770e344236babcbc1377008bbb98c0687239041378d09e22c7c3b9571eb893efe5de9e3b93b
6
+ metadata.gz: 83f22cfbe7d9c64fb8189cf2b37f0dbbf66db33aef45d658e251c77179fca54c18a0b6ffa79d57d439c7a65eea83e1be17d9034e6432c19e5992e1615162a723
7
+ data.tar.gz: 714a92645856fecd8e2cc3f8b85ef0ab3e6bdce44c7183c4ce274e214834ed235235a7c18a1969f8b0e8951fbdeae4e5d77a528652f90ec5df9ef35e683ee7d8
@@ -6,4 +6,9 @@ rvm:
6
6
  - ruby-head
7
7
  - jruby-head
8
8
 
9
+ notifications:
10
+ email:
11
+ on_success: change
12
+ on_failure: always
13
+
9
14
  script: bundle exec rspec spec
@@ -42,27 +42,19 @@ end
42
42
  # @return [InfluxDB::Client]
43
43
  def db; InfluxDBClientTasks.db; end
44
44
 
45
- # Queries data using {http://influxdb.org/docs/query_language/ InfluxDB Query Language}
46
- # and prints a tabularized output.
47
- #
48
- # i.e. query('select value from response_times')
49
- #
50
- # @see InfluxDB::Client#query
51
- # @see InfluxDBClient::Client.print_tabularize
52
- #
53
- # @param query [String] the query
54
- # @return [Hash] the number of points per time series i.e. { 'response_times.count' => 10 }
55
- def query(query)
56
- result = db.query(query)
57
- InfluxDBClient::Client.print_tabularize(result)
58
- end
59
-
60
45
  InfluxDBClientTasks.start
61
46
 
62
47
  # allow typing queries directly from console i.e.`select * from deploys` instead of `query('select * from deploys')`.
63
48
  # matches `delete from ...` and `select ... from ...`
64
49
  Pry::Commands.block_command InfluxDBClient::Client::QUERY_LANGUAGE_MATCHER, 'Execute a query' do |cmd|
65
- query(cmd)
50
+ start = Time.now
51
+ result = db.query(cmd)
52
+ duration = Time.now - start
53
+
54
+ InfluxDBClient::Client.print_tabularize(result)
55
+
56
+ # print query duration in seconds
57
+ puts "Query duration: #{duration.round(2)}s"
66
58
  end
67
59
 
68
60
  # awesome_print
@@ -10,26 +10,33 @@ module InfluxDBClient
10
10
  # @param output [STDOUT] the output to `puts` the results
11
11
  # @return [Hash] the number of points per time series i.e. { 'response_times.count' => 10 }
12
12
  def self.print_tabularize(result, output=$stdout)
13
- number_of_points = {}
14
- result.keys.each do |series|
15
- if result[series].any?
16
- output.puts generate_table(series, result)
13
+ (result || {}).keys.each do |series|
14
+ result_series = result[series]
15
+
16
+ if result_series.any?
17
+ output.puts generate_table(series, result_series)
18
+ output.puts "#{result_series.size} #{pluralize(result_series.size, 'result')} found for #{series}"
17
19
  else
18
20
  output.puts "No results found for #{series}"
19
21
  end
20
- # empty line between time series output
22
+ # print a line break between time series output
21
23
  output.puts
22
- # count total per time series
23
- number_of_points["#{series}.count"] = result[series].size
24
24
  end
25
- number_of_points
26
25
  end
27
26
 
28
27
  private
29
28
 
30
- def self.generate_table(series, result)
31
- headings = result[series].first.keys
32
- rows = result[series].collect(&:values)
29
+ def self.pluralize(count, singular, plural = nil)
30
+ if count > 1
31
+ plural ? plural : "#{singular}s"
32
+ else
33
+ singular
34
+ end
35
+ end
36
+
37
+ def self.generate_table(series, result_series)
38
+ headings = result_series.first.keys
39
+ rows = result_series.collect(&:values)
33
40
 
34
41
  Terminal::Table.new title: series, headings: headings, rows: rows
35
42
  end
@@ -1,3 +1,3 @@
1
1
  module InfluxDBClient
2
- VERSION = '0.0.6'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -30,10 +30,6 @@ module InfluxDBClient
30
30
  series2: [{ value3: 3, value4: 4, value5: nil, value6: nil },
31
31
  { value3: nil, value4: 4, value5: 5, value6: 6 }] } }
32
32
 
33
- it 'returns series count' do
34
- expect(described_class.print_tabularize(result)).to eq({ 'series1.count' => 1, 'series2.count' => 2 })
35
- end
36
-
37
33
  it 'generates tables' do
38
34
  expect(Terminal::Table).to receive(:new).
39
35
  with(title: :series1, headings: [:value1, :value2], rows: [[1, 2]])
@@ -44,13 +40,16 @@ module InfluxDBClient
44
40
  described_class.print_tabularize(result)
45
41
  end
46
42
 
47
- it 'puts tables' do
43
+ it 'prints results' do
48
44
  output = double 'Output'
49
45
  table = double 'Table'
50
46
  Terminal::Table.stub(new: table)
51
47
 
52
48
  # should print series1 and series2
53
49
  expect(output).to receive(:puts).twice.with(table)
50
+ # print results count
51
+ expect(output).to receive(:puts).once.with('1 result found for series1')
52
+ expect(output).to receive(:puts).once.with('2 results found for series2')
54
53
  # line break for series
55
54
  expect(output).to receive(:puts).twice.with(no_args)
56
55
 
@@ -61,13 +60,15 @@ module InfluxDBClient
61
60
  let(:result) { { series1: [{ value1: 1, value2: 2 }],
62
61
  series2: [] } }
63
62
 
64
- it 'puts no results found' do
63
+ it 'prints no results found' do
65
64
  output = double 'Output'
66
65
  table = double 'Table'
67
66
  Terminal::Table.stub(new: table)
68
67
 
69
68
  # should print series1
70
69
  expect(output).to receive(:puts).once.with(table)
70
+ # print results count
71
+ expect(output).to receive(:puts).once.with('1 result found for series1')
71
72
  # no results for series 2
72
73
  expect(output).to receive(:puts).once.with('No results found for series2')
73
74
  # line break for series
@@ -75,10 +76,6 @@ module InfluxDBClient
75
76
 
76
77
  described_class.print_tabularize(result, output)
77
78
  end
78
-
79
- it 'returns series count' do
80
- expect(described_class.print_tabularize(result)).to eq({ 'series1.count' => 1, 'series2.count' => 0 })
81
- end
82
79
  end
83
80
  end
84
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Cantero