-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ethtool monitoring support to Flent
This commit adds ethtool monitoring to Flent. The "common.inc" file includes this capability in most Flent tests. The ethtool support adds three new test parameters: "ethtool_hosts", "ethtool_devices", and "ethtool_fields". Behind the scenes, Flent runs the "ethtool -S <nic> command on all devices that support it via SSH. A breakdown of these new parameters is as follows: - ethtool_hosts: Specifies the hosts to monitor ethtool fields. The hosts are specified using a comma-separated list. - ethtool_devices: This parameter specifies which network devices to monitor instead of all of them. This parameter is also a comma-separated list. - ethtool_fields: This parameter defines a comma-separated list of fields to monitor. If this field is not set, it will default to monitor the "rx_packets" and "tx_packets" fields. The fields can also be prefixed with the network card if you only want to see that field for that particular device. Example: ethtool_devices=eth0,eth1 ethtool_fields=tx_packets_phy,rx_packets_phy,eth2:rx_bytes In this example, the fields "tx_packets_phy" and "rx_packets_phy" will be monitored on eth0 and eth1; however, only field rx_bytes will be monitored on eth2. One limitation of this version of the ethtool capability is that all hosts will share the same values of devices and fields. Signed-off-by: Frey Alfredsson <[email protected]>
- Loading branch information
1 parent
6c8dce5
commit 2aef3c8
Showing
7 changed files
with
333 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: GPL-3.0 | ||
# SPDX-FileContributor: Freysteinn Alfredsson <[email protected]> | ||
# SPDX-FileType: SOURCE | ||
|
||
count=10 | ||
interval=0.1 | ||
host=localhost | ||
|
||
while getopts "c:I:H:d:f:" opt; do | ||
case $opt in | ||
c) count=$OPTARG ;; | ||
I) interval=$OPTARG ;; | ||
H) host=$OPTARG ;; | ||
d) devices=$OPTARG ;; | ||
f) fields=$OPTARG ;; | ||
esac | ||
done | ||
|
||
command_string=$(cat <<EOF | ||
awk -v COUNT="$count" \ | ||
-v INTERVAL="$interval" \ | ||
-v DEVICES="$devices" \ | ||
-v FIELDS="$fields" ' \ | ||
function add_device(device) | ||
{ | ||
ethtool_cmd = ETHTOOL_CMD_TEMPLATE " " device; | ||
for (device_id in devices) | ||
if (device == devices[device_id]) | ||
return; | ||
if (((ethtool_cmd) | getline) > 0) | ||
devices[device_id_count++] = device; | ||
close(ethtool_cmd); | ||
} | ||
function add_field(device, field) | ||
{ | ||
if (entries[device, field] != 1) | ||
device_entry_count[device]++; | ||
entries[device, field] = 1; | ||
for (field_id in fields) | ||
if (field == fields[field_id]) | ||
return; | ||
fields[field_id_count++] = field; | ||
} | ||
# Startup | ||
BEGIN { | ||
ETHTOOL_CMD_TEMPLATE = "ethtool -S " | ||
DEVICE_LIST_CMD = "ls /sys/class/net"; | ||
device_id_count = 0; | ||
field_id_count = 0; | ||
# Set default fields if not specified | ||
if (FIELDS == "") { | ||
FIELDS = "rx_packets,tx_packets"; | ||
} | ||
split(DEVICES, device_args, ","); | ||
split(FIELDS, field_params, ","); | ||
# Get devices | ||
while (((DEVICE_LIST_CMD) | getline) > 0) { | ||
if (\$1 == "lo") | ||
continue; | ||
# Only add devices specified in DEVICES | ||
if (DEVICES != "") { | ||
for (device_arg_id in device_args) { | ||
if (\$1 == device_args[device_arg_id]) | ||
add_device(\$1); | ||
} | ||
} else { | ||
# Add all devices if DEVICES is not specified | ||
add_device(\$1); | ||
} | ||
} | ||
close(DEVICE_LIST_CMD); | ||
# Get fields | ||
for (field_param_id in field_params) { | ||
field_count = 0; | ||
split(field_params[field_param_id], field_pair, ":"); | ||
for (pair_id in field_pair) | ||
field_count++; | ||
field = field_pair[field_count]; | ||
# Add device specific fields | ||
if (field_count == 2) { | ||
device = field_pair[1]; | ||
add_device(device); | ||
add_field(device, field); | ||
continue | ||
} | ||
# Add global fields to all devices | ||
for (device_id in devices) { | ||
device = devices[device_id]; | ||
add_field(device, field); | ||
} | ||
} | ||
} | ||
function update_ethtool_stat(device) | ||
{ | ||
FS = ":"; | ||
ethtool_cmd = ETHTOOL_CMD_TEMPLATE " " device; | ||
found_fields = 0; | ||
while (((ethtool_cmd) | getline) > 0) { | ||
for (field_id in fields) { | ||
field = fields[field_id]; | ||
field_regexp = "^ *" field "\$"; | ||
if (\$1 !~ field_regexp) | ||
continue; | ||
value = \$2; | ||
entry_value_prev[device, field] = entry_value[device, field]; | ||
entry_value[device, field] = value; | ||
found_fields++; | ||
if (found_fields == device_entry_count[device]) | ||
break; | ||
} | ||
} | ||
close(ethtool_cmd); | ||
} | ||
function print_values(device) | ||
{ | ||
for (field_id in fields) { | ||
field = fields[field_id]; | ||
if (entries[device, field] != 1) | ||
continue; | ||
value_prev = entry_value_prev[device, field]; | ||
value = entry_value[device, field]; | ||
result = value - value_prev; | ||
print(device ":" field ": " result); | ||
} | ||
} | ||
# Main loop | ||
BEGIN { | ||
DATE_CMD = "date \"+Time: %s.%N\"" | ||
# Update initial values | ||
for (device_id in devices) { | ||
device = devices[device_id]; | ||
update_ethtool_stat(device); | ||
} | ||
# Print interval values | ||
for (i = 0; i < COUNT; i++) { | ||
print("---"); | ||
(DATE_CMD) | getline date; | ||
print(date); | ||
close(DATE_CMD); | ||
for (device_id in devices) { | ||
device = devices[device_id]; | ||
update_ethtool_stat(device); | ||
print_values(device); | ||
} | ||
system("sleep " INTERVAL); | ||
} | ||
}' | ||
EOF | ||
) | ||
|
||
if [ "$host" == "localhost" ]; then | ||
eval "$command_string" | ||
else | ||
echo "$command_string" | ssh "$host" sh | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## -*- mode: python; coding: utf-8 -*- | ||
|
||
# Mixin include file to add cpu stats to a test | ||
|
||
|
||
ETHTOOL_HOSTS=get_test_parameter('ethtool_hosts', default=[], split=True) | ||
ETHTOOL_DEVICES=get_test_parameter('ethtool_devices', default=None) | ||
ETHTOOL_FIELDS=get_test_parameter('ethtool_fields', default=None) | ||
|
||
for host in ETHTOOL_HOSTS: | ||
DATA_SETS['ethtool_stats_%s' % host] = {'interval': STEP_SIZE, | ||
'length': TOTAL_LENGTH, | ||
'host': host, | ||
'units': 'misc', | ||
'id': host, | ||
'devices': ETHTOOL_DEVICES, | ||
'fields': ETHTOOL_FIELDS, | ||
'runner': 'ethtool_stats'} | ||
|
||
if ETHTOOL_HOSTS: | ||
PLOTS['ethtool'] = {'description': 'Per ethtool field stats', | ||
'type': 'timeseries', | ||
'axis_labels': ['value'], | ||
'series': [ | ||
{'data': glob('ethtool_stats_*'), | ||
'raw_key': glob('*', exclude=["t"]), | ||
'label': 'Ethtool field stats'}, | ||
]} | ||
|
||
PLOTS['ethtool_box'] = {'description': 'Per ethtool stats (box plot)', | ||
'type': 'box', | ||
'parent': 'ethtool'} | ||
|
||
PLOTS['ethtool_bar'] = {'description': 'Per ethtool stats (bar plot)', | ||
'type': 'bar', | ||
'parent': 'ethtool'} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters