struct

Hardware::Net

Inherits Struct / Value / Object

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

Constructors

new(pid : Int64 | Nil = nil)

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

Source

Instance methods

in_bcast_octets

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

Source
in_bcast_pkts

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

Source
in_ce_pkts

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

Source
in_csum_errors

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

Source
in_ect0_pkts

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

Source
in_ect1_pkts

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

Source
in_mcast_octets

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

Source
in_mcast_pkts

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

Source
in_no_ect_pkts

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

Source
in_no_routes

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

Source
in_octets

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

Source
in_truncated_pkts

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

Source
ip_ext
Source
out_bcast_octets

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

Source
out_bcast_pkts

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

Source
out_mcast_octets

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

Source
out_mcast_pkts

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

Source
out_octets

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

Source
tcp_ext
Source