echo_cli 0.6.8 → 0.6.9
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/README.md +48 -3
- data/lib/echo_cli/cli.rb +65 -2
- data/lib/echo_cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e597bdd28e23fe7e16607780bb9ebe575f3379e
|
4
|
+
data.tar.gz: 78a3ac55ee5895b3837ce94d7b780a77f6509a91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d55971b389d14d8e91aee2485ceb05d7390b0ad724c3449ebc163c8f3d7befa1c83d3a0119b3cb465dac50ad339cc21bec7470edbdb937913aea57074ed6cca
|
7
|
+
data.tar.gz: c18037b41bdecd4b6e13f2cbe36fd43d2c9ae4da38c8cbe55d88aa72ed87c02df7aec2b9ac08b08a3aa6fc81419d31045b9dc5ef303fb7e31ebfbab4a5ca452d
|
data/README.md
CHANGED
@@ -42,6 +42,17 @@ $ echo_cli help [COMMAND]
|
|
42
42
|
|
43
43
|
### Commands
|
44
44
|
|
45
|
+
#### help
|
46
|
+
```bash
|
47
|
+
$ echo_cli help [COMMAND]
|
48
|
+
```
|
49
|
+
Provides a longer description and sample use case of an echo_cli command.
|
50
|
+
|
51
|
+
Example:
|
52
|
+
```bash
|
53
|
+
$ echo_cli help post
|
54
|
+
```
|
55
|
+
|
45
56
|
#### post
|
46
57
|
```bash
|
47
58
|
$ echo_cli post <IP> '<metric>' {number} {-q}
|
@@ -58,7 +69,13 @@ Parameters:
|
|
58
69
|
|
59
70
|
`{-q}`: (optional) does an automatic query of OpenTSDB immediately following the successful post of the metric to ensure the data transfer between StatsD and OpenTSDB. This option requires approx. 15 seconds to complete, as data flush and HA require ~15 seconds
|
60
71
|
|
61
|
-
|
72
|
+
Example:
|
73
|
+
```bash
|
74
|
+
$ echo_cli localhost 'sample.post.here:1|c' 10 -q
|
75
|
+
```
|
76
|
+
The previous example would post the metric 'sample' with tags 'post' and 'here' with data value '1' and with data type 'c' (for count). This information would be posted to the instance of StatsD located at 'localhost', and it would be posted 10. Additionally, because of the '-q' specified option, OpenTSDB will be queried immediately after the post to StatsD has been verified.
|
77
|
+
|
78
|
+
#### query
|
62
79
|
```bash
|
63
80
|
$ echo_cli query <IP> '<metric>' <time_start> <time_end> {-v}
|
64
81
|
```
|
@@ -74,9 +91,15 @@ Parameters:
|
|
74
91
|
|
75
92
|
`{-v}`: (optional) verbosely prints the status code and response body of the query
|
76
93
|
|
77
|
-
|
94
|
+
Example:
|
95
|
+
```bash
|
96
|
+
$ echo_cli localhost 'sample.query.here' 1492464745 1492465045 -v
|
97
|
+
```
|
98
|
+
The previous example will query OpenTSDB with the metric name 'sample' and tags 'query' and 'here' between the times of '1492464745' and '1492465045'. Additionally, the '-v' specified option will also return the response code and response body upon completion.
|
99
|
+
|
100
|
+
#### quick_query
|
78
101
|
```bash
|
79
|
-
$ echo_cli quick_query <IP> '<metric>' <range>
|
102
|
+
$ echo_cli quick_query <IP> '<metric>' <range> {-h}
|
80
103
|
```
|
81
104
|
Parameters:
|
82
105
|
|
@@ -86,6 +109,28 @@ Parameters:
|
|
86
109
|
|
87
110
|
`<range>`: (required) the time, in seconds from the current time (epoch time) that you would like to query, e.g. a 'range' value of 300 would query OpenTSDB for the specified metric in the last 5 minutes of time-series data
|
88
111
|
|
112
|
+
`{-e}`: (optional) formats the response datapoints such that their timestamps are in the epoch format
|
113
|
+
|
114
|
+
Example:
|
115
|
+
```bash
|
116
|
+
$ echo_cli localhost 'sample.query.here' 300
|
117
|
+
```
|
118
|
+
The previous example will query OpenTSDB located on 'localhost' 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.
|
119
|
+
|
120
|
+
#### convert
|
121
|
+
```bash
|
122
|
+
$ echo_cli convert <timestamp>
|
123
|
+
```
|
124
|
+
Parameters:
|
125
|
+
|
126
|
+
`<timestamp>`: (required) the timestamp you wish to convert, it can be given in either epoch time or a human-readable format. Ensure that the epoch timestamp is in seconds, and does not have any punctuation. Ensure that the human-readable timestamp is of the form: YYYY-MM-DDTHH:MM:SS-Z (decimals may follow the SS value).
|
127
|
+
|
128
|
+
Example:
|
129
|
+
```bash
|
130
|
+
$ echo_cli convert 1492186214
|
131
|
+
```
|
132
|
+
The previous example will convert the provided epoch timestamp into a human-readable format.
|
133
|
+
|
89
134
|
## Development
|
90
135
|
|
91
136
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/echo_cli/cli.rb
CHANGED
@@ -99,6 +99,8 @@ module Echo_cli
|
|
99
99
|
long_desc <<-LONGDESC
|
100
100
|
`echo_cli query` will query a metric directly from Echo's OpenTSDB server instance.
|
101
101
|
|
102
|
+
Timestamps are given in epoch time, in seconds.
|
103
|
+
|
102
104
|
If timestamps are unknown, echo_cli's post command provides time_start and time_end values for future querying.
|
103
105
|
|
104
106
|
Ensure single-quotes surround the metric.
|
@@ -192,7 +194,9 @@ module Echo_cli
|
|
192
194
|
return res.code
|
193
195
|
end
|
194
196
|
|
195
|
-
desc "quick_query", "Query metrics on Echo for a given time range beginning at the current time. Use \"echo_cli quick_query <IP> '<metric>' <range
|
197
|
+
desc "quick_query", "Query metrics on Echo for a given time range beginning at the current time. Use \"echo_cli quick_query <IP> '<metric>' <range> {-e}\""
|
198
|
+
|
199
|
+
option :e
|
196
200
|
|
197
201
|
long_desc <<-LONGDESC
|
198
202
|
`echo_cli quick_query` will query a metric directly from Echo's OpenTSDB server instance for a given time range beginning in the present.
|
@@ -203,6 +207,8 @@ module Echo_cli
|
|
203
207
|
|
204
208
|
The <range> parameter is defined in seconds, and is used to query the metric from the current time.
|
205
209
|
|
210
|
+
With -e (epoch) option, echo_cli will format the response datapoints such that their timestamps will be in epoch format.
|
211
|
+
|
206
212
|
> $ echo_cli quick_query localhost 'example' 30
|
207
213
|
|
208
214
|
The previous example would find all data points with metric name 'example' on Echo's OpenTSDB instance at 'localhost' in the last 30 seconds.
|
@@ -269,7 +275,21 @@ module Echo_cli
|
|
269
275
|
begin
|
270
276
|
res = https.request(req)
|
271
277
|
if res.code == '200'
|
272
|
-
|
278
|
+
|
279
|
+
json = JSON.parse(res.body)
|
280
|
+
|
281
|
+
if !options[:e]
|
282
|
+
obj = {}
|
283
|
+
for i in json[0]["dps"].keys do
|
284
|
+
Helper.new.stfu do
|
285
|
+
obj[convert(i)] = JSON.parse(res.body)[0]["dps"][i]; nil
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
json[0]["dps"] = obj
|
290
|
+
end
|
291
|
+
|
292
|
+
puts "\nSuccessfully retrieved ".green + metric.yellow + " from ".green + ip.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
|
273
293
|
else
|
274
294
|
puts "\nFailed to retrieve ".red + metric.yellow + " from ".red + ip.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
|
275
295
|
end
|
@@ -281,7 +301,50 @@ module Echo_cli
|
|
281
301
|
ENV["https_proxy"] = ""
|
282
302
|
|
283
303
|
return res.code
|
304
|
+
end
|
305
|
+
|
306
|
+
desc "convert", "Convert epoch timestamps to a human-readable format (YYYY-MM-DDTHH:MM:SS-Z), or vice-versa. Use \"echo_cli convert <timestamp>\""
|
307
|
+
|
308
|
+
long_desc <<-LONGDESC
|
309
|
+
`echo_cli convert` will convert a given timestamp from epoch to a human-readable format, or vice-versa. Useful for determining locations of data on grafana. Ensure that an epoch timestamp has no punctation, and a human-readable timestamp follows the format 'YYYY-MM-DDTHH:MM:SS.SSS-Z' exactly.
|
284
310
|
|
311
|
+
Epoch timestamp example: 1492186214
|
312
|
+
|
313
|
+
Human-readable date/time timestamp example: 2011-10-18T21:01:52-07:00
|
314
|
+
|
315
|
+
> $ echo_cli convert 1492186214
|
316
|
+
|
317
|
+
> $ echo_cli convert 2011-10-18T21:01:52-07:00
|
318
|
+
LONGDESC
|
319
|
+
|
320
|
+
def convert(timestamp)
|
321
|
+
if timestamp.include? ":"
|
322
|
+
time = Time.iso8601(timestamp).to_i.to_s
|
323
|
+
else
|
324
|
+
time = Time.at(timestamp.to_i).to_datetime.to_s
|
325
|
+
end
|
326
|
+
puts "\nConverted timstamp: ".green + time.yellow
|
327
|
+
return time
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
class Helper
|
332
|
+
def stfu
|
333
|
+
begin
|
334
|
+
orig_stderr = $stderr.clone
|
335
|
+
orig_stdout = $stdout.clone
|
336
|
+
$stderr.reopen File.new('/dev/null', 'w')
|
337
|
+
$stdout.reopen File.new('/dev/null', 'w')
|
338
|
+
retval = yield
|
339
|
+
rescue Exception => e
|
340
|
+
$stdout.reopen orig_stdout
|
341
|
+
$stderr.reopen orig_stderr
|
342
|
+
raise e
|
343
|
+
ensure
|
344
|
+
$stdout.reopen orig_stdout
|
345
|
+
$stderr.reopen orig_stderr
|
346
|
+
end
|
347
|
+
retval
|
285
348
|
end
|
286
349
|
end
|
287
350
|
end
|
data/lib/echo_cli/version.rb
CHANGED
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.
|
4
|
+
version: 0.6.9
|
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-04-
|
11
|
+
date: 2017-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|