Sha256: c7da2f81992b84130e619af0423ebe00e3c6c081bda2fefbab3eb61fe0dbb4f1

Contents?: true

Size: 653 Bytes

Versions: 25

Compression:

Stored size: 653 Bytes

Contents

class Riemann::Babbler::Cpu
  include Riemann::Babbler

  def plugin
    options.plugins.cpu
  end

  def cpu
    cpu = File.read('/proc/stat')
    cpu[/cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/]
    u2, n2, s2, i2 = [$1, $2, $3, $4].map { |e| e.to_i }

    if @old_cpu
      u1, n1, s1, i1 = @old_cpu
      used = (u2+n2+s2) - (u1+n1+s1)
      total = used + i2-i1
      fraction = used.to_f / total
    end

    @old_cpu = [u2, n2, s2, i2]
    fraction
  end

  def tick
    current_state = cpu
    report({
      :service => plugin.service,
      :state => state(current_state),
      :metric => current_state
    })
  end

end

Riemann::Babbler::Cpu.run

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
riemann-babbler-0.2.8 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.2.7 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.2.6 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.2.5 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.2.4 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.2.3 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.2.2 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.2.1 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.2.0 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.1.9 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.1.8 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.1.7 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.1.6 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.1.5 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.1.4 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.1.3 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.1.2 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.1.1 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.1.0 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.0.9 lib/riemann/babbler/plugins/cpu.rb