Sha256: fb426b9f3cf7582bd5e329bc18bf088a8e4f60400c6a00df00f43d420a72e456

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

require "zabbix-ruby-client/logger"
require "zabbix-ruby-client/plugin_base"

module ZabbixRubyClient
  module Plugins
    module Network
      extend self
      extend ZabbixRubyClient::PluginBase

      def collect(*args)
        host = args[0]
        interface = args[1]
        info = get_info(interface)
        if info
          time = Time.now.to_i
          back = []
          back << "#{host} net.rx_ok[#{interface}] #{time} #{info[2]}"
          back << "#{host} net.rx_packets[#{interface}] #{time} #{info[3]}"
          back << "#{host} net.rx_err[#{interface}] #{time} #{info[4]}"
          back << "#{host} net.rx_drop[#{interface}] #{time} #{info[5]}"
          back << "#{host} net.tx_ok[#{interface}] #{time} #{info[10]}"
          back << "#{host} net.tx_packets[#{interface}] #{time} #{info[11]}"
          back << "#{host} net.tx_err[#{interface}] #{time} #{info[12]}"
          back << "#{host} net.tx_drop[#{interface}] #{time} #{info[13]}"
          return back
        else
          return []
        end
      end

      def discover(*args)
        interface = args[0]
        [ "net.if.discovery", "{\"{#NET_IF}\": \"#{interface}\"}" ]
      end

    private

      def get_info(interface)
        info = getline("/proc/net/dev", "#{interface}: ")
        if info
          info.split(/\s+/)
        else
          false
        end
      end
      
    end
  end
end

ZabbixRubyClient::Plugins.register('network', ZabbixRubyClient::Plugins::Network)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zabbix-ruby-client-0.0.19 lib/zabbix-ruby-client/plugins/network.rb
zabbix-ruby-client-0.0.18 lib/zabbix-ruby-client/plugins/network.rb