Sha256: ff7a4b8f48680589568626003b5f3e992209956db34c4efaf1b52b0cedb9e05a

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

#! /usr/bin/env ruby
#
#   metric-filesize
#
# DESCRIPTION:
#   Simple wrapper around `stat` for getting file size stats,
#   in both, bytes and blocks.
#
# OUTPUT:
#   metric data
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#   gem: socket
#
# USAGE:
#   #YELLOW
#
# NOTES:
#   Based on: Curl HTTP Timings metric (Sensu Community Plugins) by Joe Miller
#
# LICENSE:
#   Copyright 2014 Pablo Figue
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'socket'
require 'sensu-plugin/metric/cli'

class FilesizeMetrics < Sensu::Plugin::Metric::CLI::Graphite
  option :filepath,
         short: '-f PATH',
         long: '--file PATH',
         description: 'Absolute path to file to measure',
         required: true

  option :omitblocks,
         short: '-o',
         long: '--blocksno',
         description: 'Don\'t report size in blocks',
         required: true,
         default: false

  option :omitbytes,
         short: '-b',
         long: '--bytesno',
         description: 'Don\'t report size in bytes',
         required: true,
         default: false

  option :scheme,
         description: 'Metric naming scheme, text to prepend to metric',
         short: '-s SCHEME',
         long: '--scheme SCHEME',
         required: true,
         default: "#{Socket.gethostname}.filesize"

  def run
    cmd = "/usr/bin/stat --format=\"%s,%b,\" #{config[:filepath]}"
    output = `#{cmd}`

    (bytes, blocks) = output.split(',')
    unless config[:omitbytes]
      output "#{config[:scheme]}.#{config[:filepath]}.bytes", bytes
    end
    unless config[:omitblocks]
      output "#{config[:scheme]}.#{config[:filepath]}.blocks", blocks
    end

    ok
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sensu-plugins-filesystem-checks-0.0.1 bin/metric-filesize.rb