Sha256: 54b3b0d2367095e1133aa56b320f4241438a68e478d296eec3cc6011734ea55a

Contents?: true

Size: 1.03 KB

Versions: 13

Compression:

Stored size: 1.03 KB

Contents

always_start true
interval 60

default[:per_process] = false

collect :os => 'linux' do
  @old_cpu ||= {}
  File.read('/proc/stat').each_line do |cpu_line|
    cpu_number = cpu_line.scan(/cpu(\d+|\s)\s+/)
    next if cpu_number.empty?
    cpu_number = cpu_number[0][0] == ' ' ? '_total' : cpu_number[0][0]
    cpu_line[/cpu(\d+|\s)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/]
    _, u2, n2, s2, i2 = [$1, $2, $3, $4, $5].map { |e| e.to_i }
    unless @old_cpu[cpu_number].nil?
      u1, n1, s1, i1 = @old_cpu[cpu_number]
      used           = (u2+n2+s2) - (u1+n1+s1)
      total          = used + i2-i1
      fraction       = used.to_f / total
    end
    @old_cpu[cpu_number] = [u2, n2, s2, i2]
    service              = "cpu usage cpu#{cpu_number}"
    description          = "Cpu#{cpu_number} usage"
    if cpu_number == '_total'
      event(:service => service, :metric => fraction, :desc => description, :warning => 70, :critical => 58)
    else
      event(:service => service, :metric => fraction, :desc => description, :state => 'ok')
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
kurchatov-0.0.5.pre4 examples/cpu.rb
kurchatov-0.0.5.pre2 examples/cpu.rb
kurchatov-0.0.5.pre1 examples/cpu.rb
kurchatov-0.0.4 examples/cpu.rb
kurchatov-0.0.4d examples/cpu.rb
kurchatov-0.0.4c examples/cpu.rb
kurchatov-0.0.4b examples/cpu.rb
kurchatov-0.0.3 examples/cpu.rb
kurchatov-0.0.3b examples/cpu.rb
kurchatov-0.0.3a examples/cpu.rb
kurchatov-0.0.2 examples/cpu.rb
kurchatov-0.0.2b examples/cpu.rb
kurchatov-0.0.1 examples/cpu.rb