Linux simple network diagnostics Recipe

  1. Create diag_network.sh
    #!/bin/sh
    OUTPUTFILE="diag_network_$(hostname)_$(date +"%Y%m%d_%H%M%S").log"
    INTERVAL="${1:-300}" # First argument or a default of 300 seconds (5 minutes)
    while true; do
      echo "diag: $(date +"%Y%m%d %H%M%S %N %Z") iteration" >> "${OUTPUTFILE}" 2>&1
      netstat -s >> "${OUTPUTFILE}" 2>&1
      netstat -i >> "${OUTPUTFILE}" 2>&1
      netstat -antop >> "${OUTPUTFILE}" 2>&1
      cat /proc/net/dev /proc/net/snmp* /proc/net/netstat /proc/net/tcp* /proc/net/udp* /proc/net/if_inet6 /proc/loadavg /sys/fs/cgroup/cpu.stat /sys/fs/cgroup/cpu/*/*/cpu.stat >> "${OUTPUTFILE}" 2>&1
      vmstat -twn 1 4 >> "${OUTPUTFILE}" 2>&1
      ip -color=never address >> "${OUTPUTFILE}" 2>&1
      ip -color=never route show >> "${OUTPUTFILE}" 2>&1
      ip -color=never -s link >> "${OUTPUTFILE}" 2>&1
      ulimit -a >> "${OUTPUTFILE}" 2>&1
      ss -amponetOi >> "${OUTPUTFILE}" 2>&1
      sleep ${INTERVAL}
    done
  2. Make it executable:
    chmod +x diag_network.sh
  3. Start it (default interval of 300 seconds or specify an alternate interval as the first argument):
    nohup ./diag_network.sh &
  4. Reproduce the problem
    1. If at any point you need to reduce this disk usage of the output file during the test, truncate the file:
      cat /dev/null > diag_network*log
  5. Stop the script:
    pkill -f diag_network
  6. Upload diag_network_* and nohup.out