echo_cli 0.6.19 → 0.6.20

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: 061f3487e6d0be96c2a48f11c114c4dd2128e887
4
- data.tar.gz: 0d3a15469d351b5c10371e1f4b04fa8409443915
3
+ metadata.gz: cd5f609e5d770299aa3c77843c4f22d1a8ce5243
4
+ data.tar.gz: 0128cf4cddd4dc07ecb9a6e1cad5f89c1df46c9e
5
5
  SHA512:
6
- metadata.gz: 26483bcb7d0eeb6e7444017201afe0e22fc19b2226e3ae50a325a4b236946426187972239abd4de52c973d5abe09ac40826528916774f8317c24f6b648868f65
7
- data.tar.gz: 8691197e9f88518fa22ab15da0fcc97a72f68270656b87beeb62f47762f9d3af5e332bfbd1728c0895d10bdc80ad99c37cea45aaa73376831e817beeb4f289a6
6
+ metadata.gz: 1056a5fa9b7197db6a646d37892f8f2086fac67b49124d33c5c0a6ec20dbb2aaf9cf040178f5d51617a622e1f0a977278dfce2e2f84e8f9c908582650f840a89
7
+ data.tar.gz: c0016a5bef2ee41db51406ea3a12cbf70fcbc0f5de5435ccd0642ecab0f42b875614a69af093d5cd080a19ab4ecb4f6d740b36d8296547b2d2ba095e1582c3d6
data/README.md CHANGED
@@ -110,7 +110,7 @@ The previous example would post the metric 'sample' with tags 'post' and 'here'
110
110
 
111
111
  #### query
112
112
  ```bash
113
- $ echo_cli query <URL> '<metric>' <time_start> <time_end> {-v}
113
+ $ echo_cli query <URL> '<metric>' <time_start> <time_end> {-v} {-e} {-s}
114
114
  ```
115
115
  Parameters:
116
116
 
@@ -124,6 +124,10 @@ Parameters:
124
124
 
125
125
  `{-v}`: (optional) verbosely prints the status code and response body of the query
126
126
 
127
+ `{-e}`: (optional) formats the response datapoints such that their timestamps are in the epoch format, must have '-v' option selected for changes to appear
128
+
129
+ `{-s}`: (optional) formats the response datapoints to be usable as SQL statements for insertions into SQL-esque databases, must have '-v' option selected for changes to appear
130
+
127
131
  Example:
128
132
  ```bash
129
133
  $ echo_cli https://localhost:4242/api/query 'sample.query.here' 1492464745 1492465045 -v
@@ -132,7 +136,7 @@ The previous example will query OpenTSDB with the metric name 'sample' and tags
132
136
 
133
137
  #### quick_query
134
138
  ```bash
135
- $ echo_cli quick_query <URL> '<metric>' <range> {-h}
139
+ $ echo_cli quick_query <URL> '<metric>' <range> {-e} {-s}
136
140
  ```
137
141
  Parameters:
138
142
 
@@ -144,11 +148,13 @@ Parameters:
144
148
 
145
149
  `{-e}`: (optional) formats the response datapoints such that their timestamps are in the epoch format
146
150
 
151
+ `{-s}`: (optional) formats the response datapoints to be usable as SQL statements for insertions into SQL-esque databases
152
+
147
153
  Example:
148
154
  ```bash
149
- $ echo_cli https://localhost:4242/api/query 'sample.query.here' 300
155
+ $ echo_cli https://localhost:4242/api/query 'sample.query.here' 300 -s
150
156
  ```
151
- The previous example will query OpenTSDB located on 'https://localhost:4242/api/query' with the metric name 'sample' and tags 'query' and 'here', within the time range spanning from the current time to '300' seconds before the current time.
157
+ The previous example will query OpenTSDB located on 'https://localhost:4242/api/query' with the metric name 'sample' and tags 'query' and 'here', within the time range spanning from the current time to '300' seconds before the current time. The '-s' option will return the data as SQL statements for later insertion into a SQL database.
152
158
 
153
159
  ## Development
154
160
 
data/lib/echo_cli/cli.rb CHANGED
@@ -161,9 +161,11 @@ module Echo_cli
161
161
 
162
162
  end
163
163
 
164
- desc "query", "Query metrics on Echo. Use \"echo_cli query <URL> '<metric>' <time_start> <time_end> {-v}\""
164
+ desc "query", "Query metrics on Echo. Use \"echo_cli query <URL> '<metric>' <time_start> <time_end> {-v} {-e} {-s}\""
165
165
 
166
166
  option :v
167
+ option :e
168
+ option :s
167
169
 
168
170
  long_desc <<-LONGDESC
169
171
  `echo_cli query` will query a metric directly from Echo's OpenTSDB server instance.
@@ -178,6 +180,10 @@ module Echo_cli
178
180
 
179
181
  With -v (verbose) option, query will print the status code and response body upon completion of the request.
180
182
 
183
+ With -e (epoch) option, echo_cli will format the response datapoints, with the verbose ('-v') option selected, such that their timestamps will be in epoch format.
184
+
185
+ With -s (sql) option, echo_cli will format the response data, with the verbose ('-v') option selected, to be usable within a sql database.
186
+
181
187
  > $ echo_cli query https://localhost:4242/api/query 'example.post' 1492186212 1492186214 {-v}
182
188
  LONGDESC
183
189
 
@@ -197,16 +203,39 @@ module Echo_cli
197
203
  req.body = opentsdb_query
198
204
 
199
205
  if options[:v]
200
- begin
206
+ # begin
201
207
  res = https.request(req)
202
208
  if res.code == '200'
203
- puts "\nSuccessfully retrieved ".green + metric_name.yellow + " from ".green + opentsdb_uri.blue + " in timestamp range: ".green + time_start.yellow + " to ".green + time_end.yellow + "\nStatus Code: ".green + res.code.yellow + "\nResponse Body: ".green + JSON.pretty_generate(JSON.parse(res.body)).green
209
+
210
+ json = JSON.parse(res.body)[0]
211
+
212
+ if !options[:e]
213
+ json["dps"] = {}
214
+ for i in JSON.parse(res.body)[0]["dps"].keys do
215
+ Helper.new.stfu do
216
+ json["dps"][convert(i)] = JSON.parse(res.body)[0]["dps"][i]
217
+ end
218
+ end
219
+ end
220
+
221
+ if options[:s]
222
+ sql = "CREATE TABLE " + metric + "(\n sep VARCHAR(24) NOT NULL PRIMARY KEY\n ,FIELD2 VARCHAR(21) NOT NULL\n);"
223
+ for i in json["dps"].keys do
224
+ Helper.new.stfu do
225
+ sql = sql + "\nINSERT INTO " + metric + "(sep,FIELD2) VALUES ('" + i.to_s + "','" + json["dps"][i].to_s + "');"
226
+ end
227
+ end
228
+
229
+ puts "\nSuccessfully retrieved ".green + metric_name.yellow + " from ".green + opentsdb_uri.blue + " in timestamp range: ".green + time_start.yellow + " to ".green + time_end.yellow + "\nSQL-ized data points:\n\n".green + sql.green
230
+ else
231
+ puts "\nSuccessfully retrieved ".green + metric_name.yellow + " from ".green + opentsdb_uri.blue + " in timestamp range: ".green + time_start.yellow + " to ".green + time_end.yellow + "\nData points:\n\n".green + JSON.pretty_generate(json).green
232
+ end
204
233
  else
205
234
  puts "\nFailed to retrieve ".red + metric_name.yellow + " from ".red + opentsdb_uri.blue + " in timestamp range: ".red + time_start.yellow + " to ".red + time_end.yellow + "\nStatus Code: ".red + res.code.yellow + "\nResponse Body: ".red + JSON.pretty_generate(JSON.parse(res.body)).red
206
235
  end
207
- rescue
208
- puts "\nYour request returned an error. Are you sure your query was correct?"
209
- end
236
+ # rescue
237
+ # puts "\nYour request returned an error. Are you sure your query was correct?"
238
+ # end
210
239
  else
211
240
  begin
212
241
  res = https.request(req)
@@ -225,9 +254,10 @@ module Echo_cli
225
254
  return res.code
226
255
  end
227
256
 
228
- desc "quick_query", "Query metrics on Echo from the current time. Use \"echo_cli quick_query <URL> '<metric>' <range> {-e}\""
257
+ desc "quick_query", "Query metrics on Echo from the current time. Use \"echo_cli quick_query <URL> '<metric>' <range> {-e} {-s}\""
229
258
 
230
259
  option :e
260
+ option :s
231
261
 
232
262
  long_desc <<-LONGDESC
233
263
  `echo_cli quick_query` will query a metric directly from Echo's OpenTSDB server instance for a given time range beginning in the present.
@@ -240,6 +270,8 @@ module Echo_cli
240
270
 
241
271
  With -e (epoch) option, echo_cli will format the response datapoints such that their timestamps will be in epoch format.
242
272
 
273
+ With -s (sql) option, echo_cli will format the response data to be usable within a sql database.
274
+
243
275
  > $ echo_cli quick_query https://localhost:4242/api/query 'example' 30
244
276
 
245
277
  The previous example would find all data points with metric name 'example' on Echo's OpenTSDB instance at 'localhost' in the last 30 seconds.
@@ -275,12 +307,23 @@ module Echo_cli
275
307
  json["dps"] = {}
276
308
  for i in JSON.parse(res.body)[0]["dps"].keys do
277
309
  Helper.new.stfu do
278
- json[convert(i)] = JSON.parse(res.body)[0]["dps"][i]
310
+ json["dps"][convert(i)] = JSON.parse(res.body)[0]["dps"][i]
279
311
  end
280
312
  end
281
313
  end
282
314
 
283
- puts "\nSuccessfully retrieved ".green + metric_name.yellow + " from ".green + opentsdb_uri.blue + " in timestamp range: ".green + time_start.yellow + " to ".green + time_end.yellow + "\nData points in the last ".green + range.yellow + " seconds:\n".green + JSON.pretty_generate(json).green
315
+ if options[:s]
316
+ sql = "CREATE TABLE " + metric + "(\n sep VARCHAR(24) NOT NULL PRIMARY KEY\n ,FIELD2 VARCHAR(21) NOT NULL\n);"
317
+ for i in json["dps"].keys do
318
+ Helper.new.stfu do
319
+ sql = sql + "\nINSERT INTO " + metric + "(sep,FIELD2) VALUES ('" + i.to_s + "','" + json["dps"][i].to_s + "');"
320
+ end
321
+ end
322
+
323
+ puts "\nSuccessfully retrieved ".green + metric_name.yellow + " from ".green + opentsdb_uri.blue + " in timestamp range: ".green + time_start.yellow + " to ".green + time_end.yellow + "\nSQL-ized data points in the last ".green + range.yellow + " seconds:\n\n".green + sql.green
324
+ else
325
+ puts "\nSuccessfully retrieved ".green + metric_name.yellow + " from ".green + opentsdb_uri.blue + " in timestamp range: ".green + time_start.yellow + " to ".green + time_end.yellow + "\nData points in the last ".green + range.yellow + " seconds:\n\n".green + JSON.pretty_generate(json).green
326
+ end
284
327
  else
285
328
  puts "\nFailed to retrieve ".red + metric_name.yellow + " from ".red + opentsdb_uri.blue + " in timestamp range: ".red + time_start.yellow + " to ".red + time_end.yellow + "\nStatus Code: ".red + res.code.yellow + "\nResponse Body: ".red + JSON.pretty_generate(JSON.parse(res.body)).red
286
329
  end
@@ -1,3 +1,3 @@
1
1
  module Echo_cli
2
- VERSION = "0.6.19"
2
+ VERSION = "0.6.20"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: echo_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.19
4
+ version: 0.6.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Raphael
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-08 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor