influxdb-cli 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7666677d00e9a4dcc1c06b306998e0780a8494c8
4
- data.tar.gz: 0616e96d6e8900499a1c52be38d66008b3220429
3
+ metadata.gz: eee6c28061fbb73ce08132bce8f324e50d84f3e4
4
+ data.tar.gz: 7aa0b0fcd32f70564339e928e1da503f23b8704d
5
5
  SHA512:
6
- metadata.gz: 8e60dfecba7fd8940b9c3a94facab13d57c12c01e051d40ff4eb816687e972fe9eefd4e57f8a74f4a5e3f8e298097e172be80bd2da0e162ea964e66c81ca6011
7
- data.tar.gz: 4c8ccfab14ab6d6c9bc1c07d159cd3ec346b65c1742fc8ac382604146f13060fa69f48f4a364d41e04cc64cc76246d4a3b4fbabb767760aaccea9fa932b5ad2c
6
+ metadata.gz: 43daad92887c4ff7d7bdbf35bfa647a9159f26edf52f792ba96c71087f097788d55384d19e08634e040823aac1afd6bc29b59a24fcc10351a705ad29251e1517
7
+ data.tar.gz: ff157af73651e607020e348e7d3d1fde35bc3818e29e8ef655465defb37d58db8bca92017449fe464debe795dd6b321b23d50f4393ca870411dc6e1ebf0ca6c2
data/README.md CHANGED
@@ -30,15 +30,30 @@ Options:
30
30
 
31
31
  ### Usage
32
32
 
33
- [Tabularized](https://github.com/visionmedia/terminal-table) output:
33
+ Connect to a database:
34
34
 
35
35
  ```shell
36
36
  influxdb-cli
37
37
  Connecting to {"host"=>"localhost", "port"=>8086, "username"=>"root", "password"=>"root", "database"=>"db"}
38
38
  ✔ ready
39
- 2.0.0 (main)> query('select * from cap limit 1')
39
+ ```
40
+
41
+ or
42
+
43
+ ```shell
44
+ influxdb-cli -u user -p password -d database -h sandbox.influxdb.org --port 9061
45
+ Connecting to {"host"=>"sandbox.influxdb.org", "port"=>"9061", "username"=>"phstc", "password"=>"RggLimEQfK36or", "database"=>"spree"}
46
+ ✔ ready
47
+ ```
48
+
49
+ [InfluxDB Playground](http://play.influxdb.org) :metal:
50
+
51
+ Query with a [tabularized](https://github.com/visionmedia/terminal-table) output:
52
+
53
+ ```shell
54
+ 2.0.0 (main)> SELECT * FROM deploys
40
55
  +---------------+-----------------+-----------------+--------+-----------------+-------------------+----------+
41
- | cap |
56
+ | deploys |
42
57
  +---------------+-----------------+-----------------+--------+-----------------+-------------------+----------+
43
58
  | time | sequence_number | application | branch | latest_revision | previous_revision | stage |
44
59
  +---------------+-----------------+-----------------+--------+-----------------+-------------------+----------+
@@ -46,12 +61,12 @@ Connecting to {"host"=>"localhost", "port"=>8086, "username"=>"root", "password"
46
61
  +---------------+-----------------+-----------------+--------+-----------------+-------------------+----------+
47
62
 
48
63
  => {
49
- "cap.count" => 1
64
+ "deploys.count" => 1
50
65
  }
51
66
  ```
52
67
 
53
68
 
54
- Ruby Hash output ([awesome_print](https://github.com/michaeldv/awesome_print)):
69
+ Query with a Ruby Hash output ([awesome_print](https://github.com/michaeldv/awesome_print)):
55
70
 
56
71
  ```shell
57
72
  2.0.0 (main)> db.query('SELECT * FROM deploys')
@@ -68,6 +83,7 @@ Ruby Hash output ([awesome_print](https://github.com/michaeldv/awesome_print)):
68
83
  },
69
84
  ```
70
85
 
86
+ Other methods:
71
87
 
72
88
  ```shell
73
89
  2.0.0 (main)> db.write_point(name, data)
@@ -28,26 +28,44 @@ class InfluxDBClientTasks < Thor
28
28
  default_task :db
29
29
  end
30
30
 
31
+ # Returns {InfluxDB::Client} instance using given parameters.
32
+ #
33
+ # @return [InfluxDB::Client]
31
34
  def db; InfluxDBClientTasks.db; end
32
35
 
36
+ # Queries data using {http://influxdb.org/docs/query_language/ InfluxDB Query Language}
37
+ # and prints a tabularized output.
38
+ #
39
+ # i.e. query('select value from response_times')
40
+ #
41
+ # @see InfluxDB::Client#query
42
+ #
43
+ # @return [Hash] the number of points per time series i.e. { 'response_times.count' => 10 }
33
44
  def query(query)
34
45
  result = db.query(query)
35
- count = {}
36
- result.to_h.keys.each do |serie_name|
37
- headings = result[serie_name].first.keys
38
- rows = result[serie_name].collect(&:values)
39
- table = Terminal::Table.new title: serie_name, headings: headings, rows: rows
46
+ number_of_points = {}
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
40
51
  puts table
41
- # empty line
52
+ # empty line between time series output
42
53
  puts
43
- # count total per serie
44
- count["#{serie_name}.count"] = result[serie_name].size
54
+ # count total per time series
55
+ number_of_points["#{series}.count"] = result[series].size
45
56
  end
46
- count
57
+ number_of_points
58
+ end
59
+
60
+ # allow typing queries directly from console i.e.`select * from deploys` instead of `query('select * from deploys')`.
61
+ # matches `delete from ...` and `select ... from ...`
62
+ Pry::Commands.block_command /\A\s*((delete\s+from|select\s+.+\s+from)\s*.+)\z/i, 'Execute a query' do |cmd|
63
+ query(cmd)
47
64
  end
48
65
 
49
66
  InfluxDBClientTasks.start
50
67
 
68
+ # awesome_print
51
69
  Pry.config.print = proc { |output, value| Pry::Helpers::BaseHelpers.stagger_output("=> #{value.ai}", output) }
52
70
 
53
71
  pry
@@ -1,3 +1,3 @@
1
1
  module InfluxDBClient
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Cantero