mtr_monitor 0.10.1 → 0.10.2

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: 5a4d934158913f0e7593bf0ac8fe9b1f573f19c2
4
- data.tar.gz: a8b86ea455e48bd1277e6c657aa0a0deffd8cc8d
3
+ metadata.gz: 606e6226743b91f553297bb2ce378204fb59b702
4
+ data.tar.gz: fb50ea80132d8e069c3a75b2ee46cd3a9e98b2d1
5
5
  SHA512:
6
- metadata.gz: 9b7b25e1fdcdc86c6f60c8191c03eae8ec973048832ddfd1f05ff617ae3fa113bba9d969a97391d76658bb5815fe9104e67a3da5e5236662609ece2f28b8805e
7
- data.tar.gz: fb242c660cc04b72c3542fa817dbee4c027636b7410f7fed9e2814025301e7b718362408fd16d20a76a9280648ff90ba0e95a370d25daf3f11c4f333ad3e4993
6
+ metadata.gz: b9437bb036a217c3fccf18098aa0da668528e30e701f9f2d1e086ad9ad9a93c621292e932f211ba985c5c3c04e92eff914bec7821f9cf48b27188330529956b7
7
+ data.tar.gz: fdc09e9ba5718bc9d5119439ea6f8aa3560c886fd872569127e9c04a0d58bfdc8a752b25fa2f887b19067e32a675870eda139ad0b0db2eaedbc6599a0a53166e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mtr_monitor (0.10.1)
4
+ mtr_monitor (0.10.2)
5
5
  rt-watchman (~> 0.10.0)
6
6
 
7
7
  GEM
data/lib/mtr_monitor.rb CHANGED
@@ -1,7 +1,10 @@
1
- require "mtr_monitor/version"
2
1
  require "watchman"
3
2
  require "logger"
4
3
 
4
+ require "mtr_monitor/version"
5
+ require "mtr_monitor/hop"
6
+ require "mtr_monitor/metrics"
7
+
5
8
  module MtrMonitor
6
9
  #
7
10
  # Runs a mtr trace toward a domain and saves the report
@@ -34,28 +37,8 @@ module MtrMonitor
34
37
  run "sudo mkdir -p /var/log/mtr"
35
38
  run "sudo mtr --report #{@mtr_options} #{@domain} > #{@log_path}"
36
39
  run "AWS_ACCESS_KEY_ID='#{@aws_access_key_id}' AWS_SECRET_ACCESS_KEY='#{@aws_secret_access_key}' aws s3 cp #{@log_path} #{@s3_path}"
37
- end
38
-
39
- def submit_metrics
40
- logger.info "Submitting pulse: network.mtr.pulse, tags: #{[@hostname, @name]}, prefix: #{Watchman.prefix} port: #{Watchman.port}"
41
- Watchman.submit("network.mtr.pulse", 1, :gauge, :tags => [@hostname, @name])
42
-
43
- hops.each do |hop|
44
- hop_name = hop.name.gsub(".", "-").gsub("?", "q")
45
- tags = [@hostname, @name, hop_name]
46
-
47
- Watchman.submit("network.mtr.loss", hop.loss, :gauge, :tags => tags)
48
- Watchman.submit("network.mtr.snt", hop.snt, :gauge, :tags => tags)
49
- Watchman.submit("network.mtr.last", hop.last, :gauge, :tags => tags)
50
- Watchman.submit("network.mtr.avg", hop.avg, :gauge, :tags => tags)
51
- Watchman.submit("network.mtr.best", hop.best, :gauge, :tags => tags)
52
- Watchman.submit("network.mtr.worst", hop.worst, :gauge, :tags => tags)
53
- Watchman.submit("network.mtr.std_dev", hop.std_dev, :gauge, :tags => tags)
54
- end
55
- end
56
40
 
57
- def hops
58
- `sudo cat #{@log_path}`.split("\n").map { |line| Hop.parse(line) }.compact
41
+ MtrMonitor::Metrics.submit(@log_path, @hostname, @name, @logger)
59
42
  end
60
43
 
61
44
  def run(cmd)
@@ -65,25 +48,4 @@ module MtrMonitor
65
48
  end
66
49
  end
67
50
 
68
- class Hop
69
- def self.parse(line)
70
- return unless line =~ /\|--/
71
-
72
- new(*line.split(" ")[1..-1])
73
- end
74
-
75
- attr_reader :name, :loss, :snt, :last, :avg, :best, :worst, :std_dev
76
-
77
- def initialize(name, loss, snt, last, avg, best, worst, std_dev)
78
- @name = name
79
- @loss = loss.to_f
80
- @snt = snt.to_i
81
- @last = last.to_f
82
- @avg = avg.to_f
83
- @best = best.to_f
84
- @worst = worst.to_f
85
- @std_dev = std_dev.to_f
86
- end
87
- end
88
-
89
51
  end
@@ -0,0 +1,29 @@
1
+ module MtrMonitor
2
+
3
+ # represents one hop in the MTR report
4
+ #
5
+ # example hop for `mtr --report github.com`:
6
+ # 12.|-- github-ic-318125-ash-b1.c 0.0% 10 136.2 136.2 135.0 140.7 1.5
7
+
8
+ class Hop
9
+ def self.parse(line)
10
+ return unless line =~ /\|--/
11
+
12
+ new(*line.split(" ")[1..-1])
13
+ end
14
+
15
+ attr_reader :name, :loss, :snt, :last, :avg, :best, :worst, :std_dev
16
+
17
+ def initialize(name, loss, snt, last, avg, best, worst, std_dev)
18
+ @name = name
19
+ @loss = loss.to_f
20
+ @snt = snt.to_i
21
+ @last = last.to_f
22
+ @avg = avg.to_f
23
+ @best = best.to_f
24
+ @worst = worst.to_f
25
+ @std_dev = std_dev.to_f
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,28 @@
1
+ module MtrMonitor
2
+ module Metrics
3
+
4
+ def self.submit(log_path, hostname, name, logger)
5
+ logger.info "Submitting pulse: network.mtr.pulse, tags: #{[hostname, name]}, prefix: #{Watchman.prefix} port: #{Watchman.port}"
6
+
7
+ Watchman.submit("network.mtr.pulse", 1, :gauge, :tags => [hostname, name])
8
+
9
+ hops(log_path).each do |hop|
10
+ hop_name = hop.name.gsub(".", "-").gsub("?", "q")
11
+ tags = [hostname, name, hop_name]
12
+
13
+ Watchman.submit("network.mtr.loss", hop.loss, :gauge, :tags => tags)
14
+ Watchman.submit("network.mtr.snt", hop.snt, :gauge, :tags => tags)
15
+ Watchman.submit("network.mtr.last", hop.last, :gauge, :tags => tags)
16
+ Watchman.submit("network.mtr.avg", hop.avg, :gauge, :tags => tags)
17
+ Watchman.submit("network.mtr.best", hop.best, :gauge, :tags => tags)
18
+ Watchman.submit("network.mtr.worst", hop.worst, :gauge, :tags => tags)
19
+ Watchman.submit("network.mtr.std_dev", hop.std_dev, :gauge, :tags => tags)
20
+ end
21
+ end
22
+
23
+ def self.hops(log_path)
24
+ `sudo cat #{log_path}`.split("\n").map { |line| Hop.parse(line) }.compact
25
+ end
26
+
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module MtrMonitor
2
- VERSION = "0.10.1"
2
+ VERSION = "0.10.2"
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.10.1
4
+ version: 0.10.2
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-28 00:00:00.000000000 Z
11
+ date: 2018-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rt-watchman
@@ -88,6 +88,8 @@ files:
88
88
  - docker-compose.yml
89
89
  - exe/mtr_report
90
90
  - lib/mtr_monitor.rb
91
+ - lib/mtr_monitor/hop.rb
92
+ - lib/mtr_monitor/metrics.rb
91
93
  - lib/mtr_monitor/version.rb
92
94
  - mtr_monitor.gemspec
93
95
  homepage: https://github.com/renderedtext/mtr-monitor