Sha256: f01d7d07f14dfb287b56d2e50f354bbc61bf81b6e252bea17409ae6ea1027538

Contents?: true

Size: 841 Bytes

Versions: 17

Compression:

Stored size: 841 Bytes

Contents

#!/usr/bin/env ruby
require 'rubygems'
$: <<  File.dirname(__FILE__)+'/../lib'
require 'graphiterb'
Configliere.use :commandline, :config_file

Settings.read 'graphite.yaml'
Settings.resolve!
Log = Logger.new($stderr) unless defined?(Log)

class LoadavgGraphiteSender < Graphiterb::GraphiteSender
  def hostname
    @hostname ||= `hostname`.chomp
  end

  def loadavgs
    # File.open('/proc/loadavg').read.strip.split[0..2]
    `uptime`.chomp.gsub(/.*:\s+/, '').split(/[,\s]+/)
  end

  def loadavgs_metrics
    %w[1min 5min 15min].zip(loadavgs).map do |duration, avg|
      ["system.#{hostname}.loadavg_#{duration}", avg]
    end
  end

  def send_loop
    loop do
      send *loadavgs_metrics
      Log.info "Sleeping #{Settings.update_delay}"
      sleep Settings.update_delay.to_i
    end
  end
end

LoadavgGraphiteSender.new.send_loop

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
graphiterb-0.2.11 examples/loadavg_graphite_sender.rb
graphiterb-0.2.10 examples/loadavg_graphite_sender.rb
graphiterb-0.2.9 examples/loadavg_graphite_sender.rb
graphiterb-0.2.7 examples/loadavg_graphite_sender.rb
graphiterb-0.2.6 examples/loadavg_graphite_sender.rb
graphiterb-0.2.5 examples/loadavg_graphite_sender.rb
graphiterb-0.2.4 examples/loadavg_graphite_sender.rb
graphiterb-0.2.3 examples/loadavg_graphite_sender.rb
graphiterb-0.2.2 examples/loadavg_graphite_sender.rb
graphiterb-0.2.1 examples/loadavg_graphite_sender.rb
graphiterb-0.2.0 examples/loadavg_graphite_sender.rb
graphiterb-0.1.5 examples/loadavg_graphite_sender.rb
graphiterb-0.1.4 examples/loadavg_graphite_sender.rb
graphiterb-0.1.3 bin/loadavg_graphite_sender.rb
graphiterb-0.1.2 bin/loadavg_graphite_sender.rb
graphiterb-0.1.1 bin/loadavg_graphite_sender.rb
graphiterb-0.1.0 bin/loadavg_graphite_sender.rb