Skip to content

Commit

Permalink
Merge pull request #213 from riemann/disk-usage-ratio
Browse files Browse the repository at this point in the history
Report computed disk metric
  • Loading branch information
jamtur01 authored Jun 30, 2022
2 parents d9b73ef + 976a373 commit adcce99
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
6 changes: 5 additions & 1 deletion lib/riemann/tools/health.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
44 changes: 22 additions & 22 deletions spec/riemann/tools/health_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit adcce99

Please sign in to comment.