Sha256: 265cac19829965625e110c09ea82c010257f7120b245dac8b8cce38eaa7c549c

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

# bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
Struct.new("NetworkStat", :dev,
           :rbytes, :rpackets, :rerrs, :rdrop, :rfifo, :rframe, :rcompressed, :rmulticast,
           :wbytes, :wpackets, :werrs, :wdrop, :wfifo, :wcolls, :wcarrier, :wcompressed)

module Ganymed
  class Collector
    class Network < Base
      def collect!
        return if not File.readable?('/proc/net/dev')

        File.open('/proc/net/dev') do |f|
          f.each do |line|
            next unless line =~ /:/

            ns = Struct::NetworkStat.new(*line.strip.split(/\s+/))
            ns.dev.sub!(/:$/, '')

            next if @config.exclude.map {|e| Regexp.new(e).match(ns.dev)}.any?

            @sampler.emit(:derive, "os.net.#{ns.dev}.rbytes", ns.rbytes)
            @sampler.emit(:derive, "os.net.#{ns.dev}.wbytes", ns.wbytes)
            @sampler.emit(:derive, "os.net.#{ns.dev}.rpackets", ns.rpackets)
            @sampler.emit(:derive, "os.net.#{ns.dev}.wpackets", ns.wpackets)
            @sampler.emit(:derive, "os.net.#{ns.dev}.rerrs", ns.rerrs)
            @sampler.emit(:derive, "os.net.#{ns.dev}.werrs", ns.werrs)
          end
        end
      end

      def interval
        @config.interval.tap{} or 0.1
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ganymed-0.1.2 lib/ganymed/collector/network.rb
ganymed-0.1.1 lib/ganymed/collector/network.rb