class Vnstat::Interface

A class encapsulating traffic information for a specific network interface.

@!attribute [r] id

@return [String] The network interface identifier.

Attributes

id[R]

Public Class Methods

load_data(id) click to toggle source

Retrieves the raw XML data for the given interface identifier.

@param [String] id The network interface identifier. @return [String]

# File lib/vnstat/interface.rb, line 27
def self.load_data(id)
  Utils.call_executable('-i', id, '--xml')
end
new(id, data) click to toggle source

Initializes the {Interface}.

@param [String] id The network interface identifier. @param [String] data The raw XML data.

Calls superclass method Vnstat::Document::new
# File lib/vnstat/interface.rb, line 17
def initialize(id, data)
  super(data)
  @id = id
end

Public Instance Methods

==(other) click to toggle source

Determines whether the interface is the same as another.

@param [Interface] other The compared object. @return [true, false]

# File lib/vnstat/interface.rb, line 36
def ==(other)
  return false unless other.respond_to?(:id)

  id == other.id
end
created_on() click to toggle source

The date on which tracking of the interface began. @return [Date]

# File lib/vnstat/interface.rb, line 104
def created_on
  Parser.extract_date_from_xml_element(interface_data.xpath('created'))
end
days() click to toggle source

Returns information about the daily traffic.

@return [Traffic::Daily]

# File lib/vnstat/interface.rb, line 137
def days
  @days ||= Traffic::Daily.new(self)
end
delete() click to toggle source

Deletes the traffic database for the interface.

@return [true, false]

# File lib/vnstat/interface.rb, line 56
def delete
  Utils.call_executable_returning_status('--delete', '-i', id)
end
hours() click to toggle source

Returns information about the hourly traffic.

@return [Traffic::Hourly]

# File lib/vnstat/interface.rb, line 129
def hours
  @hours ||= Traffic::Hourly.new(self)
end
inspect() click to toggle source

A human readable representation of the {Interface}.

@return [String]

# File lib/vnstat/interface.rb, line 161
def inspect
  "#<#{self.class.name} id: #{id.inspect}>"
end
months() click to toggle source

Returns information about the monthly traffic.

@return [Traffic::Monthly]

# File lib/vnstat/interface.rb, line 145
def months
  @months ||= Traffic::Monthly.new(self)
end
name()
Alias for: nick
name=(nick)
Alias for: nick=
nick() click to toggle source

Returns the alias name for the interface.

@return [String]

# File lib/vnstat/interface.rb, line 76
def nick
  @nick ||= interface_data.xpath('nick').text
end
Also aliased as: name
nick=(nick) click to toggle source

Sets the alias name for the interface.

@raise [Error] Raised when a new nickname could not be set. @param [String] nick The alias name for the interface.

# File lib/vnstat/interface.rb, line 85
def nick=(nick)
  success = Utils.call_executable_returning_status(
    '-i', id, '--nick', nick, '--update'
  )
  unless success
    raise Error, "Unable to set nickname for interface (#{id}). " \
                'Please make sure the vnstat daemon is not running while ' \
                'performing this operation.'
  end
  @nick = nick
end
Also aliased as: name=
reload() click to toggle source

Refreshes data cached in the current instance.

@return [Interface]

# File lib/vnstat/interface.rb, line 46
def reload
  self.data = self.class.load_data(id)
  @nick = nil
  self
end
reset() click to toggle source

Reset the internal counters in the database for the selected interface. Use this if the interface goes down and back up, otherwise that interface will get some extra traffic to its database. Not needed when the daemon is used.

@return [Interface]

# File lib/vnstat/interface.rb, line 67
def reset
  reload if Utils.call_executable_returning_status('--reset', '-i', id)
  self
end
tops() click to toggle source

Returns information about the traffic tops.

@return [Traffic::Tops]

# File lib/vnstat/interface.rb, line 153
def tops
  @tops ||= Traffic::Tops.new(self)
end
total() click to toggle source

Returns information about the total traffic.

@return [Result]

# File lib/vnstat/interface.rb, line 121
def total
  Result.extract_from_xml_element(interface_data.xpath('traffic/total'))
end
updated_at() click to toggle source

The date and time on which the tracking information for the interface were updated.

@return [DateTime]

# File lib/vnstat/interface.rb, line 113
def updated_at
  Parser.extract_datetime_from_xml_element(interface_data.xpath('updated'))
end

Private Instance Methods

interface_data() click to toggle source
# File lib/vnstat/interface.rb, line 167
def interface_data
  data.xpath("//interface[@id='#{id}']")
end