mtr_monitor 0.13.2 → 0.13.3

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: b53b90dc83a1ef94404e83554ab2f3e7a9cf6452
4
- data.tar.gz: 617c0477ee74365fc37ca38ec81dbdc596363af7
3
+ metadata.gz: 011e48e8082ba84320bb8cd5fd46accdd903b0a4
4
+ data.tar.gz: 258ff5f5ca66c2394d968430f9b0538541b3521f
5
5
  SHA512:
6
- metadata.gz: e12d0e58f8843b0a3ebaf80d94dbb03544b0442a76d1c295a805b311fa3e28dfb0970ae58152e619fc3ae886a50c5ddc96a83f667f6dc413ba5a5a86f40d8fd6
7
- data.tar.gz: 00f9dfbdb1ba60f162f3d294b18bad0031703e3051ae7a13f411ffa13b344ea7d7f68eacad27fa476c41da30802babc8d265e9f59d99c6049c153fe6372033dd
6
+ metadata.gz: 5321c6d62702880ba38db94ee1cac1df6394417807062334cbc7d14fe157ebaf4a3260993c2f720b12df9b5c488b64763b12c009e27383e1340ddd176500b172
7
+ data.tar.gz: a6dc9538ddf761c7ea47427aca2034227ef7d883984113571a6e018c7dd7b06548d3d9f572c983fdb39af3c7d2472f5bea3890a5a0cc645d8f19b9c48e817946
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mtr_monitor (0.13.2)
4
+ mtr_monitor (0.13.3)
5
5
  rt-watchman (~> 0.10.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -36,6 +36,63 @@ Dashboards for the MTR monitor can be found on the
36
36
  [Platform — Network](https://semaphore.grafana.net/dashboard/db/platform-network?refresh=10s&orgId=1)
37
37
  dashboard on Grafana.
38
38
 
39
+ The US based MTR monitors have the following DNS addresses:
40
+
41
+ - `mtr-monitor.us-east-1.semaphoreci.com`
42
+ - `mtr-monitor.us-west-1.semaphoreci.com`
43
+ - `mtr-monitor.us-west-2.semaphoreci.com`
44
+
45
+ To SSH into the, run `ssh ubuntu@<address>`
46
+
47
+ ## Location of the generated MTR reports
48
+
49
+ The MTR monitor generate and stores MTR reports both on the local machine, and
50
+ uploads them to S3.
51
+
52
+ Local reports on the machine are located in the `/var/log/mtr` directory, and
53
+ the following structure:
54
+
55
+ ``` txt
56
+ /var/log/mtr/<name>-<YYYY-DD-MM>-<host-ip-address>-<HH-MM>.log
57
+ ```
58
+
59
+ For example, if you call your report `hetzner-to-us-east-1` and run it at
60
+ `2017-12-18 12:33:06`, the log will be generated in:
61
+
62
+ ``` txt
63
+ /var/log/mtr/hetzner-to-us-east-1-2017-12-18-142-21-43-11-12-33.log
64
+ ```
65
+
66
+ On S3, the path will follow the same convention, but will use a nested directory
67
+ structure:
68
+
69
+ ``` txt
70
+ s3://<bucket-name>/<name>/<YYYY-DD-MM>/<host-ip-address>/<HH-MM>.log
71
+ ```
72
+
73
+ ``` txt
74
+ s3://<bucket-name>/hetzner-to-us-east-1/2017-12-18/142-21-43-11/12-33.log
75
+ ```
76
+
77
+ ## Report Name
78
+
79
+ The name of the report is used to group reports with the same purpose on S3 and
80
+ on the local file system.
81
+
82
+ We use the following naming convention:
83
+
84
+ ``` txt
85
+ <from>-to-<destination>
86
+ ```
87
+
88
+ Examples:
89
+
90
+ ``` txt
91
+ hetzner-to-github
92
+ us-east-1-to-hetzner-sb1
93
+ hetzner-to-us-west-2
94
+ ```
95
+
39
96
  ## Using MTR Monitor as a gem
40
97
 
41
98
  The MTR monitor can be used as a gem and injected into existing Ruby
@@ -85,12 +142,67 @@ information read the code in `lib/mtr_monitor/metrics.rb`.
85
142
 
86
143
  ## Using MTR Monitor as a standalone Docker container
87
144
 
145
+ The MTR monitor can be used as a standalone Docker container. This is our
146
+ current approach for monitors that are hitting Germany from the United States.
147
+
148
+ To run a standalone MTR monitor, run the following command:
149
+
88
150
  ``` bash
89
- docker run -d -v /var/log/mtr:/var/log/mtr -e NAME=<> -e DOMAIN=<> -e MTR_OPTIONS=<> -e S3_BUCKET=<> -e AWS_ACCESS_KEY_ID=<> -e AWS_SECRET_ACCESS_KEY=<> -e SLEEP_TIME=<> renderedtext/mtr_monitor
151
+ docker run --name mtr-monitor -d -v /var/log/mtr:/var/log/mtr -e NAME=<> -e DOMAIN=<> -e MTR_OPTIONS=<> -e S3_BUCKET=<> -e AWS_ACCESS_KEY_ID=<> -e AWS_SECRET_ACCESS_KEY=<> -e SLEEP_TIME=<> renderedtext/mtr_monitor
90
152
  ```
91
153
 
92
- ### Generate an MTR report from Ruby
154
+ By default, the containers running on us-east-1, us-west-1, and us-west-2 are
155
+ automatically deployed on every merge into master in for this repository.
156
+
157
+ The new container on the machine will trigger a MTR report generation every 5
158
+ minutes. Every time a Report is generated the following is executed:
159
+
160
+ - a new MTR report is generate on your local system under the `/var/log/mtr` directory
161
+ - the report is uploaded to the provided S3 bucket
162
+ - metrics are submitted via Watchman and a pulse is generated
163
+ - the MTR cleaner is uninitiated that cleans all reports from the local system
164
+ that are older then 2 weeks
165
+
166
+ To monitor if the CRON task is running as expected, you should
167
+ set up an alert on Grafana based on the "pulse" metric.
168
+
169
+ The pulse metric has the format `network.mtr.pulse` and is tagged with the
170
+ hostname of the server where the MTR monitor is running and with the name of the
171
+ metric.
172
+
173
+ MTR hops are also submitted to Grafana. Based on these metrics you can observe
174
+ the packet loss, avg, best, and worst latency on the network. For more
175
+ information read the code in `lib/mtr_monitor/metrics.rb`.
176
+
177
+ #### Setting up a new EC2 machine for a MTR monitor
178
+
179
+ 1. Buy a new EC2 machine on AWS. Choose, a `t2-nano` instance type with Ubuntu
180
+ 14.04 operating system.
181
+
182
+ 2. SSH into the machine with the newly generated SSH keypair.
183
+
184
+ 3. Add RT developers to the authorized keys file. For a list of public keys,
185
+ refer to `s3://renderedtext-secrets/stg1-semaphore/authorized-keys`.
186
+
187
+ 4. Install docker. Run `curl https://get.docker.com | curl`.
188
+
189
+ 5. Add the `ubuntu` user to docker group. `sudo usermod -aG docker ubuntu`
190
+
191
+ 6. Re-login into the SSH session.
192
+
193
+ 7. Pull and Run the MTR monitor:
194
+
195
+ ``` bash
196
+ docker run --name mtr-monitor -d -v /var/log/mtr:/var/log/mtr -e NAME=<> -e DOMAIN=<> -e MTR_OPTIONS=<> -e S3_BUCKET=<> -e AWS_ACCESS_KEY_ID=<> -e AWS_SECRET_ACCESS_KEY=<> -e SLEEP_TIME=<> renderedtext/mtr_monitor
197
+ ```
198
+
199
+ If you want to keep this machine permanently, add it to the list of continuously
200
+ deployed servers.
201
+
202
+ #### Continuously deploying MTR monitor to a EC2 machine
93
203
 
204
+ TODO @bmarkons
94
205
 
95
- Invoke mtr generation:
206
+ #### Set up Alerts and Monitoring for a MTR monitor
96
207
 
208
+ TODO @bmarkons
data/lib/mtr_monitor.rb CHANGED
@@ -7,9 +7,19 @@ require "mtr_monitor/metrics"
7
7
  require "mtr_monitor/cleaner"
8
8
 
9
9
  module MtrMonitor
10
+
11
+ #
12
+ # MtrMonitor generates a MTR report for a domain and saves the report to:
13
+ # /var/log/mtr/<name>-<YYYY-DD-MM>-<host-ip-address>-<HH-MM>.log
14
+ #
15
+ # After that, it uploads the report to S3:
16
+ # s3://<bucket-name>/<name>/<YYYY-DD-MM>/<host-ip-address>/<HH-MM>.log
10
17
  #
11
- # Runs a mtr trace toward a domain and saves the report
12
- # to /var/log/mtr/<domain>_timestamp.log , uploads to s3 and reports metrics to statsd.
18
+ # Parameters:
19
+ #
20
+ # Name: The name of this report. Example: "hetzner-to-us-east-1"
21
+ # Domain: The domain to hit with MTR. Example: "github.com"
22
+ # MTR Options: Options to pass to the mtr command line tool.
13
23
  #
14
24
 
15
25
  REPORTS_PATH = "/var/log/mtr"
@@ -27,14 +37,15 @@ module MtrMonitor
27
37
  @aws_access_key_id = aws_access_key_id
28
38
  @aws_secret_access_key = aws_secret_access_key
29
39
  @mtr_options = mtr_options
30
- @host_ip_address = `curl http://ifconfig.co`.strip.gsub(".", "-")
40
+ @host_ip_address = `dig +short myip.opendns.com @resolver1.opendns.com`.strip.gsub(".", "-")
31
41
  @hostname = `hostname`.strip.gsub(".", "-")
32
42
  @dig_ip_address = dig_ip_address
33
43
  @logger = logger || Logger.new(STDOUT)
34
44
 
35
- @log_name = "#{@name}/#{Time.now.strftime("%Y-%m-%d")}/#{@host_ip_address}/#{Time.now.strftime("%H-%M")}.log"
36
- @log_path = "#{MtrMonitor::REPORTS_PATH}/#{@log_name.gsub("/", "-")}"
37
- @s3_path = "s3://#{@s3_bucket}/#{@log_name}"
45
+ path = "#{@name}/#{Time.now.strftime("%Y-%m-%d")}/#{@host_ip_address}/#{Time.now.strftime("%H-%M")}.log"
46
+
47
+ @log_path = "#{MtrMonitor::REPORTS_PATH}/#{path.gsub("/", "-")}"
48
+ @s3_path = "s3://#{@s3_bucket}/#{path}"
38
49
  end
39
50
 
40
51
  def generate
@@ -1,3 +1,3 @@
1
1
  module MtrMonitor
2
- VERSION = "0.13.2"
2
+ VERSION = "0.13.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtr_monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 0.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - RenderedText DevOps Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-03 00:00:00.000000000 Z
11
+ date: 2018-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rt-watchman