summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Dibowitz <phil@ipom.com>2016-06-17 15:14:05 +0100
committerGitHub <noreply@github.com>2016-06-17 15:14:05 +0100
commitcd5324d7e421baed8de42b0bba2b7c9b27763941 (patch)
tree13edf010c75bfc4357217904331ebe9c40106b02
parentf5ddbd0873b1fee480b78fb6beaecf9a9b63bc7f (diff)
parent071c93fd821b35941990881dfd8360beb507c120 (diff)
downloadohai-cd5324d7e421baed8de42b0bba2b7c9b27763941.tar.gz
Merge pull request #827 from davide125/ethtool
expose ring parameters in the network plugin
-rw-r--r--lib/ohai/plugins/linux/network.rb31
-rw-r--r--spec/unit/plugins/linux/network_spec.rb23
2 files changed, 53 insertions, 1 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 65aa3d1a..dbe8cd18 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -171,6 +171,36 @@ Ohai.plugin(:Network) do
iface
end
+ # determine ring parameters for the interface using ethtool
+ def ethernet_ring_parameters(iface)
+ return iface unless ethtool_binary = find_ethtool_binary
+ iface.each_key do |tmp_int|
+ next unless iface[tmp_int][:encapsulation] == "Ethernet"
+ so = shell_out("#{ethtool_binary} -g #{tmp_int}")
+ Ohai::Log.debug("Parsing ethtool output: #{so.stdout}")
+ type = nil
+ iface[tmp_int]["ring_params"] = {}
+ so.stdout.lines.each do |line|
+ next if line.start_with?("Ring parameters for")
+ next if line.strip.nil?
+ if line =~ /Pre-set maximums/
+ type = "max"
+ next
+ end
+ if line =~ /Current hardware settings/
+ type = "current"
+ next
+ end
+ key, val = line.split(/:\s+/)
+ if type && val
+ ring_key = "#{type}_#{key.downcase.tr(' ', '_')}"
+ iface[tmp_int]["ring_params"][ring_key] = val.to_i
+ end
+ end
+ end
+ iface
+ end
+
# determine link stats, vlans, queue length, and state for an interface using ip
def link_statistics(iface, net_counters)
so = shell_out("ip -d -s link")
@@ -601,6 +631,7 @@ Ohai.plugin(:Network) do
end # end "ip else net-tools" block
iface = ethernet_layer_one(iface)
+ iface = ethernet_ring_parameters(iface)
counters[:network][:interfaces] = net_counters
network["interfaces"] = iface
end
diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb
index b91e8d0f..e2037fc3 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -339,6 +339,22 @@ Settings for eth0:
EOM
}
+ let(:linux_ethtool_g) { <<-EOM
+Ring parameters for eth0:
+Pre-set maximums:
+RX: 8192
+RX Mini: 0
+RX Jumbo: 0
+TX: 8192
+Current hardware settings:
+RX: 8192
+RX Mini: 0
+RX Jumbo: 0
+TX: 8192
+
+EOM
+ }
+
before(:each) do
allow(plugin).to receive(:collect_os).and_return(:linux)
@@ -352,7 +368,8 @@ EOM
allow(plugin).to receive(:shell_out).with("route -n").and_return(mock_shell_out(0, linux_route_n, ""))
allow(plugin).to receive(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, linux_ifconfig, ""))
allow(plugin).to receive(:shell_out).with("arp -an").and_return(mock_shell_out(0, linux_arp_an, ""))
- allow(plugin).to receive(:shell_out).with(/ethtool/).and_return(mock_shell_out(0, linux_ethtool, ""))
+ allow(plugin).to receive(:shell_out).with(/ethtool -g/).and_return(mock_shell_out(0, linux_ethtool_g, ""))
+ allow(plugin).to receive(:shell_out).with(/ethtool [^\-]/).and_return(mock_shell_out(0, linux_ethtool, ""))
end
describe "#iproute2_binary_available?" do
@@ -554,6 +571,10 @@ EOM
expect(plugin["network"]["interfaces"]["eth0"]["transceiver"]).to eq("external")
expect(plugin["network"]["interfaces"]["eth0"]["auto_negotiation"]).to eq("on")
expect(plugin["network"]["interfaces"]["eth0"]["mdi_x"]).to be_nil
+ expect(plugin["network"]["interfaces"]["eth0"]["ring_params"]["max_tx"]).to eq(8192)
+ expect(plugin["network"]["interfaces"]["eth0"]["ring_params"]["max_rx"]).to eq(8192)
+ expect(plugin["network"]["interfaces"]["eth0"]["ring_params"]["current_tx"]).to eq(8192)
+ expect(plugin["network"]["interfaces"]["eth0"]["ring_params"]["current_rx"]).to eq(8192)
end
it "detects the ipv4 addresses of the ethernet interface" do