influxdb-cli 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -0
- data/README.md +1 -0
- data/bin/influxdb-cli +16 -17
- data/lib/influxdb_client.rb +3 -0
- data/lib/influxdb_client/client.rb +23 -0
- data/lib/influxdb_client/version.rb +1 -1
- data/spec/influxdb_client/client_spec.rb +62 -0
- data/spec/spec_helper.rb +2 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38b568164a56da1eae7c93bbcde1166c19f2faa1
|
4
|
+
data.tar.gz: 548d3721361e117c98f497e6d6201d07733f85ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af16d981b18cae9e55794bbd2c4cdde9857ee1a947480591d49c76e4f6c66d71f177afe3bb0a863ac99595d7ec27cde6297f859f3983e8e4ab7cea19459db906
|
7
|
+
data.tar.gz: 2c37000746bd70fb357e99ef5fd846f7faaf30c4d1d0245e58f04f91dcff03ba1f0f81f5121dcbda7be35ee3e32caa3aee453c5f5cdf163e020c1deaab4aa472
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -3,6 +3,7 @@ InfluxDB-CLI
|
|
3
3
|
|
4
4
|
Ruby CLI for InfluxDB is a simple Ruby console (empowered with [Pry](https://github.com/pry/pry)) connected to an InfluxDB server with supplied parameters. In order to connect to InfluxDB, it uses [influxdb-ruby](https://github.com/influxdb/influxdb-ruby), so you can access any avaiable method from influxdb-ruby in the console through the `db` variable i.e.: `db.write_point(name, data)`, `db.query('SELECT value FROM response_times')` etc.
|
5
5
|
|
6
|
+
[![Build Status](https://secure.travis-ci.org/phstc/influxdb-cli.png)](http://travis-ci.org/phstc/influxdb-cli)
|
6
7
|
|
7
8
|
### Installation
|
8
9
|
```shell
|
data/bin/influxdb-cli
CHANGED
@@ -5,9 +5,11 @@ require 'influxdb'
|
|
5
5
|
require 'pry'
|
6
6
|
require 'thor'
|
7
7
|
require 'awesome_print'
|
8
|
-
require 'terminal-table'
|
9
8
|
|
10
|
-
|
9
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
10
|
+
|
11
|
+
require 'influxdb_client/version'
|
12
|
+
require 'influxdb_client/client'
|
11
13
|
|
12
14
|
class InfluxDBClientTasks < Thor
|
13
15
|
desc 'db', 'Connect to InfluxDB'
|
@@ -23,6 +25,13 @@ class InfluxDBClientTasks < Thor
|
|
23
25
|
puts '✔ ready'
|
24
26
|
end
|
25
27
|
|
28
|
+
desc 'version', 'Show influxdb-cli version'
|
29
|
+
def version
|
30
|
+
puts "influxdb-cli #{InfluxDBClient::VERSION}"
|
31
|
+
# skip `pry` console
|
32
|
+
exit 0
|
33
|
+
end
|
34
|
+
|
26
35
|
def self.db; @@db; end
|
27
36
|
|
28
37
|
default_task :db
|
@@ -43,30 +52,20 @@ def db; InfluxDBClientTasks.db; end
|
|
43
52
|
# @return [Hash] the number of points per time series i.e. { 'response_times.count' => 10 }
|
44
53
|
def query(query)
|
45
54
|
result = db.query(query)
|
46
|
-
|
47
|
-
result.to_h.keys.each do |series|
|
48
|
-
headings = result[series].first.keys
|
49
|
-
rows = result[series].collect(&:values)
|
50
|
-
table = Terminal::Table.new title: series, headings: headings, rows: rows
|
51
|
-
puts table
|
52
|
-
# empty line between time series output
|
53
|
-
puts
|
54
|
-
# count total per time series
|
55
|
-
number_of_points["#{series}.count"] = result[series].size
|
56
|
-
end
|
57
|
-
number_of_points
|
55
|
+
InfluxDBClient::Client.print_tabularize(result)
|
58
56
|
end
|
59
57
|
|
58
|
+
InfluxDBClientTasks.start
|
59
|
+
|
60
60
|
# allow typing queries directly from console i.e.`select * from deploys` instead of `query('select * from deploys')`.
|
61
61
|
# matches `delete from ...` and `select ... from ...`
|
62
|
-
Pry::Commands.block_command
|
62
|
+
Pry::Commands.block_command InfluxDBClient::Client::QUERY_LANGUAGE_MATCHER, 'Execute a query' do |cmd|
|
63
63
|
query(cmd)
|
64
64
|
end
|
65
65
|
|
66
|
-
InfluxDBClientTasks.start
|
67
|
-
|
68
66
|
# awesome_print
|
69
67
|
Pry.config.print = proc { |output, value| Pry::Helpers::BaseHelpers.stagger_output("=> #{value.ai}", output) }
|
70
68
|
|
69
|
+
# TODO start `pry` only in case of `db` command, `help` and `version` should not start `pry`
|
71
70
|
pry
|
72
71
|
|
data/lib/influxdb_client.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'terminal-table'
|
2
|
+
|
3
|
+
module InfluxDBClient
|
4
|
+
class Client
|
5
|
+
QUERY_LANGUAGE_MATCHER = /\A\s*((delete\s+from|select\s+.+\s+from)\s.+)\z/i
|
6
|
+
|
7
|
+
def self.print_tabularize(result, output=$stdout)
|
8
|
+
number_of_points = {}
|
9
|
+
result.keys.each do |series|
|
10
|
+
headings = result[series].first.keys
|
11
|
+
rows = result[series].collect(&:values)
|
12
|
+
table = Terminal::Table.new title: series, headings: headings, rows: rows
|
13
|
+
output.puts table
|
14
|
+
# empty line between time series output
|
15
|
+
output.puts
|
16
|
+
# count total per time series
|
17
|
+
number_of_points["#{series}.count"] = result[series].size
|
18
|
+
end
|
19
|
+
number_of_points
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module InfluxDBClient
|
4
|
+
describe Client do
|
5
|
+
describe '.QUERY_LANGUAGE_MATCHER' do
|
6
|
+
subject { Client::QUERY_LANGUAGE_MATCHER }
|
7
|
+
context 'when SELECT queries' do
|
8
|
+
it { should match('SELECT value1, value2 FROM response_times') }
|
9
|
+
it { should match('select * from response_times') }
|
10
|
+
it { should match('SELECT * FROM series1, series2') }
|
11
|
+
it { should match('SELECT * FROM series1, series2 LIMIT 1') }
|
12
|
+
|
13
|
+
it { should_not match('SELECT value1, value2FROM response_times') }
|
14
|
+
it { should_not match('select from response_times') }
|
15
|
+
it { should_not match('SELECT * FROM') }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when DELETE queries' do
|
19
|
+
it { should match('DELETE FROM response_times') }
|
20
|
+
it { should match('delete from series1, series2') }
|
21
|
+
|
22
|
+
it { should_not match('DELETEFROM response_times') }
|
23
|
+
it { should_not match('delete value1, value2 from series1, series2') }
|
24
|
+
it { should_not match('DELETE * FROM series1, series2') }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.print_tabularize' do
|
29
|
+
let(:result) { { series1: [{ value1: 1, value2: 2 }],
|
30
|
+
series2: [{ value3: 3, value4: 4, value5: nil, value6: nil },
|
31
|
+
{ value3: nil, value4: 4, value5: 5, value6: 6 }] } }
|
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
|
+
it 'generates tables' do
|
38
|
+
expect(Terminal::Table).to receive(:new).
|
39
|
+
with(title: :series1, headings: [:value1, :value2], rows: [[1, 2]])
|
40
|
+
|
41
|
+
expect(Terminal::Table).to receive(:new).
|
42
|
+
with(title: :series2, headings: [:value3, :value4, :value5, :value6], rows: [[3, 4, nil, nil], [nil, 4, 5, 6]])
|
43
|
+
|
44
|
+
described_class.print_tabularize(result)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'puts tables' do
|
48
|
+
output = double 'Output'
|
49
|
+
table = double 'Table'
|
50
|
+
Terminal::Table.stub(new: table)
|
51
|
+
|
52
|
+
# should print series1 and series2
|
53
|
+
expect(output).to receive(:puts).twice.with(table)
|
54
|
+
# line break for series
|
55
|
+
expect(output).to receive(:puts).twice.with(no_args)
|
56
|
+
|
57
|
+
described_class.print_tabularize(result, output)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/spec/spec_helper.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Cantero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: influxdb
|
@@ -132,6 +132,7 @@ extra_rdoc_files: []
|
|
132
132
|
files:
|
133
133
|
- .gitignore
|
134
134
|
- .rspec
|
135
|
+
- .travis.yml
|
135
136
|
- Gemfile
|
136
137
|
- LICENSE.txt
|
137
138
|
- README.md
|
@@ -139,7 +140,9 @@ files:
|
|
139
140
|
- bin/influxdb-cli
|
140
141
|
- influxdb-cli.gemspec
|
141
142
|
- lib/influxdb_client.rb
|
143
|
+
- lib/influxdb_client/client.rb
|
142
144
|
- lib/influxdb_client/version.rb
|
145
|
+
- spec/influxdb_client/client_spec.rb
|
143
146
|
- spec/spec_helper.rb
|
144
147
|
homepage: https://github.com/phstc/influxdb-cli
|
145
148
|
licenses: []
|
@@ -165,4 +168,5 @@ signing_key:
|
|
165
168
|
specification_version: 4
|
166
169
|
summary: Ruby CLI for InfluxDB
|
167
170
|
test_files:
|
171
|
+
- spec/influxdb_client/client_spec.rb
|
168
172
|
- spec/spec_helper.rb
|