Sha256: 7f353a5b191c46d4b3c5d957fe734632861f92c9b77225e44ced88447b3f4a0f

Contents?: true

Size: 550 Bytes

Versions: 2

Compression:

Stored size: 550 Bytes

Contents

class Riemann::Babbler::Cpu < Riemann::Babbler

  def collect
    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]
    
    if @old_cpu
      { :service => plugin.service, :metric => fraction }
    else
      { :service => plugin.service, :state => 'ok' }
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
riemann-babbler-0.4.8 lib/riemann/babbler/plugins/cpu.rb
riemann-babbler-0.4.7 lib/riemann/babbler/plugins/cpu.rb