Sha256: c4247faf4ef27cc4022024ad1500cb2dcd77e353449e8afe8cf02cb7a49c5e6f

Contents?: true

Size: 1.57 KB

Versions: 8

Compression:

Stored size: 1.57 KB

Contents

#!/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)", :type => Integer
  opt :critical, "Dir space critical threshold (in bytes)", :type => Integer
  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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
riemann-tools-0.2.14 bin/riemann-dir-space
riemann-tools-0.2.13 bin/riemann-dir-space
riemann-tools-0.2.11 bin/riemann-dir-space
riemann-tools-0.2.10 bin/riemann-dir-space
riemann-tools-0.2.9 bin/riemann-dir-space
riemann-tools-0.2.8 bin/riemann-dir-space
riemann-tools-0.2.7 bin/riemann-dir-space
riemann-tools-0.2.6 bin/riemann-dir-space