summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-03-13 11:07:59 -0700
committerGitHub <noreply@github.com>2020-03-13 11:07:59 -0700
commitd0741ac399dd5a6fae9d630ae193b9eadf3db2f8 (patch)
treed5d2a9b20ef5004bd9fe36b55e160d91cd312fb9
parentc19ec6e4977601111827301138c8d1f707abfb2c (diff)
parentfe2d2efde3d0e4699809e5e833195b0f8dbce3a4 (diff)
downloadohai-d0741ac399dd5a6fae9d630ae193b9eadf3db2f8.tar.gz
Merge pull request #1439 from matt-c-clark/matt-c-clark-NIC-info
Expose NIC channel params, coalesce params, and driver info...
-rw-r--r--lib/ohai/plugins/linux/network.rb90
-rw-r--r--spec/unit/plugins/linux/network_spec.rb113
2 files changed, 203 insertions, 0 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 62f5dfd6..e92c149a 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -207,6 +207,93 @@ Ohai.plugin(:Network) do
iface
end
+ # determine channel parameters for the interface using ethtool
+ def ethernet_channel_parameters(iface)
+ return iface unless ethtool_binary_path
+
+ iface.each_key do |tmp_int|
+ next unless iface[tmp_int][:encapsulation] == "Ethernet"
+
+ so = shell_out("#{ethtool_binary_path} -l #{tmp_int}")
+ logger.trace("Plugin Network: Parsing ethtool output: #{so.stdout}")
+ type = nil
+ iface[tmp_int]["channel_params"] = {}
+ so.stdout.lines.each do |line|
+ next if line.start_with?("Channel 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
+ channel_key = "#{type}_#{key.downcase.tr(" ", "_")}"
+ iface[tmp_int]["channel_params"][channel_key] = val.to_i
+ end
+ end
+ end
+ iface
+ end
+
+ # determine coalesce parameters for the interface using ethtool
+ def ethernet_coalesce_parameters(iface)
+ return iface unless ethtool_binary_path
+
+ iface.each_key do |tmp_int|
+ next unless iface[tmp_int][:encapsulation] == "Ethernet"
+
+ so = shell_out("#{ethtool_binary_path} -c #{tmp_int}")
+ logger.trace("Plugin Network: Parsing ethtool output: #{so.stdout}")
+ iface[tmp_int]["coalesce_params"] = {}
+ so.stdout.lines.each do |line|
+ next if line.start_with?("Coalesce parameters for")
+ next if line.strip.nil?
+
+ if line.start_with?("Adaptive")
+ _, adaptive_rx, _, adaptive_tx = line.split(/:\s+|\s+TX|\n/)
+ iface[tmp_int]["coalesce_params"]["adaptive_rx"] = adaptive_rx
+ iface[tmp_int]["coalesce_params"]["adaptive_tx"] = adaptive_tx
+ next
+ end
+ key, val = line.split(/:\s+/)
+ if val
+ coalesce_key = "#{key.downcase.tr(" ", "_")}"
+ iface[tmp_int]["coalesce_params"][coalesce_key] = val.to_i
+ end
+ end
+ end
+ iface
+ end
+
+ # determine driver info for the interface using ethtool
+ def ethernet_driver_info(iface)
+ return iface unless ethtool_binary_path
+
+ iface.each_key do |tmp_int|
+ next unless iface[tmp_int][:encapsulation] == "Ethernet"
+
+ so = shell_out("#{ethtool_binary_path} -i #{tmp_int}")
+ logger.trace("Plugin Network: Parsing ethtool output: #{so.stdout}")
+ iface[tmp_int]["driver_info"] = {}
+ so.stdout.lines.each do |line|
+ next if line.strip.nil?
+
+ key, val = line.split(/:\s+/)
+ if val.nil?
+ val = ""
+ end
+ driver_key = "#{key.downcase.tr(" ", "_")}"
+ iface[tmp_int]["driver_info"][driver_key] = val.chomp
+ 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")
@@ -669,6 +756,9 @@ Ohai.plugin(:Network) do
iface = ethernet_layer_one(iface)
iface = ethernet_ring_parameters(iface)
+ iface = ethernet_channel_parameters(iface)
+ iface = ethernet_coalesce_parameters(iface)
+ iface = ethernet_driver_info(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 38877783..4e6974e4 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -371,6 +371,71 @@ describe Ohai::System, "Linux Network Plugin" do
EOM
end
+ let(:linux_ethtool_l) do
+ <<~EOM
+ Channel parameters for eth0:
+ Pre-set maximums:
+ RX: 16
+ TX: 16
+ Other: 0
+ Combined: 32
+ Current hardware settings:
+ RX: 0
+ TX: 0
+ Other: 0
+ Combined: 16
+
+ EOM
+ end
+
+ let(:linux_ethtool_c) do
+ <<~EOM
+ Coalesce parameters for eth0:
+ Adaptive RX: on TX: off
+ stats-block-usecs: 0
+ sample-interval: 0
+ pkt-rate-low: 0
+ pkt-rate-high: 0
+
+ rx-usecs: 33
+ rx-frames: 88
+ rx-usecs-irq: 0
+ rx-frames-irq: 0
+
+ tx-usecs: 8
+ tx-frames: 128
+ tx-usecs-irq: 0
+ tx-frames-irq: 0
+
+ rx-usecs-low: 0
+ rx-frame-low: 0
+ tx-usecs-low: 0
+ tx-frame-low: 0
+
+ rx-usecs-high: 0
+ rx-frame-high: 0
+ tx-usecs-high: 0
+ tx-frame-high: 0
+
+ EOM
+ end
+
+ let(:linux_ethtool_i) do
+ <<~EOM
+ driver: mlx5_core
+ version: 5.0-0
+ firmware-version: 14.23.8012
+ expansion-rom-version:
+ bus-info: 0000:02:00.0
+ supports-statistics: yes
+ supports-test: yes
+ supports-eeprom-access: no
+ supports-register-dump: no
+ supports-priv-flags: yes
+
+ EOM
+ end
+
before do
allow(plugin).to receive(:collect_os).and_return(:linux)
@@ -385,6 +450,9 @@ describe Ohai::System, "Linux Network Plugin" do
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 -g/).and_return(mock_shell_out(0, linux_ethtool_g, ""))
+ allow(plugin).to receive(:shell_out).with(/ethtool -l/).and_return(mock_shell_out(0, linux_ethtool_l, ""))
+ allow(plugin).to receive(:shell_out).with(/ethtool -c/).and_return(mock_shell_out(0, linux_ethtool_c, ""))
+ allow(plugin).to receive(:shell_out).with(/ethtool -i/).and_return(mock_shell_out(0, linux_ethtool_i, ""))
allow(plugin).to receive(:shell_out).with(/ethtool [^\-]/).and_return(mock_shell_out(0, linux_ethtool, ""))
end
@@ -575,6 +643,51 @@ describe Ohai::System, "Linux Network Plugin" do
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)
+ expect(plugin["network"]["interfaces"]["eth0"]["channel_params"]["max_tx"]).to eq(16)
+ expect(plugin["network"]["interfaces"]["eth0"]["channel_params"]["max_rx"]).to eq(16)
+ expect(plugin["network"]["interfaces"]["eth0"]["channel_params"]["max_other"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["channel_params"]["max_combined"]).to eq(32)
+ expect(plugin["network"]["interfaces"]["eth0"]["channel_params"]["current_tx"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["channel_params"]["current_rx"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["channel_params"]["current_other"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["channel_params"]["current_combined"]).to eq(16)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["adaptive_rx"]).to eq("on")
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["adaptive_tx"]).to eq("off")
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["stats-block-usecs"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["sample-interval"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["pkt-rate-low"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["pkt-rate-high"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["rx-usecs"]).to eq(33)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["rx-frames"]).to eq(88)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["rx-usecs-irq"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["rx-frames-irq"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["tx-usecs"]).to eq(8)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["tx-frames"]).to eq(128)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["tx-usecs-irq"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["tx-frames-irq"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["rx-usecs-low"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["rx-frame-low"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["tx-usecs-low"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["tx-frame-low"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["rx-usecs-high"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["rx-frame-high"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["tx-usecs-high"]).to eq(0)
+ expect(plugin["network"]["interfaces"]["eth0"]["coalesce_params"]["tx-frame-high"]).to eq(0)
+
+ end
+
+ it "detects the driver info of an ethernet interface" do
+ expect(plugin["network"]["interfaces"]["eth0"]["driver_info"]["driver"]).to eq("mlx5_core")
+ expect(plugin["network"]["interfaces"]["eth0"]["driver_info"]["version"]).to eq("5.0-0")
+ expect(plugin["network"]["interfaces"]["eth0"]["driver_info"]["firmware-version"]).to eq("14.23.8012")
+ expect(plugin["network"]["interfaces"]["eth0"]["driver_info"]["expansion-rom-version"]).to eq("")
+ expect(plugin["network"]["interfaces"]["eth0"]["driver_info"]["bus-info"]).to eq("0000:02:00.0")
+ expect(plugin["network"]["interfaces"]["eth0"]["driver_info"]["supports-statistics"]).to eq("yes")
+ expect(plugin["network"]["interfaces"]["eth0"]["driver_info"]["supports-test"]).to eq("yes")
+ expect(plugin["network"]["interfaces"]["eth0"]["driver_info"]["supports-eeprom-access"]).to eq("no")
+ expect(plugin["network"]["interfaces"]["eth0"]["driver_info"]["supports-register-dump"]).to eq("no")
+ expect(plugin["network"]["interfaces"]["eth0"]["driver_info"]["supports-priv-flags"]).to eq("yes")
+
end
it "detects the ipv4 addresses of the ethernet interface" do