Class: MtrMonitor::Report
- Inherits:
-
Object
- Object
- MtrMonitor::Report
- Defined in:
- lib/mtr_monitor.rb
Overview
Runs a mtr trace toward a domain and saves the report to /var/log/mtr/<domain>_timestamp.log , uploads to s3 and reports metrics to statsd.
Instance Method Summary collapse
- #generate ⇒ Object
- #hops ⇒ Object
- #host_ip_address ⇒ Object
-
#initialize(name, domain, s3_bucket, aws_access_key_id, aws_secret_access_key) ⇒ Report
constructor
A new instance of Report.
- #submit_metrics ⇒ Object
Constructor Details
#initialize(name, domain, s3_bucket, aws_access_key_id, aws_secret_access_key) ⇒ Report
Returns a new instance of Report.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mtr_monitor.rb', line 11 def initialize(name, domain, s3_bucket, aws_access_key_id, aws_secret_access_key) @name = name @domain = domain @s3_bucket = s3_bucket @aws_access_key_id = aws_access_key_id @aws_secret_access_key = aws_secret_access_key @log_name = "#{@name}/#{Time.now.strftime("%Y-%m-%d")}/#{host_ip_address}/#{Time.now.strftime("%H-%M")}.log" @log_path = "/var/log/mtr/#{@log_name.gsub("/", "-")}" @s3_path = "s3://#{@s3_bucket}/#{@log_name}" end |
Instance Method Details
#generate ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/mtr_monitor.rb', line 23 def generate puts "Local Path : #{@log_path}" puts "S3 Path : #{@s3_path}" `sudo mkdir -p /var/log/mtr` `sudo sh -c 'mtr --report #{@domain} > #{@log_path}'` `AWS_ACCESS_KEY_ID='#{@aws_access_key_id}' AWS_SECRET_ACCESS_KEY='#{@aws_secret_access_key}' aws s3 cp #{@log_path} #{@s3_path}` end |
#hops ⇒ Object
47 48 49 |
# File 'lib/mtr_monitor.rb', line 47 def hops `sudo cat #{@log_path}`.split("\n").map { |line| Hop.parse(line) }.compact end |
#host_ip_address ⇒ Object
51 52 53 |
# File 'lib/mtr_monitor.rb', line 51 def host_ip_address `/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1`.strip.gsub(".", "-") end |
#submit_metrics ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mtr_monitor.rb', line 32 def submit_metrics hops.each do |hop| hop_name = hop.name.gsub(".", "-").gsub("?", "q") = [`hostname`.strip, @name, hop_name] Watchman.submit("network.mtr.loss", hop.loss, :gauge, :tags => ) Watchman.submit("network.mtr.snt", hop.snt, :gauge, :tags => ) Watchman.submit("network.mtr.last", hop.last, :gauge, :tags => ) Watchman.submit("network.mtr.avg", hop.avg, :gauge, :tags => ) Watchman.submit("network.mtr.best", hop.best, :gauge, :tags => ) Watchman.submit("network.mtr.worst", hop.worst, :gauge, :tags => ) Watchman.submit("network.mtr.std_dev", hop.std_dev, :gauge, :tags => ) end end |