Sha256: d91d9d7a3e13fa5f6865fa4bf3dbdd297aaee27c344fed85190c3e2463323694

Contents?: true

Size: 1.67 KB

Versions: 16

Compression:

Stored size: 1.67 KB

Contents

#! /usr/bin/env ruby
#
#   metric-windows-network.rb
#
# DESCRIPTION:
#   This plugin collects and outputs the uptime in seconds in a Graphite acceptable format.
#
# OUTPUT:
#   metric data
#
# PLATFORMS:
#   Windows
#
# DEPENDENCIES:
#   gem: sensu-plugin
#   gem: socket
#
# USAGE:
#
# NOTES:
#
# LICENSE:
#   Copyright 2015 <miguelangel.garcia@gmail.com>
#   Released under the same terms as Sensu (the MIT license); see LICENSE for details.
#
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-plugin/metric/cli'
require 'socket'
require 'time'
require 'csv'

class UptimeMetric < Sensu::Plugin::Metric::CLI::Graphite
  option :scheme,
         description: 'Metric naming scheme, text to prepend to .$interface.$metric',
         long: '--scheme SCHEME',
         default: "#{Socket.gethostname}.system.network"
  option :interface,
         description: 'Metric naming scheme, text to prepend to .$parent.$child',
         long: '--interface INTERFACE',
         default: '*'

  def run
    interface = config[:interface]
    timestamp = Time.now.utc.to_i
    IO.popen("typeperf -sc 1 \"\\Network Interface(#{interface})\\*\" ") do |io|
      CSV.parse(io.read, headers: true) do |row|
        row.each do |k, v|
          next unless v && k
          break if v.start_with? 'Exiting'

          path = k.split('\\')
          ifz = path[3]
          metric = path[4]
          next unless ifz && metric

          ifz_name = ifz[18, ifz.length - 19].tr('.', ' ')
          value = format('%.2f', v.to_f)
          name = [config[:scheme], ifz_name, metric].join('.').tr(' ', '_').tr('{}', '').tr('[]', '')

          output name, value, timestamp
        end
      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-network.rb
sensu-plugins-windows-2.9.0 bin/metric-windows-network.rb
sensu-plugins-windows-2.8.1 bin/metric-windows-network.rb
sensu-plugins-windows-2.8.0 bin/metric-windows-network.rb
sensu-plugins-windows-2.7.0 bin/metric-windows-network.rb
sensu-plugins-windows-2.6.0 bin/metric-windows-network.rb
sensu-plugins-windows-2.5.0 bin/metric-windows-network.rb
sensu-plugins-windows-2.4.1 bin/metric-windows-network.rb
sensu-plugins-windows-2.4.0 bin/metric-windows-network.rb
sensu-plugins-windows-2.3.0 bin/metric-windows-network.rb
sensu-plugins-windows-2.2.1 bin/metric-windows-network.rb
sensu-plugins-windows-2.2.0 bin/metric-windows-network.rb
sensu-plugins-windows-2.1.0 bin/metric-windows-network.rb
sensu-plugins-windows-2.0.0 bin/metric-windows-network.rb
sensu-plugins-windows-1.0.0 bin/metric-windows-network.rb
sensu-plugins-windows-0.1.0 bin/metric-windows-network.rb