#!/bin/bash

echo "=== KERNEL VERSION ==="
uname -r
echo ""

echo "=== SYSCTL NETWORK PARAMETERS ==="
sysctl net.core.somaxconn
sysctl net.core.netdev_max_backlog
sysctl net.ipv4.tcp_max_syn_backlog
sysctl net.ipv4.tcp_syncookies
sysctl net.ipv4.tcp_tw_reuse
sysctl net.ipv4.tcp_fin_timeout
sysctl net.ipv4.ip_local_port_range
sysctl net.ipv4.tcp_rmem
sysctl net.ipv4.tcp_wmem
sysctl net.core.rmem_max
sysctl net.core.wmem_max
echo ""

echo "=== LIMITES ulimit ==="
ulimit -n
ulimit -a
echo ""

echo "=== FILE-MAX (max descripteurs système) ==="
cat /proc/sys/fs/file-max
echo ""

echo "=== CONNEXIONS TCP ACTUELLES ==="
ss -s
echo ""

echo "=== STATS PAR ÉTAT TCP ==="
echo -n "TIME_WAIT : "; ss -n state time-wait | wc -l
echo -n "SYN_RECV  : "; ss -n state syn-recv | wc -l
echo -n "CLOSE_WAIT: "; ss -n state close-wait | wc -l
echo -n "ESTABLISHED: "; ss -n state established | wc -l
echo ""

echo "=== SOCKETS OUVERTES PAR xbt_tracker ==="
pid=$(pgrep xbt_tracker)
if [ -n "$pid" ]; then
  echo "PID de xbt_tracker : $pid"
  ls -l /proc/$pid/fd | wc -l
else
  echo "xbt_tracker non trouvé."
fi

echo ""
echo "=== FIN DU RAPPORT ==="

