Sha256: 4c8309bf9b8dc76f78fb735d7869c5fd9cfd494b49ccedec78c62e72879f8136

Contents?: true

Size: 1.25 KB

Versions: 16

Compression:

Stored size: 1.25 KB

Contents

#! /usr/bin/env ruby
#
#   metric-windows-uptime.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'

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

  def acquire_uptime
    temp_arr = []
    timestamp = Time.now.utc.to_i
    IO.popen('typeperf -sc 1 "\\System\\System Up Time" ') { |io| io.each { |line| temp_arr.push(line) } }
    uptime_str = temp_arr[2].split(',')[1]
    uptime = uptime_str.strip[1, uptime_str.length - 3]
    [format('%.2f', uptime), timestamp]
  end

  def run
    # To get the uptime usage
    values = acquire_uptime
    output [config[:scheme], 'uptime'].join('.'), values[0], values[1]
    ok
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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