Sha256: c7386d71ade8a57dec5446d9efce5fd66752b69add229be58c54656daf319029

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

#! /usr/bin/env ruby
#
#   check-lxc-memstat
#
# DESCRIPTION:
#   This is a simple check script for Sensu to check out the LXC's memory usage
#
# OUTPUT:
#   plain text
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#   gem: lxc
#
# USAGE:
#   check-lxc-memstat.rb -n name -w warn  -c critical
#
#   check-lxc-memstat.rb -n testdebian -w 80 -c 90
#
#   Default lxc is "testdebian", change to if you dont want to pass host
#   option
#
# NOTES:
#
# LICENSE:
#   Deepak Mohan Dass   <deepakmdass88@gmail.com>
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'sensu-plugin/check/cli'
require 'lxc'

class CheckLXCMemstat < Sensu::Plugin::Check::CLI
  option :name,
         short: '-n name',
         default: 'testdebian'

  option :warning,
         short: '-w warning',
         default: '80'

  option :critical,
         short: '-c critical',
         default: '90'

  def run
    lxc = LXC.new
    conn = LXC.container.new(lxc: lxc, name: config[:name].to_s)
    if conn.exists?
      if conn.running?
        used = conn.memory_usage
        max = conn.memory_limit
        if used > (max * (config[:critical].to_s.to_f / 100))
          critical "container #{config[:name]} memory usage crossed the critical limit"
        elsif used > (max * (config[:warning].to_s.to_f / 100))
          warning "container #{config[:name]} memory usage crossed the warning limit"
        else
          ok "container #{config[:name]} memory usage is normal"
        end
      else
        critical "container #{config[:name]} is not running"
      end
    else
      critical "container #{config[:name]} does not exists"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sensu-plugins-lxc-1.0.0 bin/check-lxc-memstat.rb