echo_cli 0.6.20 → 0.6.21

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: cd5f609e5d770299aa3c77843c4f22d1a8ce5243
4
- data.tar.gz: 0128cf4cddd4dc07ecb9a6e1cad5f89c1df46c9e
3
+ metadata.gz: 455a70f05530bd541185638a1c07ed7005bba915
4
+ data.tar.gz: d298d2bd257fd85935a71c0e9a123a1efde0c34f
5
5
  SHA512:
6
- metadata.gz: 1056a5fa9b7197db6a646d37892f8f2086fac67b49124d33c5c0a6ec20dbb2aaf9cf040178f5d51617a622e1f0a977278dfce2e2f84e8f9c908582650f840a89
7
- data.tar.gz: c0016a5bef2ee41db51406ea3a12cbf70fcbc0f5de5435ccd0642ecab0f42b875614a69af093d5cd080a19ab4ecb4f6d740b36d8296547b2d2ba095e1582c3d6
6
+ metadata.gz: aee1848d8b950130cbd33ecc95bf2d9a4134551f481b50cef43105003d6906fe63c05be04b18559826c5dfcc30a84aad51b48410d7f3c46942c6ff76351be519
7
+ data.tar.gz: fd88e47ba8f795825c6cd69854d1fdf54b0fc4531500b02e4e1b3004098583ea52c040bae12f621a560e4c3526e578f7979efdaaff4d042fbc43b166b4989bcf
data/README.md CHANGED
@@ -2,7 +2,29 @@
2
2
 
3
3
  ## Installation
4
4
 
5
- Ensure git and rbenv (or rvm) are installed on your machine:
5
+ Ensure git and rbenv (or rvm, NOT both) are installed on your machine:
6
+
7
+ Verify the 'rbenv' and 'git' commands are found
8
+ ```bash
9
+ $ git
10
+ ```
11
+
12
+ ```bash
13
+ $ rbenv
14
+ ```
15
+
16
+ If you are missing git:
17
+
18
+ Install git:
19
+
20
+ ```bash
21
+ $ brew update
22
+ $ brew install git
23
+ ```
24
+
25
+ See more about git here: https://www.atlassian.com/git/tutorials/install-git
26
+
27
+ If you are missing rbenv:
6
28
 
7
29
  Install rbenv:
8
30
 
@@ -17,7 +39,7 @@ See more about rbenv here: https://github.com/rbenv/rbenv
17
39
  Install 'echo_cli':
18
40
 
19
41
  ```bash
20
- $ gem install echo_cli
42
+ $ sudo gem install echo_cli
21
43
  ```
22
44
 
23
45
  Test the installation to ensure it is working properly (no errors should occur if the installation was successful):
@@ -26,6 +48,30 @@ Test the installation to ensure it is working properly (no errors should occur i
26
48
  $ echo_cli
27
49
  ```
28
50
 
51
+ ## Metrics Explained
52
+
53
+ ### Posting data to Echo
54
+ The Echo server receives data in text format with the following syntax:
55
+
56
+ ```
57
+ <Application_name>.<tag1>.<tag2>…<tag(n)>:<value>|<metric type>
58
+ ```
59
+
60
+ ### Application name
61
+ This is the name of the application that you are sending the data from. It is what you are measuring. It must be a text string.
62
+
63
+ ### Tag1 – tag(n)
64
+ The database works off of tags to identify metrics. What ever tags you use will be what identifies your measurement in the database and in the front end. We recommend that you use two to three tags for each measurement type.
65
+
66
+ ### Value
67
+ This is a numeric value that is representative of the metric being tracked. It must be a number in text format.
68
+
69
+ ### Metric type
70
+ A special flag that tells the Echo server what type of data you are recording. The server will perform different calculations depending on this value. There are three types of flags that are currently supported by Echo:
71
+ * **c**: (Count) – Tells the Echo server that the values represent a count.
72
+ * **ms**: (Time Duration) – Tells the server that values represent a duration of time. The number is recorded in milliseconds and is to be transmitted as a number, not a time stamp. Note: in practice, ms does not have to represent time. It can represent any number. The system does not care, it only records.
73
+ * **g**: (Gauge) – Represents a Gauge function. When a number is received, the server will continue to record that number every 10 seconds until a new number is received. Note: The gauge auto repost function has been turned off in the sandbox environment. This is to reduce the amount of noise in the data as people test and configure different measurements.
74
+
29
75
  ## Usage
30
76
 
31
77
  View available echo_cli commands and their short descriptions:
@@ -48,7 +94,7 @@ $ echo_cli convert <timestamp>
48
94
  ```
49
95
  Parameters:
50
96
 
51
- `<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).
97
+ `<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 (decimals may follow the SS value).
52
98
 
53
99
  Example:
54
100
  ```bash
@@ -56,18 +102,26 @@ $ echo_cli convert 1492186214
56
102
  ```
57
103
  The previous example will convert the provided epoch timestamp into a human-readable format.
58
104
 
105
+ Example:
106
+ ```bash
107
+ $ echo_cli convert 2017-05-11T15:05:23-07:00
108
+ ```
109
+ This example will convert from a human-readable timestamp to an epoch timestamp.
110
+
59
111
  #### cpost
60
112
  ```bash
61
- $ echo_cli cpost <URL> '<metric>' {frequency} {-z}
113
+ $ echo_cli cpost <URL> '<metric>' {frequency} {-v} {-z}
62
114
  ```
63
115
  Parameters:
64
116
 
65
117
  `<URL>`: (required) specifies the StatsD endpoint you are attempting to post a metric to
66
118
 
67
- `'<metric>'`: (required) the metric name, as well as any tags, and data value and data type to be posted to StatsD
119
+ `'<metric>'`: (required) the application name, as well as any tags, and data value and data type to be posted to StatsD
68
120
 
69
121
  `{frequency}`: (optional) the rate at which the metric will be continuously posted to Echo's server. If left unspecified, this value will default to 10 seconds.
70
122
 
123
+ `{-v}`: (optional) continuously output a 'successfully posted' message, with updated start and end times, to the command line.
124
+
71
125
  `{-z}`: (optional) spawn the continuous post process in the background. Additionally, this option will return a PID (Process ID) that can be used in the future to kill the command. Use `kill -9 <PID>` to kill the process.
72
126
 
73
127
  Example:
@@ -95,18 +149,18 @@ Parameters:
95
149
 
96
150
  `<URL>`: (required) specifies the StatsD endpoint you are attempting to post a metric to
97
151
 
98
- `'<metric>'`: (required) the metric name, as well as any tags, and data value and data type to be posted to StatsD
152
+ `'<metric>'`: (required) the application name, as well as any tags, and data value and data type to be posted to StatsD
99
153
 
100
154
  `{number}`: (optional) the number of posts to occur, e.g. a number value of '10' would post the metric 10 times to the StatsD server
101
155
 
102
156
 
103
- `{-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
157
+ `{-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 to occur
104
158
 
105
159
  Example:
106
160
  ```bash
107
161
  $ echo_cli https://localhost:8125/metrix 'sample.post.here:1|c' 10 -q
108
162
  ```
109
- 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 'https://localhost:8125/metrix', 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.
163
+ 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 located at 'https://localhost:8125/metrix', and it would be posted 10 times. Additionally, because of the '-q' specified option, OpenTSDB will be queried immediately after the post to StatsD, to verify it has been received by Echo's instance of OpenTSDB.
110
164
 
111
165
  #### query
112
166
  ```bash
@@ -116,7 +170,7 @@ Parameters:
116
170
 
117
171
  `<URL>`: (required) specifies the OpenTSDB endpoint you are attempting to query
118
172
 
119
- `'<metric>'`: (required) the metric name, including any tags, with which the query for OpenTSDB will be constructed
173
+ `'<metric>'`: (required) the application name, including any tags, with which the query for OpenTSDB will be constructed
120
174
 
121
175
  `<time_start>`: (required) the start of the range you are attempting to query in seconds from January 1, 1970 (epoch time)
122
176
 
@@ -132,7 +186,7 @@ Example:
132
186
  ```bash
133
187
  $ echo_cli https://localhost:4242/api/query 'sample.query.here' 1492464745 1492465045 -v
134
188
  ```
135
- 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.
189
+ The previous example will query OpenTSDB with the application 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.
136
190
 
137
191
  #### quick_query
138
192
  ```bash
@@ -142,7 +196,7 @@ Parameters:
142
196
 
143
197
  `<URL>`: (required) specifies the OpenTSDB endpoint you are attempting to query
144
198
 
145
- `'<metric>'`: (required) the metric name, including any tags, with which the query for OpenTSDB will be constructed
199
+ `'<metric>'`: (required) the application name, including any tags, with which the query for OpenTSDB will be constructed
146
200
 
147
201
  `<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
148
202
 
@@ -154,7 +208,7 @@ Example:
154
208
  ```bash
155
209
  $ echo_cli https://localhost:4242/api/query 'sample.query.here' 300 -s
156
210
  ```
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.
211
+ The previous example will query OpenTSDB located on 'https://localhost:4242/api/query' with the application 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.
158
212
 
159
213
  ## Development
160
214
 
data/lib/echo_cli/cli.rb CHANGED
@@ -86,7 +86,6 @@ module Echo_cli
86
86
  if response.code == '200'
87
87
  puts "\nSuccessfully posted ".green + request.body.yellow + " to ".green + statsd_uri.blue + "\nTime start: ".green + time_start.yellow + ", Time end: ".green + time_end.yellow
88
88
 
89
-
90
89
  if options[:q]
91
90
  opentsdb_uri = statsd_uri[0..statsd_uri.index(':8125')-1] + ":4242/api/query"
92
91
  query(opentsdb_uri, request.body[0..request.body.index(":")-1], time_start, time_end)
@@ -101,9 +100,10 @@ module Echo_cli
101
100
  Helper.new.unset_envs()
102
101
  end
103
102
 
104
- desc "cpost", "Continuously post metrics to Echo. Use \"echo_cli cpost <URL> '<metric>' {frequency} {-z}\""
103
+ desc "cpost", "Continuously post metrics to Echo. Use \"echo_cli cpost <URL> '<metric>' {frequency} {-v} {-z}\""
105
104
 
106
105
  option :z
106
+ option :v
107
107
 
108
108
  long_desc <<-LONGDESC
109
109
  `echo_cli cpost` will continuously post a metric directly to Echo's StatsD server. This process can be killed with "CTRL-c".
@@ -112,9 +112,11 @@ module Echo_cli
112
112
 
113
113
  Ensure single-quotes surround the metric.
114
114
 
115
- With -z (zombie) option, cpost will continuously send posts to Echo in the background, and return its PID for future removal. Use "$ kill -9 <PID>" to kill the zombie process.
115
+ With -v (verbose) option, cpost will continuously output a 'successfully posted' message, with updated times, to the command line.
116
116
 
117
- > $ echo_cli cpost https://localhost:8125/metrix 'example.post:1|c' {1} {-z}
117
+ With -z (zombie) option, cpost will continuously send posts to Echo in the background, and return its PID for future removal. Use "$ kill -9 <PID>" to kill the zombie process. Specifying this option will override the '-v' option.
118
+
119
+ > $ echo_cli cpost https://localhost:8125/metrix 'example.post:1|c' {1} {-v} {-z}
118
120
  LONGDESC
119
121
 
120
122
  def cpost(statsd_uri, metric, num = 0)
@@ -146,14 +148,23 @@ module Echo_cli
146
148
  sleep s
147
149
  end
148
150
  end
149
- puts "Process ID: " + pid.to_s
151
+ puts "\nProcess ID: ".green + pid.to_s.yellow + "\nUse ".green + "kill -9 ".yellow + pid.to_s.yellow + " to kill the zombie process.".green
150
152
  else
151
153
  puts "\nPosting: ".green + metric.yellow + " once every ".green + s.to_s.yellow + " seconds".green + " to ".green + statsd_uri.yellow + "\nPress Ctrl-c to kill the process.\n".green
152
154
  while true do
153
- Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
155
+ time_start = Time.new.to_i.to_s
156
+
157
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
154
158
  http.request(request)
155
159
  end
160
+
156
161
  sleep s
162
+
163
+ time_end = Time.new.to_i.to_s
164
+
165
+ if(options[:v] && response.code == '200')
166
+ puts "\nSuccessfully posted ".green + request.body.yellow + " to ".green + statsd_uri.blue + "\nTime start: ".green + time_start.yellow + ", Time end: ".green + time_end.yellow + "\nPress Ctrl-c to kill the process.\n".green
167
+ end
157
168
  end
158
169
  end
159
170
 
@@ -203,7 +214,7 @@ module Echo_cli
203
214
  req.body = opentsdb_query
204
215
 
205
216
  if options[:v]
206
- # begin
217
+ begin
207
218
  res = https.request(req)
208
219
  if res.code == '200'
209
220
 
@@ -233,9 +244,9 @@ module Echo_cli
233
244
  else
234
245
  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
235
246
  end
236
- # rescue
237
- # puts "\nYour request returned an error. Are you sure your query was correct?"
238
- # end
247
+ rescue
248
+ puts "\nYour request returned an error. Are you sure your query was correct?"
249
+ end
239
250
  else
240
251
  begin
241
252
  res = https.request(req)
@@ -1,3 +1,3 @@
1
1
  module Echo_cli
2
- VERSION = "0.6.20"
2
+ VERSION = "0.6.21"
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.20
4
+ version: 0.6.21
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-11 00:00:00.000000000 Z
11
+ date: 2017-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor