Sha256: f0ef0f642ca0129a4bb8bc3bbf6b4b47aa06f5ab7879f95bdabedb592009a80c

Contents?: true

Size: 1.32 KB

Versions: 16

Compression:

Stored size: 1.32 KB

Contents

#! /usr/bin/env ruby
#
#   metric-windows-processor-queue-length.rb
#
# DESCRIPTION:
#   This plugin collects and outputs the Processor Queue Length.
#   It uses Typeperf to get the processor usage.
#
# OUTPUT:
#   metric data
#
# PLATFORMS:
#   Windows
#
# DEPENDENCIES:
#   gem: sensu-plugin
#
# USAGE:
#
# NOTES:
#
# LICENSE:
#   Andy Royle <ajroyle@gmail.com>
#   Released under the same terms as Sensu (the MIT license); see LICENSE for details.
#
require 'sensu-plugin/metric/cli'
require 'socket'

class CpuMetric < Sensu::Plugin::Metric::CLI::Graphite
  option :scheme,
         description: 'Metric naming scheme, text to prepend to .$parent.$child',
         long: '--scheme SCHEME',
         default: Socket.gethostname.to_s

  def acquire_cpu_load
    temp_arr = []
    timestamp = Time.now.utc.to_i
    IO.popen('typeperf -sc 1 "system\\processor queue length" ') { |io| io.each { |line| temp_arr.push(line) } }
    temp = temp_arr[2].split(',')[1]
    queue_metric = temp[1, temp.length - 3].to_f
    [queue_metric, timestamp]
  end

  def run
    values = acquire_cpu_load
    metrics = {
      cpu: {
        queuelength: values[0]
      }
    }
    metrics.each do |parent, children|
      children.each do |child, value|
        output [config[:scheme], parent, child].join('.'), value, values[1]
      end
    end
    ok
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
sensu-plugins-windows-2.9.1 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-2.9.0 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-2.8.1 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-2.8.0 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-2.7.0 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-2.6.0 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-2.5.0 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-2.4.1 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-2.4.0 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-2.3.0 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-2.2.1 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-2.2.0 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-2.1.0 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-2.0.0 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-1.0.0 bin/metric-windows-processor-queue-length.rb
sensu-plugins-windows-0.1.0 bin/metric-windows-processor-queue-length.rb