Sha256: 2208834e99f6952de74e1b0e6f6bd54c5066b1ae874146fed6845d1979b4add6

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

#! /usr/bin/env ruby
#
#   uptime-windows
#
# DESCRIPTION:
#   This is metrics which outputs the uptime in seconds in 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

2 entries across 2 versions & 1 rubygems

Version Path
sensu-plugins-windows-0.0.10 bin/metrics-windows-uptime.rb
sensu-plugins-windows-0.0.9 bin/metrics-windows-uptime.rb