mtr_monitor 0.4.0 → 0.5.0

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: b7c84d43ef8922804d7c968ef44e7e07ef2932d8
4
- data.tar.gz: 42686ab91ceacd16256c2a2e4df95e28bfb8508a
3
+ metadata.gz: 5f4fc19a4c802efd3bc96fca5ca2f737c0147eb0
4
+ data.tar.gz: df11b7d5705fdc2a086702889bec29cf3bcc4c77
5
5
  SHA512:
6
- metadata.gz: 635b63e1f77e8827b94a2036de0b52ad88474c9be644979af57f693f4ef0be2ad4ac36767212f048552910a08da48fa134ae16ffaf8b0549789296e4498aadcd
7
- data.tar.gz: 5c086be79a78aba1059b01221242a39c43f4afff795ca03f75ab8aedb77604092068dfe5b8f125bd9caa54d13375430eb49a882c1026f98bf80465e674c4b5d0
6
+ metadata.gz: ddb342e7429f1018777e1e98e1e198f31df57e084709f5229686da3937c94a28fb81a93766907c6a9485a7a2f25be2196a24cec23f7dc3462508b9248c64518f
7
+ data.tar.gz: 980bb3e934e45d20f729f47710f770e0f5ee8dacf4b14f7a5775ffb047257cf24f6f2874cec3874fc6a27b32371812ffe2b9250bef0639a3dee39477f86c2fc4
@@ -0,0 +1,10 @@
1
+ FROM ubuntu:14.04
2
+
3
+ RUN apt-get update && apt-get install -y mtr ruby python-pip
4
+
5
+ RUN pip install awscli --upgrade --user
6
+ RUN echo "export PATH=~/.local/bin:\$PATH" >> ~/.bashrc
7
+
8
+ RUN gem install mtr_monitor
9
+
10
+ CMD ["bash", "-c", "mtr_report"]
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mtr_monitor (0.4.0)
4
+ mtr_monitor (0.5.0)
5
5
  rt-watchman (~> 0.10.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,34 +1,26 @@
1
1
  # MtrMonitor
2
2
 
3
- Generates a MTR report, uploads the report to S3, and finally parses the report
4
- and collects statsd metrics.
3
+ [![Build Status](https://semaphoreci.com/api/v1/renderedtext/mtr-monitor/branches/master/badge.svg)](https://semaphoreci.com/renderedtext/mtr-monitor)
5
4
 
6
- ## Installation
7
5
 
8
- Add this line to your application's Gemfile:
9
-
10
- ```ruby
11
- gem 'mtr_monitor'
12
- ```
6
+ Generates a MTR report, uploads the report to S3, and finally parses the report
7
+ and collects statsd metrics.
13
8
 
14
- Or install it on your system:
9
+ ### Run mtr_monitor as a docker container
15
10
 
16
11
  ``` bash
17
- gem install mtr_monitor
12
+ 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
18
13
  ```
19
14
 
20
- ## Usage
21
-
22
- ### Generate an MTR report from the CLI
15
+ ### Generate an MTR report from Ruby
23
16
 
24
- ``` bash
25
- export AWS_ACCESS_KEY_ID=<XXX>
26
- export AWS_SECRET_ACCESS_KEY=<YYY>
17
+ Install mtr_monitor as a gem:
27
18
 
28
- mtr_report --name "test" --domain "google.com" --bucket "bucket-aaa"
19
+ ```ruby
20
+ gem 'mtr_monitor'
29
21
  ```
30
22
 
31
- ### Generate an MTR report from Ruby
23
+ Invoke mtr generation:
32
24
 
33
25
  ``` ruby
34
26
  name = "google"
@@ -0,0 +1,5 @@
1
+ version: "2.0"
2
+
3
+ services:
4
+ app:
5
+ build: .
@@ -1,41 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "mtr_monitor"
4
- require "optparse"
5
4
 
6
- options = {}
7
-
8
- OptionParser.new do |opts|
9
-
10
- opts.on("--domain [DOMAIN]", "Domain to Test") do |domain|
11
- options[:domain] = domain
12
- end
13
-
14
- opts.on("--name [NAME]", "Name of the Report") do |name|
15
- options[:name] = name
16
- end
17
-
18
- opts.on("--bucket [BUCKET]", "Name of the S3 Bucket") do |bucket|
19
- options[:bucket] = bucket
20
- end
21
-
22
- end.parse!
23
-
24
- name = options.fetch(:name)
25
- domain = options.fetch(:domain)
26
- s3_bucket = options.fetch(:bucket)
27
-
28
- aws_access_key_id = ENV["AWS_ACCESS_KEY_ID"]
29
- aws_secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
30
-
31
- report = MtrMonitor::Report.new(name,
32
- domain,
33
- s3_bucket,
34
- aws_access_key_id,
35
- aws_secret_access_key)
36
-
37
- puts "Generating report"
38
- report.generate
39
-
40
- puts "Submiting metrics"
41
- report.submit_metrics
5
+ name = ENV.fetch("NAME")
6
+ domain = ENV.fetch("DOMAIN")
7
+ s3_bucket = ENV.fetch("S3_BUCKET")
8
+ aws_access_key_id = ENV.fetch("AWS_ACCESS_KEY_ID")
9
+ aws_secret_access_key = ENV.fetch("AWS_SECRET_ACCESS_KEY")
10
+ mtr_options = ENV.fetch("MTR_OPTIONS", "")
11
+ sleep_time = ENV.fetch("SLEEP_TIME", "5").to_i
12
+
13
+ loop do
14
+ report = MtrMonitor::Report.new(name,
15
+ domain,
16
+ s3_bucket,
17
+ mtr_options,
18
+ aws_access_key_id,
19
+ aws_secret_access_key)
20
+
21
+ puts "Generating report"
22
+ report.generate
23
+
24
+ puts "Submiting metrics"
25
+ report.submit_metrics
26
+
27
+ puts "Sleeping for #{sleep_time} minutes"
28
+ sleep(sleep_time * 60)
29
+ end
@@ -8,12 +8,13 @@ module MtrMonitor
8
8
  #
9
9
  class Report
10
10
 
11
- def initialize(name, domain, s3_bucket, aws_access_key_id, aws_secret_access_key)
11
+ def initialize(name, domain, s3_bucket, mtr_options, aws_access_key_id, aws_secret_access_key)
12
12
  @name = name
13
13
  @domain = domain
14
14
  @s3_bucket = s3_bucket
15
15
  @aws_access_key_id = aws_access_key_id
16
16
  @aws_secret_access_key = aws_secret_access_key
17
+ @mtr_options = mtr_options
17
18
 
18
19
  @log_name = "#{@name}/#{Time.now.strftime("%Y-%m-%d")}/#{host_ip_address}/#{Time.now.strftime("%H-%M")}.log"
19
20
  @log_path = "/var/log/mtr/#{@log_name.gsub("/", "-")}"
@@ -24,9 +25,9 @@ module MtrMonitor
24
25
  puts "Local Path : #{@log_path}"
25
26
  puts "S3 Path : #{@s3_path}"
26
27
 
27
- `sudo mkdir -p /var/log/mtr`
28
- `sudo sh -c 'mtr --report #{@domain} > #{@log_path}'`
29
- `AWS_ACCESS_KEY_ID='#{@aws_access_key_id}' AWS_SECRET_ACCESS_KEY='#{@aws_secret_access_key}' aws s3 cp #{@log_path} #{@s3_path}`
28
+ run "sudo mkdir -p /var/log/mtr"
29
+ run "sudo sh -c 'mtr --report #{@mtr_options} #{@domain} > #{@log_path}'"
30
+ run "AWS_ACCESS_KEY_ID='#{@aws_access_key_id}' AWS_SECRET_ACCESS_KEY='#{@aws_secret_access_key}' aws s3 cp #{@log_path} #{@s3_path}"
30
31
  end
31
32
 
32
33
  def submit_metrics
@@ -51,6 +52,14 @@ module MtrMonitor
51
52
  def host_ip_address
52
53
  `/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1`.strip.gsub(".", "-")
53
54
  end
55
+
56
+ def log_path
57
+ @log_path
58
+ end
59
+
60
+ def run(cmd)
61
+ `#{cmd}`
62
+ end
54
63
  end
55
64
 
56
65
  class Hop
@@ -1,3 +1,3 @@
1
1
  module MtrMonitor
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
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.4.0
4
+ version: 0.5.0
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: 2017-12-20 00:00:00.000000000 Z
11
+ date: 2017-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rt-watchman
@@ -77,6 +77,7 @@ files:
77
77
  - ".gitignore"
78
78
  - ".rspec"
79
79
  - CODE_OF_CONDUCT.md
80
+ - Dockerfile
80
81
  - Gemfile
81
82
  - Gemfile.lock
82
83
  - LICENSE.txt
@@ -84,6 +85,7 @@ files:
84
85
  - Rakefile
85
86
  - bin/console
86
87
  - bin/setup
88
+ - docker-compose.yml
87
89
  - exe/mtr_report
88
90
  - lib/mtr_monitor.rb
89
91
  - lib/mtr_monitor/version.rb
@@ -108,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
110
  version: '0'
109
111
  requirements: []
110
112
  rubyforge_project:
111
- rubygems_version: 2.5.2.1
113
+ rubygems_version: 2.6.14
112
114
  signing_key:
113
115
  specification_version: 4
114
116
  summary: Generate, parse, and collect MTR reports