echo_cli 0.6.31 → 0.6.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -1
- data/echo_cli.gemspec +1 -0
- data/lib/echo_cli/cli.rb +66 -3
- data/lib/echo_cli/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25536f05cb3b0450889c3ac1e6fe6fdb223dd5e8
|
4
|
+
data.tar.gz: ed64ce29b3318c3a77dce4381972114a62ff6a39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e85a94067b22e442552d944056dd6431d0e4efc264afb0f5bce0bbe2991789e059c2368f76e2ff68814fd4e28b2474a0324228035afe793fff915d40f536c34
|
7
|
+
data.tar.gz: a8f3b1d2c714bc4eec19dec7fd9ff14c54d769f430f29a4f46daccea4a7c04bb3d8d06f1057db9be4578408a78a01e5b4896d1a826ad3a5864f5ee6d6c6891de
|
data/README.md
CHANGED
@@ -158,6 +158,24 @@ Example:
|
|
158
158
|
$ echo_cli now
|
159
159
|
```
|
160
160
|
|
161
|
+
#### populate
|
162
|
+
```bash
|
163
|
+
$ echo_cli populate '<metric>' {timespan} {frequency}
|
164
|
+
```
|
165
|
+
Parameters:
|
166
|
+
|
167
|
+
`'<metric>'`: (required) the application name, as well as any tags, and data value and data type to be posted to StatsD. Note the single-quotes surrounding the metric, these are required as well.
|
168
|
+
|
169
|
+
`{timespan}`: (optional) the length of time to populate data for the given metric, given in seconds. This value defaults to 1209600 seconds (2 weeks).
|
170
|
+
|
171
|
+
`{frequency}`: (optional) the frequency with which data will be back-populated, given in seconds. This value defaults to 600 seconds (10 minutes).
|
172
|
+
|
173
|
+
Example:
|
174
|
+
```bash
|
175
|
+
$ echo_cli populate 'sample.back.populate:1|c'
|
176
|
+
```
|
177
|
+
The previous example would populate random data (between 1-100) within the metric 'sample.back.populate' for the previous 2 weeks, at a frequency of once every 10 minutes.
|
178
|
+
|
161
179
|
#### post
|
162
180
|
```bash
|
163
181
|
$ echo_cli post '<metric>' {number} {-z}
|
@@ -172,7 +190,7 @@ Parameters:
|
|
172
190
|
|
173
191
|
Example:
|
174
192
|
```bash
|
175
|
-
$ echo_cli 'sample.post.here:1|c' 10
|
193
|
+
$ echo_cli post 'sample.post.here:1|c' 10
|
176
194
|
```
|
177
195
|
The previous example would post the application name '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, and it would be posted 10 times.
|
178
196
|
|
data/echo_cli.gemspec
CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
|
32
32
|
spec.add_runtime_dependency 'thor', '~> 0'
|
33
33
|
spec.add_runtime_dependency 'colorize', '~> 0'
|
34
|
+
spec.add_runtime_dependency 'highline', '~> 1.7.8'
|
34
35
|
|
35
36
|
spec.add_development_dependency "bundler", "~> 1.14"
|
36
37
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/echo_cli/cli.rb
CHANGED
@@ -8,6 +8,7 @@ require 'net/https'
|
|
8
8
|
require 'uri'
|
9
9
|
require 'openssl'
|
10
10
|
require 'timeout'
|
11
|
+
require "highline/import"
|
11
12
|
|
12
13
|
module Echo_cli
|
13
14
|
class Echo < Thor
|
@@ -26,7 +27,7 @@ module Echo_cli
|
|
26
27
|
|
27
28
|
Ensure the environment variable 'ECHO_CLI_HOST' is set to the correct IP.
|
28
29
|
|
29
|
-
With the -z (zombie) option, post will continuously send the metric to Echo
|
30
|
+
With the -z (zombie) option, post will continuously send the metric to Echo a random number of times every second in the background, and return its PID for future removal. Use "$ kill -9 <PID>" to kill the zombie process.
|
30
31
|
|
31
32
|
The -z option will override the {number} parameter, should both be included in an execution of the command.
|
32
33
|
|
@@ -48,9 +49,10 @@ module Echo_cli
|
|
48
49
|
helper.do_post_tcp(ENV["ECHO_CLI_HOST"], "8125", metric)
|
49
50
|
|
50
51
|
pid = Process.fork do
|
52
|
+
prng = Random.new
|
51
53
|
while true do
|
52
54
|
helper.do_post_tcp(ENV["ECHO_CLI_HOST"], "8125", metric)
|
53
|
-
sleep 1
|
55
|
+
sleep prng.rand(0.1...1.0)
|
54
56
|
end
|
55
57
|
end
|
56
58
|
puts "\nProcess ID: ".green + pid.to_s.yellow + "\nUse ".green + "$ kill ".yellow + pid.to_s.yellow + " to kill the zombie process.".green
|
@@ -123,6 +125,51 @@ module Echo_cli
|
|
123
125
|
helper.unset_envs()
|
124
126
|
end
|
125
127
|
|
128
|
+
desc "populate", "Back-populate a metric. Use \"echo_cli populate '<metric>' {timespan} {frequency}\""
|
129
|
+
|
130
|
+
long_desc <<-LONGDESC
|
131
|
+
Back-populate a metric for a specified amount of time. Use \"echo_cli populate '<metric>' {timespan} {frequency}\"
|
132
|
+
|
133
|
+
`echo_cli populate` will populate a metric's timeseries data with random values between 1-100.
|
134
|
+
|
135
|
+
The default {timespan} that will be populated spans from now to 1209600 seconds (2 weeks) prior to now.
|
136
|
+
|
137
|
+
The default {frequency} at which data will be populated is 600 seconds (10 minutes).
|
138
|
+
|
139
|
+
The metric-value number (following the ':' in the <metric> string parameter) can be random. The populate command does not require this information, it is merely left in place for consistency across commands and ease-of-use.
|
140
|
+
|
141
|
+
Ensure single-quotes surround the metric.
|
142
|
+
|
143
|
+
Ensure the environment variable 'ECHO_CLI_HOST' is set to the correct IP.
|
144
|
+
|
145
|
+
> $ echo_cli populate 'example.back.populate:1|c' {600} {100}
|
146
|
+
LONGDESC
|
147
|
+
|
148
|
+
def populate(metric, timespan = 600, frequency = 600)
|
149
|
+
helper = Helper.new
|
150
|
+
helper.set_envs
|
151
|
+
metric = metric.gsub(/'/,"").gsub(/"/,"")
|
152
|
+
exit if !helper.check_metric_format(metric)
|
153
|
+
|
154
|
+
now = Time.new.to_i
|
155
|
+
prng = Random.new
|
156
|
+
|
157
|
+
puts "\nWARNING: You are about to back-populate a metric.\nAre you sure you want to back-populate ".red + metric.yellow + " for the last ".red + timespan.to_s.yellow + " seconds?".red
|
158
|
+
input = ask "[y/n]".red
|
159
|
+
|
160
|
+
if input == "y"
|
161
|
+
puts "\nPopulating..."
|
162
|
+
while timespan >= 0
|
163
|
+
to_post = helper.get_metric_string_populate(metric) + " " + prng.rand(0...100).to_s + " " + (now - timespan).to_s
|
164
|
+
helper.do_post_tcp(ENV["ECHO_CLI_HOST"], "2003", to_post)
|
165
|
+
timespan = timespan - frequency
|
166
|
+
end
|
167
|
+
puts "Complete."
|
168
|
+
else
|
169
|
+
exit
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
126
173
|
desc "convert", "Convert timestamp formats. Use \"echo_cli convert <timestamp>\""
|
127
174
|
|
128
175
|
long_desc <<-LONGDESC
|
@@ -220,6 +267,20 @@ module Echo_cli
|
|
220
267
|
end
|
221
268
|
end
|
222
269
|
|
270
|
+
def get_metric_string_populate(metric)
|
271
|
+
type = metric[metric.index('|') + 1 .. metric.length]
|
272
|
+
case type
|
273
|
+
when 'c'
|
274
|
+
return "stats.counters." + metric[0..metric.index(':')-1] + ".count"
|
275
|
+
when 'ms'
|
276
|
+
return "stats.timers." + metric[0..metric.index(':')-1] + ".count"
|
277
|
+
when 's'
|
278
|
+
return "stats.sets." + metric[0..metric.index(':')-1] + ".count"
|
279
|
+
when 'g'
|
280
|
+
return "stats.gauges." + metric[0..metric.index(':')-1]
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
223
284
|
def check_metric_format(metric)
|
224
285
|
if /.*(:\d*\.?\d*)\|(ms|c|g|s)/.match(metric).to_s != metric
|
225
286
|
puts "\nThe posted metric was not of the correct form.\nMetrics must be of the form ".red + "<Application_name>.<tag1>.<tag2>...<tag(n)>:<value>|<metric_type>".yellow
|
@@ -233,11 +294,13 @@ module Echo_cli
|
|
233
294
|
begin
|
234
295
|
timeout(10) do
|
235
296
|
socket = TCPSocket.new(statsd_uri, port)
|
236
|
-
socket.
|
297
|
+
socket.write(request_body + "\n")
|
298
|
+
socket.close
|
237
299
|
end
|
238
300
|
rescue Timeout::Error
|
239
301
|
puts "\nOperation timed out! Ensure the 'ECHO_CLI_HOST' environment variable is correct.".red
|
240
302
|
exit
|
303
|
+
rescue Errno::ECONNREFUSED
|
241
304
|
end
|
242
305
|
end
|
243
306
|
|
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.32
|
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-06-
|
11
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: highline
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.7.8
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.7.8
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|