<commit_before>#!/usr/bin/env ruby
#
# Network interface throughput
# ===
#
# DEPENDENCIES:
#   sensu-plugin Ruby gem
#   sysstat to get 'sar'
#
# 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'

class NetIFMetrics < Sensu::Plugin::Metric::CLI::Graphite

  option :scheme,
    :description => "Metric naming scheme, text to prepend to .$parent.$child",
    :long => "--scheme SCHEME",
    :default => "#{Socket.gethostname}"

  def run
    `sar -n DEV 1 1 | grep Average | grep -v IFACE | awk '{ print $2 }'`.split("\n").each do |nic|
      stats = `sar -n DEV 1 1 | grep Average | grep #{nic} | awk '{ print $5, $6 }'`.split(' ')
        unless stats.empty?
          output "#{config[:scheme]}.#{nic}.rx_kB_per_sec", stats[0].to_i.round
          output "#{config[:scheme]}.#{nic}.tx_kB_per_sec", stats[1].to_i.round
        end
    end

    ok

  end

end<commit_msg>Update the netif-metrics plugin for efficiency<commit_after>#!/usr/bin/env ruby
#
# Network interface throughput
# ===
#
# DEPENDENCIES:
#   sensu-plugin Ruby gem
#   sysstat to get 'sar'
#
# 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'

class NetIFMetrics < Sensu::Plugin::Metric::CLI::Graphite

  option :scheme,
    :description => "Metric naming scheme, text to prepend to .$parent.$child",
    :long => "--scheme SCHEME",
    :default => "#{Socket.gethostname}"

  def run
    `sar -n DEV 1 1 | grep Average | grep -v IFACE`.each_line do |line|
      stats = line.split(/\s+/)
      unless stats.empty?
        stats.shift
        nic = stats.shift
        output "#{config[:scheme]}.#{nic}.rx_kB_per_sec", stats[2].to_f if stats[3]
        output "#{config[:scheme]}.#{nic}.tx_kB_per_sec", stats[3].to_f if stats[3]
      end
    end

    ok

  end

end
{'fraction_non_alphanumeric': 0.153, 'fraction_numerical': 0.0105, 'mean_word_length': 3.1774530271398747, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5694714', 'n_tokens_mistral': 729, 'n_tokens_neox': 694, 'n_words': 196}