Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 59 lines (47 sloc) 1.539 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#!/usr/bin/env ruby
require "bundler"
Bundler.setup

require "cgi"
require "librato/metrics"
require "uri"

require_relative "../lib/ferret"

uri = URI.parse(ENV["LIBRATO_API_URL"])
Librato::Metrics.authenticate CGI.unescape(uri.user), uri.password

def sum(metric, opts={})
  opts[:duration] ||= 600
  opts[:end_time] ||= Time.now

  begin
    m = Librato::Metrics.fetch(metric,
      end_time: opts[:end_time],
      start_time: opts[:end_time] - opts[:duration],
      summarize_time: true,
      summarize_sources: true
    )
    m.empty? ? 0 : m["all"][0]["sum"]
  rescue Librato::Metrics::NotFound
    0
  end
end

def avail(metric, opts={})
  opts[:duration] ||= 600

  s = sum("#{metric}.success.count", opts)
  f = sum("#{metric}.failure.count", opts)
  s.to_f / (s + f) * 100
end

def mean_time(metric, opts={})
  opts[:duration] ||= 600

  s = sum("#{metric}.success.mean", opts)
end

metrics = [
  ["#{ENV["ORG"]}.dashboard_oauth_redirect.redirect", duration: 600],
  ["#{ENV["ORG"]}.git_clone.clone", duration: 600],
  ["#{ENV["ORG"]}.git_clone_bamboo.clone", duration: 600],
  ["#{ENV["ORG"]}.git_clone_elb.clone", duration: 600],
  ["#{ENV["ORG"]}.git_push_ruby.push", duration: 600],
  ["#{ENV["ORG"]}.exec_converge.poll", duration: 3600],
  ["#{ENV["ORG"]}.exec_run.run", duration: 600],
]

metrics.each do |m,opts|
  fn = m.split(".")[1]
  log(val: avail(m,opts), measure: "#{ENV["ORG"]}.#{ENV["NAME"]}.#{fn}.avail")
end
Something went wrong with that request. Please try again.