class Vnstat::Interface
A class encapsulating traffic information for a specific network interface.
@!attribute [r] id
@return [String] The network interface identifier.
Attributes
Public Class Methods
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
Initializes the {Interface}.
@param [String] id The network interface identifier. @param [String] data The raw XML data.
Vnstat::Document::new
# File lib/vnstat/interface.rb, line 17 def initialize(id, data) super(data) @id = id end
Public Instance Methods
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
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
Returns information about the daily traffic.
@return [Traffic::Daily]
# File lib/vnstat/interface.rb, line 137 def days @days ||= Traffic::Daily.new(self) end
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
Returns information about the hourly traffic.
@return [Traffic::Hourly]
# File lib/vnstat/interface.rb, line 129 def hours @hours ||= Traffic::Hourly.new(self) end
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
Returns information about the monthly traffic.
@return [Traffic::Monthly]
# File lib/vnstat/interface.rb, line 145 def months @months ||= Traffic::Monthly.new(self) end
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
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
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 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
Returns information about the traffic tops.
@return [Traffic::Tops]
# File lib/vnstat/interface.rb, line 153 def tops @tops ||= Traffic::Tops.new(self) end
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
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
# File lib/vnstat/interface.rb, line 167 def interface_data data.xpath("//interface[@id='#{id}']") end