influxdb-cli 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/bin/influxdb-cli +8 -16
- data/lib/influxdb_client/client.rb +18 -11
- data/lib/influxdb_client/version.rb +1 -1
- data/spec/influxdb_client/client_spec.rb +7 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7a4f8e0419999de09aa047254204462f8150b6d
|
4
|
+
data.tar.gz: f468e14d522630cc1e4b6de1970e3484ba2b8051
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83f22cfbe7d9c64fb8189cf2b37f0dbbf66db33aef45d658e251c77179fca54c18a0b6ffa79d57d439c7a65eea83e1be17d9034e6432c19e5992e1615162a723
|
7
|
+
data.tar.gz: 714a92645856fecd8e2cc3f8b85ef0ab3e6bdce44c7183c4ce274e214834ed235235a7c18a1969f8b0e8951fbdeae4e5d77a528652f90ec5df9ef35e683ee7d8
|
data/.travis.yml
CHANGED
data/bin/influxdb-cli
CHANGED
@@ -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
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
#
|
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.
|
31
|
-
|
32
|
-
|
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
|
@@ -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 '
|
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 '
|
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
|