struct Hardware::Net

Overview

Network informations about the system or a process like the brandwidth use.

Example of network brandwidth calculation:

net = Hardware::Net.new # System network stats
old_in, old_out = net.in_octets, net.out_octets
loop do
  sleep 1
  net = Hardware::Net.new # Update network stats
  now_in, now_out = net.in_octets, net.out_octets
  puts "down: #{(now_in - old_in) / 1000}kB/s | up: #{(now_out - old_out) / 1000}kB/s" # => down: 427kB/s | up: 24kB/s
  old_in, old_out = now_in, now_out
end

Defined in:

net.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(pid : Int32? = nil) #

Creates a new Hardware::Net for the system, or a given PID.


[View source]

Instance Method Detail

def in_bcast_octets : Int64 #

Returns the ""InBcastOctets"" field of the IpExt field in net/netstat.


[View source]
def in_bcast_pkts : Int64 #

Returns the ""InBcastPkts"" field of the IpExt field in net/netstat.


[View source]
def in_ce_pkts : Int64 #

Returns the ""InCePkts"" field of the IpExt field in net/netstat. Only in recent versions of Linux


[View source]
def in_csum_errors : Int64 #

Returns the ""InCsumErrors"" field of the IpExt field in net/netstat. Only in recent versions of Linux


[View source]
def in_ect0_pkts : Int64 #

Returns the ""InEct0Pkts"" field of the IpExt field in net/netstat. Only in recent versions of Linux


[View source]
def in_ect1_pkts : Int64 #

Returns the ""InEct1Pkts"" field of the IpExt field in net/netstat. Only in recent versions of Linux


[View source]
def in_mcast_octets : Int64 #

Returns the ""InMcastOctets"" field of the IpExt field in net/netstat.


[View source]
def in_mcast_pkts : Int64 #

Returns the ""InMcastPkts"" field of the IpExt field in net/netstat.


[View source]
def in_no_ect_pkts : Int64 #

Returns the ""InNoEctPkts"" field of the IpExt field in net/netstat. Only in recent versions of Linux


[View source]
def in_no_routes : Int64 #

Returns the ""InNoRoutes"" field of the IpExt field in net/netstat.


[View source]
def in_octets : Int64 #

Returns the ""InOctets"" field of the IpExt field in net/netstat.


[View source]
def in_truncated_pkts : Int64 #

Returns the ""InTruncatedPkts"" field of the IpExt field in net/netstat.


[View source]
def ip_ext : Hash(String, Int64) #

[View source]
def out_bcast_octets : Int64 #

Returns the ""OutBcastOctets"" field of the IpExt field in net/netstat.


[View source]
def out_bcast_pkts : Int64 #

Returns the ""OutBcastPkts"" field of the IpExt field in net/netstat.


[View source]
def out_mcast_octets : Int64 #

Returns the ""OutMcastOctets"" field of the IpExt field in net/netstat.


[View source]
def out_mcast_pkts : Int64 #

Returns the ""OutMcastPkts"" field of the IpExt field in net/netstat.


[View source]
def out_octets : Int64 #

Returns the ""OutOctets"" field of the IpExt field in net/netstat.


[View source]
def pid : Int32? #

[View source]
def tcp_ext : Hash(String, Int64) #

[View source]