echo_cli 0.6.2 → 0.6.3

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: f40be413ffd45a59cdb6ab5da86ae6667617f128
4
- data.tar.gz: 078150dff54063387c76aca88649d67026264239
3
+ metadata.gz: 0448a4ae9927eeb77e8b2043f5ff4bdceddcd39c
4
+ data.tar.gz: 0f9b13961677f98786fb2152e51b3cad864b91ab
5
5
  SHA512:
6
- metadata.gz: d5be7474e7224e833b85c554305ca6ba1c6b561ddbaadba42df28c9e578597818edd26b6a2b42736865c4cb2e085a52495623b558a75650fab1bb9aa148fa865
7
- data.tar.gz: fef649166a32f16685218da4cd6fa03780b5203be9371eb6ef422e2288425a526fc9e6f0faf4ba6255213b45a03aba62cea7fd9b3a69bfbe9591edbfb9c567dc
6
+ metadata.gz: 3acbc693f08696a9970fac9a604b037bccbaaaad7633fb650e8e57f619699bd2bd3979a82cd07b09f447f9398471c5d1fcc1546c2eeb29eb77ba12f79d079ac5
7
+ data.tar.gz: b78fcdaad8e3dded18685d09c12a2d08cf8d1ce10d6a185b6d9329493508bf6bf50907d3df67fec960255a47e7df5f7acba102dc62dc90d34e23bf5433340be9
data/README.md CHANGED
@@ -30,6 +30,19 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
30
30
 
31
31
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
32
 
33
+ ```bash
34
+ git add .
35
+ git commit -m
36
+ git push
37
+
38
+ gem bump minor/major
39
+ rake build
40
+ rake install
41
+ rake release
42
+
43
+ gem install echo_cli
44
+ ```
45
+
33
46
  ## Contributing
34
47
 
35
48
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/echo_cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -38,4 +51,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
38
51
  ## License
39
52
 
40
53
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
-
data/lib/echo_cli/cli.rb CHANGED
@@ -7,6 +7,8 @@ module Echo_cli
7
7
  class Echo < Thor
8
8
  desc "post", "Post metrics to Echo. Use \"echo_cli post <IP> '<metric>' <{number}>\""
9
9
 
10
+ option :q
11
+
10
12
  long_desc <<-LONGDESC
11
13
  `echo_cli post` will post a metric directly to Echo's StatsD server.
12
14
 
@@ -14,11 +16,13 @@ module Echo_cli
14
16
 
15
17
  Ensure single-quotes surround the metric.
16
18
 
17
- > $ echo_cli post localhost 'example.post:1|c' {10}
19
+ With -q (query-verify) option, post will perform a query of previously posted metric in Echo's instance of OpenTSDB, and provide a message verifying the datapoint exists.
20
+
21
+ > $ echo_cli post localhost 'example.post:1|c' {10} {-q}
18
22
  LONGDESC
19
23
 
20
- def post(ip, body, num = 0)
21
- request_body = body.gsub(/'/,"")
24
+ def post(ip, metric, num = 0)
25
+ request_body = metric.gsub(/'/,"")
22
26
  statsd_uri = "http://" + ip + ":8125/metrix"
23
27
 
24
28
  ENV["http_proxy"] = ENV["HTTP_PROXY"]
@@ -34,6 +38,7 @@ module Echo_cli
34
38
  if(num.to_i > 0)
35
39
  begin
36
40
  time_start = Time.new.to_i.to_s
41
+
37
42
  for i in 1..num.to_i
38
43
  res = https.request(req)
39
44
  if res.code != '200'
@@ -41,6 +46,10 @@ module Echo_cli
41
46
  raise
42
47
  end
43
48
  end
49
+
50
+ if options[:q]
51
+ sleep 10 # ensure data reception and replication
52
+ end
44
53
  time_end = Time.new.to_i.to_s
45
54
 
46
55
  puts "\n\tSuccessfully posted ".green + request_body.yellow + " to ".green + ip.blue + " " + num.green + " time(s)".green + "\n\tTime start: ".green + time_start.yellow + ", Time end: ".green + time_end.yellow
@@ -51,8 +60,15 @@ module Echo_cli
51
60
  else
52
61
  begin
53
62
  time_start = Time.new.to_i.to_s
63
+
54
64
  res = https.request(req)
65
+
66
+ if options[:q]
67
+ sleep 10 # ensure data reception and replication
68
+ end
69
+
55
70
  time_end = Time.new.to_i.to_s
71
+
56
72
  if res.code == '200'
57
73
  puts "\n\tSuccessfully posted ".green + request_body.yellow + " to ".green + ip.blue + "\n\tTime start: ".green + time_start.yellow + ", Time end: ".green + time_end.yellow
58
74
  end
@@ -61,6 +77,108 @@ module Echo_cli
61
77
  end
62
78
  end
63
79
 
80
+ if options[:q]
81
+ query(ip, request_body[0..request_body.index(":")-1], time_start, time_end)
82
+ end
83
+
84
+ ENV["http_proxy"] = ""
85
+ ENV["https_proxy"] = ""
86
+ end
87
+
88
+ desc "query", "Query metrics on Echo. Use \"echo_cli query <IP> '<metric>' <time_start> <time_end> {-v}\""
89
+
90
+ option :v
91
+
92
+ long_desc <<-LONGDESC
93
+ `echo_cli query` will query a metric directly from Echo's OpenTSDB server instance.
94
+
95
+ If timestamps are unknown, echo_cli's post command provides time_start and time_end values for future querying.
96
+
97
+ Ensure single-quotes surround the metric.
98
+
99
+ Unlike the echo_cli post command, query does not require the data value nor the data type (e.g. remove ':1|c' from 'example.post:1|c' and your query will still work).
100
+
101
+ With -v (verbose) option, query will print the status code and response body upon completion of the request.
102
+
103
+ > $ echo_cli query localhost 'example.post' 1492186212 1492186214 {-v}
104
+ LONGDESC
105
+
106
+ def query(ip, metric, time_start, time_end)
107
+ metric = metric.gsub(/'/,"")
108
+ if metric.include? ":"
109
+ metric = metric[0..metric.index(":")-1]
110
+ end
111
+
112
+ opentsdb_uri = "http://" + ip + ":4242/api/query"
113
+
114
+ tags=""
115
+
116
+ if metric.include? "."
117
+ tags = metric[metric.index(".")+1..-1] + "."
118
+ metric = metric[0..metric.index(".")-1]
119
+
120
+ toReturn = ""
121
+ count = 1
122
+ while tags.include?(".") do
123
+ toReturn = toReturn + "\"tag" + count.to_s + "\": \"" + tags[0..tags.index(".")-1] + "\""
124
+ count = count + 1
125
+ tags = tags[tags.index(".")+1..-1]
126
+ if tags.include?(".")
127
+ toReturn = toReturn + ",\n"
128
+ end
129
+ end
130
+
131
+ tags = toReturn
132
+ end
133
+
134
+ opentsdb_query =
135
+ "{
136
+ \"start\": " + time_start + ",
137
+ \"end\": " + time_end + ",
138
+ \"queries\": [
139
+ {
140
+ \"aggregator\": \"sum\",
141
+ \"metric\": \"" + metric + "\",
142
+ \"tags\": {" + tags +
143
+ "}
144
+ }
145
+ ]
146
+ }"
147
+
148
+ ENV["http_proxy"] = ENV["HTTP_PROXY"]
149
+ ENV["https_proxy"] = ENV["HTTPS_PROXY"]
150
+
151
+ uri = URI.parse(opentsdb_uri)
152
+ https = Net::HTTP.new(uri.host, uri.port)
153
+ https.use_ssl = false
154
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE if https.use_ssl?
155
+ req = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' => 'text/plain'}, )
156
+ req.body = opentsdb_query
157
+
158
+ if options[:v]
159
+ begin
160
+ res = https.request(req)
161
+ if res.code == '200'
162
+ puts "\n\tSuccessfully retrieved ".green + metric.yellow + " from ".green + ip.blue + " in timestamp range: ".green + time_start.yellow + " to ".green + time_end.yellow + "\n\tStatus Code: ".green + res.code.yellow + "\n\tResponse Body: ".green + res.body.green
163
+ else
164
+ puts "\n\tFailed to retrieve ".red + metric.yellow + " from ".red + ip.blue + " in timestamp range: ".red + time_start.yellow + " to ".red + time_end.yellow + "\n\tStatus Code: ".red + res.code.yellow + "\n\tResponse Body: ".red + res.body.red
165
+ end
166
+ rescue
167
+ puts "\n\tYour request returned an error. Are you sure your query was correct?"
168
+ end
169
+ else
170
+ begin
171
+ res = https.request(req)
172
+ if res.code == '200'
173
+ puts "\n\tSuccessfully retrieved ".green + metric.yellow + " from ".green + ip.blue + " in timestamp range: ".green + time_start.yellow + " to ".green + time_end.yellow
174
+ else
175
+ puts "\n\tFailed to retrieve ".red + metric.yellow + " from ".red + ip.blue + " in timestamp range: ".red + time_start.yellow + " to ".red + time_end.yellow
176
+ end
177
+ rescue
178
+ puts "\n\tYour request returned an error. Are you sure your query was correct?"
179
+ end
180
+ end
181
+
64
182
  ENV["http_proxy"] = ""
65
183
  ENV["https_proxy"] = ""
66
184
  end
@@ -1,3 +1,3 @@
1
1
  module Echo_cli
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: echo_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Raphael
@@ -100,7 +100,6 @@ files:
100
100
  - bin/console
101
101
  - bin/echo_cli
102
102
  - bin/setup
103
- - echo_cli-0.6.0.gem
104
103
  - echo_cli.gemspec
105
104
  - exe/console
106
105
  - exe/echo_cli
data/echo_cli-0.6.0.gem DELETED
Binary file