mtr_monitor 0.5.4 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +2 -3
- data/Gemfile.lock +1 -1
- data/Rakefile +28 -0
- data/exe/mtr_report +4 -0
- data/lib/mtr_monitor/version.rb +1 -1
- data/lib/mtr_monitor.rb +12 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91b53ce8ac5bb956e5ea9e42f90cd9a446d22be7
|
4
|
+
data.tar.gz: 53166733f7d76fe2be5ce76fca2b480c64dc7697
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf94120283fa6d17e06996c8004497e671b42f49ba389b4735cde5aa1da1e1f5d738c84e4e7b0447ede38065b0e463fa9eb4cf2f4ee135412818fb9cd5cbcfd8
|
7
|
+
data.tar.gz: cd653d78dc67a762e6cf955874a7c7bc41f3091347d03ec1f7846cf9d62f1edfba70caea9b1474fbd20460ca1479e86b480f72e0f9c51ebc58a1ded2c1408c7d
|
data/Dockerfile
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
FROM ubuntu:14.04
|
2
2
|
|
3
|
-
RUN apt-get update && apt-get install -y mtr ruby python-pip
|
3
|
+
RUN apt-get update && apt-get install -y curl mtr ruby python-pip
|
4
4
|
|
5
|
-
RUN pip install awscli
|
6
|
-
RUN echo "export PATH=~/.local/bin:\$PATH" >> ~/.bashrc
|
5
|
+
RUN pip install awscli
|
7
6
|
|
8
7
|
RUN gem install mtr_monitor
|
9
8
|
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -4,3 +4,31 @@ require "rspec/core/rake_task"
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
6
|
task :default => :spec
|
7
|
+
|
8
|
+
desc "Deploys mtr-monitor to servers"
|
9
|
+
task :deploy do
|
10
|
+
server = ENV.fetch("SERVER")
|
11
|
+
|
12
|
+
output =
|
13
|
+
`ssh -o StrictHostKeychecking=no ubuntu@#{server} <<'ENDSSH'
|
14
|
+
docker stop mtr-monitor || true
|
15
|
+
docker rm mtr-monitor || true
|
16
|
+
docker pull renderedtext/mtr-monitor
|
17
|
+
docker run -d \
|
18
|
+
--name mtr-monitor \
|
19
|
+
--hostname "#{server}" \
|
20
|
+
-v /var/log/mtr:/var/log/mtr \
|
21
|
+
-e WATCHMAN_HOST="#{ENV['WATCHMAN_HOST']}" \
|
22
|
+
-e NAME="#{ENV['NAME']}" \
|
23
|
+
-e DOMAIN="#{ENV['DOMAIN']}" \
|
24
|
+
-e MTR_OPTIONS="#{ENV['MTR_OPTIONS']}" \
|
25
|
+
-e S3_BUCKET="#{ENV['S3_BUCKET']}" \
|
26
|
+
-e AWS_ACCESS_KEY_ID="#{ENV['AWS_ACCESS_KEY_ID']}" \
|
27
|
+
-e AWS_SECRET_ACCESS_KEY="#{ENV['AWS_SECRET_ACCESS_KEY']}" \
|
28
|
+
-e SLEEP_TIME="#{ENV['SLEEP_TIME']}" \
|
29
|
+
renderedtext/mtr-monitor
|
30
|
+
ENDSSH`
|
31
|
+
|
32
|
+
puts output
|
33
|
+
exit 1 if $?.exitstatus != 0
|
34
|
+
end
|
data/exe/mtr_report
CHANGED
@@ -13,6 +13,10 @@ aws_secret_access_key = ENV.fetch("AWS_SECRET_ACCESS_KEY")
|
|
13
13
|
mtr_options = ENV.fetch("MTR_OPTIONS", "")
|
14
14
|
sleep_time = ENV.fetch("SLEEP_TIME", "5").to_i
|
15
15
|
|
16
|
+
Watchman.host = ENV.fetch("WATCHMAN_HOST")
|
17
|
+
Watchman.port = ENV.fetch("WATCHMAN_PORT", 8125).to_i
|
18
|
+
Watchman.prefix = "mtr-monitor.prod"
|
19
|
+
|
16
20
|
loop do
|
17
21
|
report = MtrMonitor::Report.new(name,
|
18
22
|
domain,
|
data/lib/mtr_monitor/version.rb
CHANGED
data/lib/mtr_monitor.rb
CHANGED
@@ -7,16 +7,19 @@ module MtrMonitor
|
|
7
7
|
# to /var/log/mtr/<domain>_timestamp.log , uploads to s3 and reports metrics to statsd.
|
8
8
|
#
|
9
9
|
class Report
|
10
|
+
attr_reader :log_path
|
10
11
|
|
11
12
|
def initialize(name, domain, s3_bucket, mtr_options, aws_access_key_id, aws_secret_access_key)
|
12
|
-
@name
|
13
|
-
@domain
|
14
|
-
@s3_bucket
|
15
|
-
@aws_access_key_id
|
13
|
+
@name = name
|
14
|
+
@domain = domain
|
15
|
+
@s3_bucket = s3_bucket
|
16
|
+
@aws_access_key_id = aws_access_key_id
|
16
17
|
@aws_secret_access_key = aws_secret_access_key
|
17
|
-
@mtr_options
|
18
|
+
@mtr_options = mtr_options
|
19
|
+
@host_ip_address = `curl http://ifconfig.co`.strip.gsub(".", "-")
|
20
|
+
@hostname = `hostname`.strip.gsub(".", "-")
|
18
21
|
|
19
|
-
@log_name = "#{@name}/#{Time.now.strftime("%Y-%m-%d")}/#{host_ip_address}/#{Time.now.strftime("%H-%M")}.log"
|
22
|
+
@log_name = "#{@name}/#{Time.now.strftime("%Y-%m-%d")}/#{@host_ip_address}/#{Time.now.strftime("%H-%M")}.log"
|
20
23
|
@log_path = "/var/log/mtr/#{@log_name.gsub("/", "-")}"
|
21
24
|
@s3_path = "s3://#{@s3_bucket}/#{@log_name}"
|
22
25
|
end
|
@@ -31,9 +34,11 @@ module MtrMonitor
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def submit_metrics
|
37
|
+
Watchman.submit("network.mtr.pulse", 1, :gauge, :tags => [@hostname, @name])
|
38
|
+
|
34
39
|
hops.each do |hop|
|
35
40
|
hop_name = hop.name.gsub(".", "-").gsub("?", "q")
|
36
|
-
tags = [
|
41
|
+
tags = [@hostname, @name, hop_name]
|
37
42
|
|
38
43
|
Watchman.submit("network.mtr.loss", hop.loss, :gauge, :tags => tags)
|
39
44
|
Watchman.submit("network.mtr.snt", hop.snt, :gauge, :tags => tags)
|
@@ -49,14 +54,6 @@ module MtrMonitor
|
|
49
54
|
`sudo cat #{@log_path}`.split("\n").map { |line| Hop.parse(line) }.compact
|
50
55
|
end
|
51
56
|
|
52
|
-
def host_ip_address
|
53
|
-
`/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1`.strip.gsub(".", "-")
|
54
|
-
end
|
55
|
-
|
56
|
-
def log_path
|
57
|
-
@log_path
|
58
|
-
end
|
59
|
-
|
60
57
|
def run(cmd)
|
61
58
|
`#{cmd}`
|
62
59
|
end
|