-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from yeller/add_riemann_dir_space
add directory space use monitoring
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# Gathers the space used by a directory and submits it to riemann | ||
|
||
require File.expand_path('../../lib/riemann/tools', __FILE__) | ||
|
||
class Riemann::Tools::DirSpace | ||
include Riemann::Tools | ||
|
||
opt :directory, "", :default => '/var/log' | ||
opt :service_prefix, "The first part of the service name, before the directory path", :default => "dir-space" | ||
opt :warning, "Dir space warning threshold (in bytes)" | ||
opt :critical, "Dir space critical threshold (in bytes)" | ||
opt :alert_on_missing, "Send a critical metric if the directory is missing?", :default => true | ||
|
||
def initialize | ||
@dir = opts.fetch(:directory) | ||
@service_prefix = opts.fetch(:service_prefix) | ||
@warning = opts.fetch(:warning, nil) | ||
@critical = opts.fetch(:critical, nil) | ||
@alert_on_missing = opts.fetch(:alert_on_missing) | ||
end | ||
|
||
def tick | ||
if Dir.exists?(@dir) | ||
metric = `du '#{@dir}'`.lines.to_a.last.split("\t")[0].to_i | ||
report( | ||
:service => "#{@service_prefix} #{@dir}", | ||
:metric => metric, | ||
:state => state(metric), | ||
:tags => ['dir_space'] | ||
) | ||
elsif @alert_on_missing | ||
report( | ||
:service => "#{@service_prefix} #{@dir} missing", | ||
:description => "#{@service_prefix} #{@dir} does not exist", | ||
:metric => metric, | ||
:state => 'critical', | ||
:tags => ['dir_space'] | ||
) | ||
end | ||
end | ||
|
||
def state(metric) | ||
if @critical && metric > @critical | ||
'critical' | ||
elsif @warning && metric > @warning | ||
'warning' | ||
else | ||
'ok' | ||
end | ||
end | ||
end | ||
|
||
Riemann::Tools::DirSpace.run |