diff --git a/lib/riemann/tools/health.rb b/lib/riemann/tools/health.rb index 9f2ec7b7..dfbd31e0 100644 --- a/lib/riemann/tools/health.rb +++ b/lib/riemann/tools/health.rb @@ -320,7 +320,11 @@ def disk next if f[0] == 'Filesystem' # Calculate capacity - x = f[4].to_f / 100 + used = f[2].to_i + available = f[3].to_i + total_without_reservation = used + available + + x = used.to_f / total_without_reservation if x > @limits[:disk][:critical] alert "disk #{f[5]}", :critical, x, "#{f[4]} used" diff --git a/spec/riemann/tools/health_spec.rb b/spec/riemann/tools/health_spec.rb index 46cd4134..3a62ac68 100644 --- a/spec/riemann/tools/health_spec.rb +++ b/spec/riemann/tools/health_spec.rb @@ -22,29 +22,29 @@ end it 'reports all zfs filesystems' do - allow(subject).to receive(:alert).with('disk /', :ok, 0.07, '7% used') - allow(subject).to receive(:alert).with('disk /var/audit', :ok, 0, '0% used') - allow(subject).to receive(:alert).with('disk /var/mail', :ok, 0, '0% used') - allow(subject).to receive(:alert).with('disk /tmp', :ok, 0, '0% used') - allow(subject).to receive(:alert).with('disk /zroot', :ok, 0, '0% used') - allow(subject).to receive(:alert).with('disk /var/crash', :ok, 0, '0% used') - allow(subject).to receive(:alert).with('disk /usr/src', :ok, 0, '0% used') - allow(subject).to receive(:alert).with('disk /usr/home', :ok, 0.33, '33% used') - allow(subject).to receive(:alert).with('disk /var/tmp', :ok, 0, '0% used') - allow(subject).to receive(:alert).with('disk /var/log', :ok, 0, '0% used') - allow(subject).to receive(:alert).with('disk /usr/home/romain/Medias', :ok, 0.4, '40% used') + allow(subject).to receive(:alert).with('disk /', :ok, 0.07185344331519083, '7% used') + allow(subject).to receive(:alert).with('disk /var/audit', :ok, 2.9484841782529697e-07, '0% used') + allow(subject).to receive(:alert).with('disk /var/mail', :ok, 4.529924689197913e-06, '0% used') + allow(subject).to receive(:alert).with('disk /tmp', :ok, 0.0001386131897766662, '0% used') + allow(subject).to receive(:alert).with('disk /zroot', :ok, 2.9484841782529697e-07, '0% used') + allow(subject).to receive(:alert).with('disk /var/crash', :ok, 2.9484841782529697e-07, '0% used') + allow(subject).to receive(:alert).with('disk /usr/src', :ok, 2.9484841782529697e-07, '0% used') + allow(subject).to receive(:alert).with('disk /usr/home', :ok, 0.33075683535672684, '33% used') + allow(subject).to receive(:alert).with('disk /var/tmp', :ok, 4.02065981198671e-07, '0% used') + allow(subject).to receive(:alert).with('disk /var/log', :ok, 2.0545157787749945e-05, '0% used') + allow(subject).to receive(:alert).with('disk /usr/home/romain/Medias', :ok, 0.39906518922242257, '40% used') subject.disk - expect(subject).to have_received(:alert).with('disk /', :ok, 0.07, '7% used') - expect(subject).to have_received(:alert).with('disk /var/audit', :ok, 0, '0% used') - expect(subject).to have_received(:alert).with('disk /var/mail', :ok, 0, '0% used') - expect(subject).to have_received(:alert).with('disk /tmp', :ok, 0, '0% used') - expect(subject).to have_received(:alert).with('disk /zroot', :ok, 0, '0% used') - expect(subject).to have_received(:alert).with('disk /var/crash', :ok, 0, '0% used') - expect(subject).to have_received(:alert).with('disk /usr/src', :ok, 0, '0% used') - expect(subject).to have_received(:alert).with('disk /usr/home', :ok, 0.33, '33% used') - expect(subject).to have_received(:alert).with('disk /var/tmp', :ok, 0, '0% used') - expect(subject).to have_received(:alert).with('disk /var/log', :ok, 0, '0% used') - expect(subject).to have_received(:alert).with('disk /usr/home/romain/Medias', :ok, 0.4, '40% used') + expect(subject).to have_received(:alert).with('disk /', :ok, 0.07185344331519083, '7% used') + expect(subject).to have_received(:alert).with('disk /var/audit', :ok, 2.9484841782529697e-07, '0% used') + expect(subject).to have_received(:alert).with('disk /var/mail', :ok, 4.529924689197913e-06, '0% used') + expect(subject).to have_received(:alert).with('disk /tmp', :ok, 0.0001386131897766662, '0% used') + expect(subject).to have_received(:alert).with('disk /zroot', :ok, 2.9484841782529697e-07, '0% used') + expect(subject).to have_received(:alert).with('disk /var/crash', :ok, 2.9484841782529697e-07, '0% used') + expect(subject).to have_received(:alert).with('disk /usr/src', :ok, 2.9484841782529697e-07, '0% used') + expect(subject).to have_received(:alert).with('disk /usr/home', :ok, 0.33075683535672684, '33% used') + expect(subject).to have_received(:alert).with('disk /var/tmp', :ok, 4.02065981198671e-07, '0% used') + expect(subject).to have_received(:alert).with('disk /var/log', :ok, 2.0545157787749945e-05, '0% used') + expect(subject).to have_received(:alert).with('disk /usr/home/romain/Medias', :ok, 0.39906518922242257, '40% used') end end end