<commit_before># WMI Metrics
# ===
#
# Collects a variety of system metrics every 10 seconds (by default).
# Expects a "graphite" handler on the Sensu server, eg:
#
# "graphite": {
#   "type": "tcp",
#   "socket": {
#     "host": "graphite.hw-ops.com",
#     "port": 2003
#   },
#   "mutator": "only_check_output"
# }
#
# Copyright 2014 Heavy Water Operations, LLC.
#
# Changelog
# ----------
# 03/11/2015 - <NAME> (@cloakedcode) added cumulative metric
#              collection for network traffic over interval timespan.
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.

require 'win32ole'

module Sensu
  module Extension
    class WMIMetrics < Check
      def name
        'wmi_metrics'
      end

      def description
        'collects system metrics, using wmi and the graphite plain-text format'
      end

      def definition
        {
          type: 'metric',
          name: name,
          interval: options[:interval],
          standalone: true,
          handler: options[:handler]
        }
      end

      def post_init
        @metrics = {}
        @wmi = WIN32OLE.connect('winmgmts://')

        # setup timer for cumulative metrics
        EM.add_periodic_timer(1) do
          network_interface_metrics
        end
        true
      end

      def run
        memory_metrics do
          disk_metrics do
            cpu_metrics do
              yield flush_metrics, 0
            end
          end
        end
      end

      private<commit_msg>Oops, need a block in there or a yield fails<commit_after># WMI Metrics
# ===
#
# Collects a variety of system metrics every 10 seconds (by default).
# Expects a "graphite" handler on the Sensu server, eg:
#
# "graphite": {
#   "type": "tcp",
#   "socket": {
#     "host": "graphite.hw-ops.com",
#     "port": 2003
#   },
#   "mutator": "only_check_output"
# }
#
# Copyright 2014 Heavy Water Operations, LLC.
#
# Changelog
# ----------
# 03/11/2015 - <NAME> (@cloakedcode) added cumulative metric
#              collection for network traffic over interval timespan.
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.

require 'win32ole'

module Sensu
  module Extension
    class WMIMetrics < Check
      def name
        'wmi_metrics'
      end

      def description
        'collects system metrics, using wmi and the graphite plain-text format'
      end

      def definition
        {
          type: 'metric',
          name: name,
          interval: options[:interval],
          standalone: true,
          handler: options[:handler]
        }
      end

      def post_init
        @metrics = {}
        @wmi = WIN32OLE.connect('winmgmts://')

        # setup timer for cumulative metrics
        EM.add_periodic_timer(1) do
          network_interface_metrics do
          end
        end
        true
      end

      def run
        memory_metrics do
          disk_metrics do
            cpu_metrics do
              yield flush_metrics, 0
            end
          end
        end
      end

      private
{'fraction_non_alphanumeric': 0.09342447916666667, 'fraction_numerical': 0.015625, 'mean_word_length': 1.8827392120075046, 'pattern_counts': {'":': 12, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2208832', 'n_tokens_mistral': 938, 'n_tokens_neox': 877, 'n_words': 286}