summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Cavalca <dcavalca@fb.com>2016-05-25 11:09:07 -0700
committerDavide Cavalca <dcavalca@fb.com>2016-05-25 11:09:07 -0700
commit700f03d212948c976933b5d93ecb1d996c144544 (patch)
treebce2d4c426b81108266017b47fbd5ca9f8cd36c1
parenteb75927881b10f1c60a26add31f6afe9f773330f (diff)
downloadohai-700f03d212948c976933b5d93ecb1d996c144544.tar.gz
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 18f6dd31..edf779f2 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}")
+ # Nasty, brittle regex to capture the ethtool output
+ nasty_regex =
+/Ring parameters for #{tmp_int}:
+Pre-set maximums:
+RX:\s+(\d+)
+.*
+TX:\s+(\d+)
+Current hardware settings:
+RX:\s+(\d+)
+.*
+TX:\s+(\d+)/m
+ if nasty_regex.match(so.stdout)
+ iface[tmp_int]["ring_params"] = {
+ "max_rx" => $1.to_i,
+ "max_tx" => $2.to_i,
+ "current_rx" => $3.to_i,
+ "current_tx" => $4.to_i,
+ }
+ 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")
@@ -593,6 +623,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 40bbdc17..ea948deb 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