influxdb-cli 0.1.3 → 0.1.4

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: 6ce4b04c848405e7568e3917616625f6ebdb3b44
4
- data.tar.gz: 6119394e1cc3fbb8aa623ef9c771bb91c8dde217
3
+ metadata.gz: 5e41aad56b30e0f0407d98abd82cd260613f5d94
4
+ data.tar.gz: 912c971b11e4d00436a4f4f87234eacc6f205477
5
5
  SHA512:
6
- metadata.gz: 7b305986de06fff53402acb46f62e2f6d12ce7f0cd1344c7de3d90cdaa9417e86017f23649968eb1ad7787424dcf3378070b57785d25beb90d2e3136e2baae64
7
- data.tar.gz: 7739e71d2dfb2ad8da8a08b210f3de4ee7c97c44a2a745c64d867ec94d3bbadb63d209dff69dfd5793637ffd0003dd4b6020c3cb62019ced4840e50085cec930
6
+ metadata.gz: 703c39b21030ad02cc0636fe6dfe1dfa39e22c5f7586c544fa73ad7ae3c038de6d69ff236f9b49484f3fe26874e634f6624288fe74fa36dcd1195c8bc1f776be
7
+ data.tar.gz: c186a91062e03966dd02ffc141b8b5650bcf613f9d6cd934acd0ce0850914c334681ce672194b198aa6cb448f8a31e12b83d4cd7622bf5f3d8cfe016b68a793b
data/.rspec CHANGED
@@ -1,2 +1 @@
1
1
  --color
2
- --format d
data/README.md CHANGED
@@ -13,21 +13,26 @@ gem install influxdb-cli
13
13
  ### Options
14
14
 
15
15
  ```shell
16
+ $ influxdb-cli help db
17
+
16
18
  Usage:
17
- influxdb-cli
19
+ influxdb-cli db
18
20
 
19
21
  Options:
20
- [--host=HOST] # Hostname
21
- # Default: localhost
22
- [--port=PORT] # Port
23
- # Default: 8086
24
- -u, [--username=USERNAME] # Username
25
- # Default: root
26
- -p, [--password=PASSWORD] # Password
27
- # Default: root
28
- -d, [--database=DATABASE] # Database
29
- # Default: db
30
- [--pretty=PRETTY] # Human readable times
22
+ [--host=HOST] # Hostname
23
+ # Default: localhost
24
+ [--port=PORT] # Port
25
+ # Default: 8086
26
+ -u, [--username=USERNAME] # Username
27
+ # Default: root
28
+ -p, [--password=PASSWORD] # Password
29
+ # Default: root
30
+ -d, [--database=DATABASE] # Database
31
+ # Default: db
32
+ [--pretty=PRETTY] # Human readable times (UTC)
33
+ [--ssl], [--no-ssl] # Connect using TLS/SSL
34
+ [--time-precision=TIME_PRECISION] # Time precision can be set to either "s" for seconds, "ms" for milliseconds, or "u" for microseconds
35
+ # Default: s
31
36
  ```
32
37
 
33
38
  ### Usage
@@ -16,13 +16,14 @@ class InfluxDBClientTasks < Thor
16
16
  @@db = nil
17
17
 
18
18
  desc 'db', 'Connect to InfluxDB (default command)'
19
- method_option :host, :default => 'localhost', :desc => 'Hostname'
20
- method_option :port, :default => 8086, :desc => 'Port'
21
- method_option :username, :default => 'root', :desc => 'Username', :aliases => '-u'
22
- method_option :password, :default => 'root', :desc => 'Password', :aliases => '-p'
23
- method_option :database, :default => 'db', :desc => 'Database', :aliases => '-d'
24
- method_option :pretty, :default => nil, :desc => 'Human readable times (UTC)'
25
- method_option :ssl, :default => false, :desc => 'Connect using TLS/SSL', :type => :boolean
19
+ method_option :host, default: 'localhost', desc: 'Hostname'
20
+ method_option :port, default: 8086, desc: 'Port'
21
+ method_option :username, default: 'root', desc: 'Username', aliases: '-u'
22
+ method_option :password, default: 'root', desc: 'Password', aliases: '-p'
23
+ method_option :database, default: 'db', desc: 'Database', aliases: '-d'
24
+ method_option :pretty, default: nil, desc: 'Human readable times (UTC)'
25
+ method_option :ssl, default: false, desc: 'Connect using TLS/SSL', type: :boolean
26
+ method_option :time_precision, default: 's', desc: 'Time precision can be set to either "s" for seconds, "ms" for milliseconds, or "u" for microseconds'
26
27
 
27
28
  def db
28
29
  puts "Connecting to #{options.inspect}"
@@ -32,7 +33,8 @@ class InfluxDBClientTasks < Thor
32
33
  password: options[:password],
33
34
  host: options[:host],
34
35
  port: options[:port],
35
- use_ssl: options[:ssl]
36
+ use_ssl: options[:ssl],
37
+ time_precision: options[:time_precision]
36
38
  }
37
39
  InfluxDBClient::Client.pretty = options[:pretty]
38
40
  puts '✔ ready'
@@ -58,6 +60,7 @@ InfluxDBClientTasks.start
58
60
  # exit if the db command wasn't called
59
61
  exit 0 unless db
60
62
 
63
+
61
64
  # allow typing queries directly from console i.e.`select * from deploys` instead of `query('select * from deploys')`.
62
65
  # matches `delete from ...` and `select ... from ...`
63
66
  Pry::Commands.block_command InfluxDBClient::Client::QUERY_LANGUAGE_MATCHER, 'Execute a query' do |query|
@@ -65,7 +68,7 @@ Pry::Commands.block_command InfluxDBClient::Client::QUERY_LANGUAGE_MATCHER, 'Exe
65
68
  result = db.query(query)
66
69
  duration = Time.now - start
67
70
 
68
- InfluxDBClient::Client.print_tabularize(result)
71
+ InfluxDBClient::Client.print_tabularize(result, db.time_precision)
69
72
 
70
73
  # print query duration in seconds
71
74
  puts "Query duration: #{duration.round(2)}s"
@@ -81,4 +84,3 @@ Pry.config.print = proc { |output, value| Pry::Helpers::BaseHelpers.stagger_outp
81
84
 
82
85
  # TODO start `pry` only in case of `db` command, `help` and `version` should not start `pry`
83
86
  pry
84
-
@@ -10,7 +10,7 @@ module InfluxDBClient
10
10
  # @param result [Hash] the {InfluDB::Client#query result}
11
11
  # @param output [STDOUT] the output to `puts` the results
12
12
  # @return [Hash] the number of points per time series i.e. { 'response_times.count' => 10 }
13
- def self.print_tabularize(result, output=$stdout)
13
+ def self.print_tabularize(result, time_precision, output=$stdout)
14
14
  result ||= {}
15
15
 
16
16
  if result.keys.empty?
@@ -21,8 +21,10 @@ module InfluxDBClient
21
21
  result.keys.each do |series|
22
22
  result_series = result[series]
23
23
  if result_series.any?
24
- output.puts generate_table(series, result_series)
25
- output.puts "#{result_series.size} #{pluralize(result_series.size, 'result')} found for #{series}"
24
+ output.puts generate_table(series, result_series, time_precision)
25
+ output.puts "#{result_series.size} " \
26
+ "#{pluralize(result_series.size, 'result')} " \
27
+ "found for #{series}"
26
28
  else
27
29
  output.puts "No results found for #{series}"
28
30
  end
@@ -45,12 +47,18 @@ module InfluxDBClient
45
47
  end
46
48
  end
47
49
 
48
- def self.generate_table(series, result_series)
50
+ def self.generate_table(series, result_series, time_precision)
49
51
  headings = result_series.first.keys
52
+ precision_factor, str_format = case time_precision.to_s
53
+ when 's' then [1.0, '%F %T']
54
+ when 'ms' then [1_000.0, '%F %T.%3N']
55
+ when 'u' then [1_000_000.0, '%F %T.%6N']
56
+ else raise "unknown time_precision #{time_precision}"
57
+ end
50
58
  rows = result_series.map do |row|
51
59
  if @pretty
52
- microseconds_with_frac = "#{row['time'] / 1000}.#{row['time'] % 100}".to_f
53
- row['time'] = Time.at(microseconds_with_frac).utc.strftime('%Y-%m-%d %H:%M:%S.%L')
60
+ seconds_with_frac = row['time'].to_f / precision_factor
61
+ row['time'] = Time.at(seconds_with_frac).utc.strftime(str_format)
54
62
  end
55
63
  row.values
56
64
  end
@@ -59,4 +67,3 @@ module InfluxDBClient
59
67
  end
60
68
  end
61
69
  end
62
-
@@ -1,3 +1,3 @@
1
1
  module InfluxDBClient
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -48,27 +48,51 @@ module InfluxDBClient
48
48
  expect(Terminal::Table).to receive(:new).
49
49
  with(title: :series2, headings: %w[time value3 value4 value5 value6], rows: [[1394552447955, 3, 4, nil, nil], [1394664358980, nil, 4, 5, 6]])
50
50
 
51
- described_class.print_tabularize(result)
51
+ described_class.print_tabularize(result, :ms)
52
52
  end
53
53
 
54
54
  context 'when pretty' do
55
55
  before(:all) { described_class.pretty = true }
56
56
  after(:all) { described_class.pretty = false }
57
- it 'generates tables' do
58
- expect(Terminal::Table).to receive(:new).
59
- with(title: :series1, headings: %w[time value1 value2], rows: [['2013-12-17 13:42:03.160', 1, 2]])
60
57
 
61
- expect(Terminal::Table).to receive(:new).
62
- with(title: :series2, headings: %w[time value3 value4 value5 value6], rows: [['2014-03-11 15:40:47.549', 3, 4, nil, nil], ['2014-03-12 22:45:58.799', nil, 4, 5, 6]])
58
+ context 'and time precision is seconds' do
59
+ let(:result) { { series1: [{ 'time' => 1387287723, 'value1' => 1, 'value2' => 2 }] } }
60
+ it 'generates tables' do
61
+ expect(Terminal::Table).to receive(:new).
62
+ with(title: :series1, headings: %w[time value1 value2], rows: [['2013-12-17 13:42:03', 1, 2]])
63
+
64
+ described_class.print_tabularize(result, :s)
65
+ end
66
+ end
67
+
68
+ context 'and time precision is milliseconds' do
69
+ it 'generates tables' do
70
+ expect(Terminal::Table).to receive(:new).
71
+ with(title: :series1, headings: %w[time value1 value2], rows: [['2013-12-17 13:42:03.815', 1, 2]])
72
+
73
+ expect(Terminal::Table).to receive(:new).
74
+ with(title: :series2, headings: %w[time value3 value4 value5 value6], rows: [['2014-03-11 15:40:47.954', 3, 4, nil, nil], ['2014-03-12 22:45:58.980', nil, 4, 5, 6]])
63
75
 
64
- described_class.print_tabularize(result)
76
+ described_class.print_tabularize(result, :ms)
77
+ end
65
78
  end
79
+
80
+ context 'and time precision is microseconds' do
81
+ let(:result) { { series1: [{ 'time' => 1387287723816232, 'value1' => 1, 'value2' => 2 }] } }
82
+ it 'generates tables' do
83
+ expect(Terminal::Table).to receive(:new).
84
+ with(title: :series1, headings: %w[time value1 value2], rows: [['2013-12-17 13:42:03.816231', 1, 2]])
85
+
86
+ described_class.print_tabularize(result, :u)
87
+ end
88
+ end
89
+
66
90
  end
67
91
 
68
92
  it 'prints results' do
69
93
  output = double 'Output'
70
94
  table = double 'Table'
71
- Terminal::Table.stub(new: table)
95
+ allow(Terminal::Table).to receive(:new).and_return(table)
72
96
 
73
97
  # should print series1 and series2
74
98
  expect(output).to receive(:puts).twice.with(table)
@@ -78,7 +102,7 @@ module InfluxDBClient
78
102
  # line break for series
79
103
  expect(output).to receive(:puts).twice.with(no_args)
80
104
 
81
- described_class.print_tabularize(result, output)
105
+ described_class.print_tabularize(result, :ms, output)
82
106
  end
83
107
 
84
108
  context 'when no results' do
@@ -89,13 +113,13 @@ module InfluxDBClient
89
113
  output = double 'Output'
90
114
  result = {}
91
115
  expect(output).to receive(:puts).once.with('No results found')
92
- described_class.print_tabularize(result, output)
116
+ described_class.print_tabularize(result, :ms, output)
93
117
  end
94
118
 
95
119
  it 'prints specific no results found per series' do
96
120
  output = double 'Output'
97
121
  table = double 'Table'
98
- Terminal::Table.stub(new: table)
122
+ allow(Terminal::Table).to receive(:new).and_return(table)
99
123
 
100
124
  # should print series1
101
125
  expect(output).to receive(:puts).once.with(table)
@@ -106,7 +130,7 @@ module InfluxDBClient
106
130
  # line break for series
107
131
  expect(output).to receive(:puts).twice.with(no_args)
108
132
 
109
- described_class.print_tabularize(result, output)
133
+ described_class.print_tabularize(result, :ms, output)
110
134
  end
111
135
  end
112
136
 
@@ -115,10 +139,9 @@ module InfluxDBClient
115
139
  output = double 'Output'
116
140
  result = nil
117
141
  expect(output).to receive(:puts).once.with('No results found')
118
- described_class.print_tabularize(result, output)
142
+ described_class.print_tabularize(result, :ms, output)
119
143
  end
120
144
  end
121
145
  end
122
146
  end
123
147
  end
124
-
@@ -7,7 +7,18 @@ Dir['../lib/**/*.rb'].each &method(:require)
7
7
  require './lib/influxdb_client'
8
8
 
9
9
  RSpec.configure do |config|
10
- config.color_enabled = true
11
- config.formatter = 'progress'
10
+ original_stderr = $stderr
11
+ original_stdout = $stdout
12
+
13
+ config.before(:all) do
14
+ # Redirect stderr and stdout
15
+ $stderr = File.new('/dev/null', 'w')
16
+ $stdout = File.new('/dev/null', 'w')
17
+ end
18
+
19
+ config.after(:all) do
20
+ $stderr = original_stderr
21
+ $stdout = original_stdout
22
+ end
12
23
  end
13
24
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Cantero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-29 00:00:00.000000000 Z
11
+ date: 2014-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: influxdb