Sha256: 771aae3b585a386eb350df66470ba52d61aa696f257299b66cf9550d36a65b6f

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 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[1]}"
          back << "#{host} net.rx_packets[#{interface}] #{time} #{info[2]}"
          back << "#{host} net.rx_err[#{interface}] #{time} #{info[3]}"
          back << "#{host} net.rx_drop[#{interface}] #{time} #{info[4]}"
          back << "#{host} net.tx_ok[#{interface}] #{time} #{info[9]}"
          back << "#{host} net.tx_packets[#{interface}] #{time} #{info[10]}"
          back << "#{host} net.tx_err[#{interface}] #{time} #{info[11]}"
          back << "#{host} net.tx_drop[#{interface}] #{time} #{info[12]}"
          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

1 entries across 1 versions & 1 rubygems

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