1
This commit is contained in:
572
scripts/bench.sh
572
scripts/bench.sh
@@ -2,7 +2,7 @@
|
||||
|
||||
#
|
||||
# Linux BenchTools - Client Benchmark Script
|
||||
# Version: 1.1.0
|
||||
# Version: 1.3.0
|
||||
#
|
||||
# Collecte les informations hardware, exécute les benchmarks
|
||||
# puis envoie les résultats au serveur backend (payload JSON).
|
||||
@@ -14,7 +14,7 @@ set -e
|
||||
# Version / variables globales
|
||||
#=========================================================
|
||||
|
||||
BENCH_SCRIPT_VERSION="1.2.0"
|
||||
BENCH_SCRIPT_VERSION="1.3.1"
|
||||
|
||||
# Couleurs
|
||||
GREEN='\033[0;32m'
|
||||
@@ -26,16 +26,16 @@ NC='\033[0m' # No Color
|
||||
TOTAL_STEPS=8
|
||||
CURRENT_STEP=0
|
||||
|
||||
# Paramètres réseau / API (fixés)
|
||||
SERVER_URL="10.0.1.97:8007" # ajouter le port ou le schéma dans send_benchmark_payload si besoin
|
||||
API_TOKEN="29855796dacf5cfe75ff9b02d6adf3dd0f9c52db5b53e7abfb4c0df7ece1be0a"
|
||||
IPERF_SERVER="10.0.1.97"
|
||||
# Paramètres réseau / API (peuvent être surchargés par variables d'environnement)
|
||||
SERVER_URL="${SERVER_URL:-10.0.1.97:8007}" # ajouter le port ou le schéma dans send_benchmark_payload si besoin
|
||||
API_TOKEN="${API_TOKEN:-29855796dacf5cfe75ff9b02d6adf3dd0f9c52db5b53e7abfb4c0df7ece1be0a}"
|
||||
IPERF_SERVER="${IPERF_SERVER:-10.0.1.97}"
|
||||
|
||||
# Mode DEBUG
|
||||
# Mettre à 1 pour afficher le payload JSON complet avant envoi
|
||||
# Mettre à 0 pour désactiver le debug
|
||||
DEBUG_PAYLOAD="${DEBUG_PAYLOAD:-1}" # Par défaut: 1 (activé)
|
||||
# Peut être désactivé via: DEBUG_PAYLOAD=0 bash bench.sh
|
||||
DEBUG_PAYLOAD="${DEBUG_PAYLOAD:-0}" # Par défaut: 0 (désactivé)
|
||||
# Peut être activé via: DEBUG_PAYLOAD=1 bash bench.sh
|
||||
|
||||
# Forcer locale en anglais pour parsing
|
||||
export LC_ALL=C
|
||||
@@ -50,9 +50,18 @@ RAM_INFO="null"
|
||||
GPU_INFO="null"
|
||||
MOTHERBOARD_INFO="null"
|
||||
STORAGE_INFO="[]"
|
||||
PARTITION_INFO="[]"
|
||||
NETWORK_INFO="[]"
|
||||
PCI_INFO="[]"
|
||||
USB_INFO="[]"
|
||||
NETWORK_SHARES_INFO="[]"
|
||||
BENCHMARK_RESULTS="null"
|
||||
|
||||
SMARTCTL_CMD="sudo smartctl"
|
||||
if command -v timeout &>/dev/null; then
|
||||
SMARTCTL_CMD="timeout 10s sudo smartctl"
|
||||
fi
|
||||
|
||||
#=========================================================
|
||||
# Affichage / logs
|
||||
#=========================================================
|
||||
@@ -190,6 +199,58 @@ safe_bc() {
|
||||
echo "$out"
|
||||
}
|
||||
|
||||
bytes_to_gb() {
|
||||
local bytes="$1"
|
||||
if [[ -z "$bytes" || "$bytes" == "0" ]]; then
|
||||
echo ""
|
||||
else
|
||||
safe_bc "scale=2; $bytes / (1024*1024*1024)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Detect the current graphical session type (wayland/x11/tty)
|
||||
detect_session_type() {
|
||||
local session_type="${XDG_SESSION_TYPE:-}"
|
||||
|
||||
if [[ -z "$session_type" && -n "$USER" && $(command -v loginctl) ]]; then
|
||||
local session_id
|
||||
session_id=$(loginctl 2>/dev/null | awk -v user="$USER" '$3==user {print $1; exit}')
|
||||
if [[ -n "$session_id" ]]; then
|
||||
session_type=$(loginctl show-session "$session_id" -p Type 2>/dev/null | awk -F= '/Type=/ {print $2}')
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$session_type" && -n "$WAYLAND_DISPLAY" ]]; then
|
||||
session_type="wayland"
|
||||
elif [[ -z "$session_type" && -n "$DISPLAY" ]]; then
|
||||
session_type="x11"
|
||||
fi
|
||||
|
||||
echo "$session_type"
|
||||
}
|
||||
|
||||
# Try to detect the primary screen resolution
|
||||
detect_screen_resolution() {
|
||||
local resolution=""
|
||||
|
||||
if command -v xrandr &>/dev/null && [[ -n "$DISPLAY" ]]; then
|
||||
resolution=$(xrandr --current 2>/dev/null | awk '/\*/ {print $1; exit}')
|
||||
fi
|
||||
|
||||
if [[ -z "$resolution" && -n "$DISPLAY" ]] && command -v xdpyinfo &>/dev/null; then
|
||||
resolution=$(xdpyinfo 2>/dev/null | awk '/dimensions:/ {print $2; exit}')
|
||||
fi
|
||||
|
||||
if [[ -z "$resolution" ]] && command -v swaymsg &>/dev/null; then
|
||||
resolution=$(swaymsg -t get_outputs 2>/dev/null | jq -r '
|
||||
[.[] | select(.active == true) | "\(.current_mode.width)x\(.current_mode.height)"] | .[0]'
|
||||
)
|
||||
[[ "$resolution" == "null" ]] && resolution=""
|
||||
fi
|
||||
|
||||
echo "$resolution"
|
||||
}
|
||||
|
||||
#=========================================================
|
||||
# Étape 1 : Système
|
||||
#=========================================================
|
||||
@@ -198,12 +259,48 @@ collect_system_info() {
|
||||
log_step "Collecte des informations système de base"
|
||||
|
||||
local hostname os_name os_version kernel arch
|
||||
local session_type screen_resolution last_boot uptime_seconds
|
||||
local battery_percentage="" battery_status="" battery_health=""
|
||||
|
||||
hostname=$(hostname)
|
||||
os_name=$(grep '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"')
|
||||
os_version=$(grep '^VERSION=' /etc/os-release | cut -d= -f2 | tr -d '"')
|
||||
kernel=$(uname -r)
|
||||
arch=$(uname -m)
|
||||
session_type=$(detect_session_type)
|
||||
screen_resolution=$(detect_screen_resolution)
|
||||
|
||||
if command -v who &>/dev/null; then
|
||||
last_boot=$(who -b 2>/dev/null | awk '{print $3 " " $4}')
|
||||
fi
|
||||
|
||||
if [[ -r /proc/uptime ]]; then
|
||||
uptime_seconds=$(awk '{print int($1)}' /proc/uptime)
|
||||
fi
|
||||
|
||||
for bat in /sys/class/power_supply/BAT*; do
|
||||
[[ -d "$bat" ]] || continue
|
||||
if [[ -f "$bat/present" ]]; then
|
||||
local present
|
||||
present=$(cat "$bat/present")
|
||||
[[ "$present" != "1" ]] && continue
|
||||
fi
|
||||
|
||||
if [[ -z "$battery_percentage" && -f "$bat/capacity" ]]; then
|
||||
battery_percentage=$(cat "$bat/capacity" | tr -dc '0-9.')
|
||||
fi
|
||||
if [[ -z "$battery_status" && -f "$bat/status" ]]; then
|
||||
battery_status=$(cat "$bat/status")
|
||||
fi
|
||||
if [[ -z "$battery_health" ]]; then
|
||||
if [[ -f "$bat/health" ]]; then
|
||||
battery_health=$(cat "$bat/health")
|
||||
elif [[ -f "$bat/uevent" ]]; then
|
||||
battery_health=$(grep -m1 'POWER_SUPPLY_HEALTH' "$bat/uevent" 2>/dev/null | cut -d= -f2)
|
||||
fi
|
||||
fi
|
||||
break
|
||||
done
|
||||
|
||||
SYSTEM_INFO=$(jq -n \
|
||||
--arg hostname "$hostname" \
|
||||
@@ -211,19 +308,40 @@ collect_system_info() {
|
||||
--arg os_version "$os_version" \
|
||||
--arg kernel "$kernel" \
|
||||
--arg arch "$arch" \
|
||||
--arg session "$session_type" \
|
||||
--arg resolution "$screen_resolution" \
|
||||
--arg last_boot "$last_boot" \
|
||||
--arg uptime "$uptime_seconds" \
|
||||
--arg battery_pct "$battery_percentage" \
|
||||
--arg battery_status "$battery_status" \
|
||||
--arg battery_health "$battery_health" \
|
||||
'{
|
||||
hostname: $hostname,
|
||||
os: {
|
||||
name: $os_name,
|
||||
version: $os_version,
|
||||
kernel_version: $kernel,
|
||||
architecture: $arch
|
||||
architecture: $arch,
|
||||
session_type: (if $session != "" then $session else null end),
|
||||
display_server: (if $session != "" then $session else null end),
|
||||
screen_resolution: (if $resolution != "" then $resolution else null end),
|
||||
last_boot_time: (if $last_boot != "" then $last_boot else null end),
|
||||
uptime_seconds: (if $uptime != "" then ($uptime | tonumber?) else null end),
|
||||
battery_percentage: (if $battery_pct != "" then ($battery_pct | tonumber?) else null end),
|
||||
battery_status: (if $battery_status != "" then $battery_status else null end),
|
||||
battery_health: (if $battery_health != "" then $battery_health else null end)
|
||||
}
|
||||
}')
|
||||
|
||||
log_info "Hostname: $hostname"
|
||||
log_info "OS: $os_name $os_version"
|
||||
log_info "Kernel: $kernel"
|
||||
[[ -n "$session_type" ]] && log_info "Session: $session_type"
|
||||
[[ -n "$screen_resolution" ]] && log_info "Résolution écran: $screen_resolution"
|
||||
[[ -n "$last_boot" ]] && log_info "Dernier boot: $last_boot"
|
||||
if [[ -n "$battery_percentage" ]]; then
|
||||
log_info "Batterie: ${battery_percentage}% ${battery_status:+($battery_status)}"
|
||||
fi
|
||||
echo ""
|
||||
}
|
||||
|
||||
@@ -442,13 +560,23 @@ collect_hardware_info() {
|
||||
# Essayer d'obtenir plus d'infos avec nvidia-smi
|
||||
if command -v nvidia-smi &>/dev/null; then
|
||||
local nvidia_model nvidia_vram nvidia_driver
|
||||
nvidia_model=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -1)
|
||||
nvidia_vram=$(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits 2>/dev/null | head -1)
|
||||
nvidia_driver=$(nvidia-smi --query-gpu=driver_version --format=csv,noheader 2>/dev/null | head -1)
|
||||
# Vérifier que nvidia-smi fonctionne avant d'extraire les infos
|
||||
if nvidia-smi &>/dev/null; then
|
||||
nvidia_model=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -1 | tr -d '\n')
|
||||
nvidia_vram=$(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits 2>/dev/null | head -1 | tr -d '\n')
|
||||
nvidia_driver=$(nvidia-smi --query-gpu=driver_version --format=csv,noheader 2>/dev/null | head -1 | tr -d '\n')
|
||||
|
||||
[[ -n "$nvidia_model" ]] && gpu_model="$nvidia_model"
|
||||
[[ -n "$nvidia_vram" ]] && gpu_vram="$nvidia_vram"
|
||||
[[ -n "$nvidia_driver" ]] && gpu_driver="$nvidia_driver"
|
||||
# Ne remplacer que si les valeurs sont non-vides et valides
|
||||
if [[ -n "$nvidia_model" && ! "$nvidia_model" =~ (failed|error|Error) ]]; then
|
||||
gpu_model="$nvidia_model"
|
||||
fi
|
||||
if [[ -n "$nvidia_vram" && "$nvidia_vram" =~ ^[0-9]+$ ]]; then
|
||||
gpu_vram="$nvidia_vram"
|
||||
fi
|
||||
if [[ -n "$nvidia_driver" && ! "$nvidia_driver" =~ (failed|error|Error) ]]; then
|
||||
gpu_driver="$nvidia_driver"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
elif echo "$gpu_line" | grep -qi 'amd'; then
|
||||
gpu_vendor="AMD"
|
||||
@@ -510,6 +638,79 @@ collect_hardware_info() {
|
||||
log_info "Motherboard: $mb_manufacturer $mb_model"
|
||||
log_info "BIOS: $bios_version ($bios_date)"
|
||||
echo ""
|
||||
|
||||
collect_pci_devices
|
||||
collect_usb_devices
|
||||
}
|
||||
|
||||
collect_pci_devices() {
|
||||
PCI_INFO="[]"
|
||||
|
||||
if ! command -v lspci &>/dev/null; then
|
||||
log_warn "lspci non disponible - périphériques PCI ignorés"
|
||||
return
|
||||
fi
|
||||
|
||||
local count=0
|
||||
while IFS= read -r line; do
|
||||
[[ -z "$line" ]] && continue
|
||||
|
||||
local slot class vendor device
|
||||
slot=$(echo "$line" | awk '{print $1}')
|
||||
class=$(echo "$line" | cut -d'"' -f2)
|
||||
vendor=$(echo "$line" | cut -d'"' -f4)
|
||||
device=$(echo "$line" | cut -d'"' -f6)
|
||||
|
||||
[[ -z "$slot" ]] && continue
|
||||
|
||||
local entry
|
||||
entry=$(jq -n \
|
||||
--arg slot "$slot" \
|
||||
--arg class "$class" \
|
||||
--arg vendor "$vendor" \
|
||||
--arg device "$device" \
|
||||
'{slot: $slot, class: $class, vendor: $vendor, device: $device}')
|
||||
|
||||
PCI_INFO=$(echo "$PCI_INFO" | jq --argjson e "$entry" '. + [$e]')
|
||||
count=$((count + 1))
|
||||
done < <(lspci -mm 2>/dev/null || true)
|
||||
|
||||
log_info "Périphériques PCI détectés: $count"
|
||||
}
|
||||
|
||||
collect_usb_devices() {
|
||||
USB_INFO="[]"
|
||||
|
||||
if ! command -v lsusb &>/dev/null; then
|
||||
log_warn "lsusb non disponible - périphériques USB ignorés"
|
||||
return
|
||||
fi
|
||||
|
||||
local count=0
|
||||
while IFS= read -r line; do
|
||||
[[ -z "$line" ]] && continue
|
||||
if [[ "$line" =~ Bus[[:space:]]([0-9]+)[[:space:]]Device[[:space:]]([0-9]+):[[:space:]]ID[[:space:]]([0-9a-fA-F]+):([0-9a-fA-F]+)[[:space:]](.*)$ ]]; then
|
||||
local bus="${BASH_REMATCH[1]}"
|
||||
local dev="${BASH_REMATCH[2]}"
|
||||
local vendor_id="${BASH_REMATCH[3]}"
|
||||
local product_id="${BASH_REMATCH[4]}"
|
||||
local name="${BASH_REMATCH[5]}"
|
||||
|
||||
local entry
|
||||
entry=$(jq -n \
|
||||
--arg bus "$bus" \
|
||||
--arg device "$dev" \
|
||||
--arg vendor_id "$vendor_id" \
|
||||
--arg product_id "$product_id" \
|
||||
--arg name "$name" \
|
||||
'{bus: $bus, device: $device, vendor_id: $vendor_id, product_id: $product_id, name: $name}')
|
||||
|
||||
USB_INFO=$(echo "$USB_INFO" | jq --argjson e "$entry" '. + [$e]')
|
||||
count=$((count + 1))
|
||||
fi
|
||||
done < <(lsusb 2>/dev/null || true)
|
||||
|
||||
log_info "Périphériques USB détectés: $count"
|
||||
}
|
||||
|
||||
#=========================================================
|
||||
@@ -537,15 +738,16 @@ collect_storage_info() {
|
||||
|
||||
local model="Unknown" serial="Unknown" temperature="null" smart_health="null"
|
||||
if command -v smartctl &>/dev/null; then
|
||||
if sudo smartctl -i "/dev/$d" &>/dev/null; then
|
||||
log_info "→ SMART (/dev/$d): collecte en cours (timeout 10s)"
|
||||
if $SMARTCTL_CMD -i "/dev/$d" &>/dev/null; then
|
||||
local s
|
||||
s=$(sudo smartctl -i "/dev/$d" 2>/dev/null)
|
||||
s=$($SMARTCTL_CMD -i "/dev/$d" 2>/dev/null)
|
||||
model=$(echo "$s" | awk -F: '/Device Model|Model Number/ {gsub(/^[ \t]+/,"",$2); print $2}' | head -1)
|
||||
serial=$(echo "$s" | awk -F: '/Serial Number/ {gsub(/^[ \t]+/,"",$2); print $2}' | head -1)
|
||||
|
||||
# Essayer de récupérer la température et le statut SMART
|
||||
local smart_all
|
||||
smart_all=$(sudo smartctl -A "/dev/$d" 2>/dev/null || true)
|
||||
smart_all=$($SMARTCTL_CMD -A "/dev/$d" 2>/dev/null || true)
|
||||
# Température (diverses variantes selon le type de disque)
|
||||
# SATA/HDD: Temperature_Celsius, Airflow_Temperature_Cel, Current Drive Temperature
|
||||
# RAW_VALUE est après le "-" (colonne 8 dans la plupart des cas, mais peut varier)
|
||||
@@ -557,7 +759,7 @@ collect_storage_info() {
|
||||
|
||||
# Statut SMART health
|
||||
local health
|
||||
health=$(sudo smartctl -H "/dev/$d" 2>/dev/null | awk '/SMART overall-health|SMART Health Status/ {print $NF}' | head -1)
|
||||
health=$($SMARTCTL_CMD -H "/dev/$d" 2>/dev/null | awk '/SMART overall-health|SMART Health Status/ {print $NF}' | head -1)
|
||||
[[ -n "$health" ]] && smart_health="$health" || smart_health="null"
|
||||
fi
|
||||
fi
|
||||
@@ -595,9 +797,144 @@ collect_storage_info() {
|
||||
done
|
||||
|
||||
STORAGE_INFO="$storage_array"
|
||||
|
||||
local partitions_json="[]"
|
||||
if command -v lsblk &>/dev/null; then
|
||||
log_info "→ Récupération des partitions via lsblk"
|
||||
local lsblk_payload=""
|
||||
local lsblk_fields="NAME,TYPE,MOUNTPOINT,SIZE,FSTYPE,FSUSED,FSAVAIL"
|
||||
local lsblk_cmd="lsblk -b -J -o"
|
||||
|
||||
if command -v timeout &>/dev/null; then
|
||||
lsblk_cmd="timeout 10s lsblk -b -J -o"
|
||||
fi
|
||||
|
||||
if ! lsblk_payload=$(bash -c "$lsblk_cmd \"$lsblk_fields\" 2>/dev/null"); then
|
||||
log_warn "lsblk avec colonnes étendues indisponible, tentative en mode simplifié"
|
||||
lsblk_fields="NAME,TYPE,MOUNTPOINT,SIZE,FSTYPE"
|
||||
lsblk_payload=$(bash -c "$lsblk_cmd \"$lsblk_fields\" 2>/dev/null" || true)
|
||||
fi
|
||||
|
||||
if [[ -n "$lsblk_payload" ]]; then
|
||||
if ! partitions_json=$(echo "$lsblk_payload" | jq '
|
||||
def flatten(node):
|
||||
[node]
|
||||
+ ( (node.children // []) | map(flatten(.)) | add );
|
||||
(.blockdevices // [])
|
||||
| map(flatten(.))
|
||||
| add
|
||||
| map(select(.type == "part"))
|
||||
| map({
|
||||
name: (if .name then "/dev/" + .name else null end),
|
||||
mount_point: (if (.mountpoint // "") == "" then null else .mountpoint end),
|
||||
fs_type: (.fstype // null),
|
||||
total_gb: (if (.size? // null) then (((.size | tonumber) / (1024*1024*1024)) * 100 | round / 100) else null end),
|
||||
used_gb: (if (.fsused? // null) then (((.fsused | tonumber) / (1024*1024*1024)) * 100 | round / 100) else null end),
|
||||
free_gb: (if (.fsavail? // null) then (((.fsavail | tonumber) / (1024*1024*1024)) * 100 | round / 100) else null end)
|
||||
})
|
||||
' 2>/dev/null); then
|
||||
log_warn "Parsing JSON lsblk échoué"
|
||||
partitions_json="[]"
|
||||
fi
|
||||
[[ -z "$partitions_json" ]] && partitions_json="[]"
|
||||
else
|
||||
log_warn "Impossible d'obtenir la sortie lsblk (timeout ?)"
|
||||
fi
|
||||
fi
|
||||
|
||||
PARTITION_INFO="$partitions_json"
|
||||
if [[ "$partitions_json" != "[]" ]]; then
|
||||
local partition_count
|
||||
partition_count=$(echo "$partitions_json" | jq 'length')
|
||||
log_info "Partitions détectées: $partition_count"
|
||||
fi
|
||||
|
||||
collect_network_shares
|
||||
echo ""
|
||||
}
|
||||
|
||||
collect_network_shares() {
|
||||
NETWORK_SHARES_INFO="[]"
|
||||
|
||||
if [[ ! -r /proc/mounts ]]; then
|
||||
log_warn "Impossible de lire /proc/mounts - partages réseau ignorés"
|
||||
return
|
||||
fi
|
||||
|
||||
local count=0
|
||||
while read -r raw_src raw_target raw_type raw_opts _; do
|
||||
local fstype
|
||||
fstype=$(printf '%b' "$raw_type" | tr '[:upper:]' '[:lower:]')
|
||||
case "$fstype" in
|
||||
nfs|nfs4|cifs|smbfs|fuse.cifs|fuse.smbfs|afp|afpfs|fuse.afpfs|sshfs|fuse.sshfs|ftpfs|curlftpfs|fuse.ftpfs|davfs|davfs2|fuse.webdavfs)
|
||||
;;
|
||||
*)
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
local protocol="$fstype"
|
||||
case "$fstype" in
|
||||
cifs|smbfs|fuse.cifs|fuse.smbfs) protocol="smb" ;;
|
||||
nfs|nfs4) protocol="nfs" ;;
|
||||
afp|afpfs|fuse.afpfs) protocol="afp" ;;
|
||||
sshfs|fuse.sshfs) protocol="sshfs" ;;
|
||||
ftpfs|curlftpfs|fuse.ftpfs) protocol="ftp" ;;
|
||||
davfs|davfs2|fuse.webdavfs) protocol="webdav" ;;
|
||||
esac
|
||||
|
||||
local source target options
|
||||
source=$(printf '%b' "$raw_src")
|
||||
target=$(printf '%b' "$raw_target")
|
||||
options=$(printf '%b' "$raw_opts")
|
||||
|
||||
local total_gb="" used_gb="" free_gb=""
|
||||
if [[ -d "$target" ]]; then
|
||||
local df_line
|
||||
df_line=$(df -B1 "$target" 2>/dev/null | tail -1)
|
||||
if [[ -n "$df_line" ]]; then
|
||||
local total_bytes used_bytes free_bytes
|
||||
total_bytes=$(echo "$df_line" | awk '{print $2}')
|
||||
used_bytes=$(echo "$df_line" | awk '{print $3}')
|
||||
free_bytes=$(echo "$df_line" | awk '{print $4}')
|
||||
[[ -n "$total_bytes" ]] && total_gb=$(bytes_to_gb "$total_bytes")
|
||||
[[ -n "$used_bytes" ]] && used_gb=$(bytes_to_gb "$used_bytes")
|
||||
[[ -n "$free_bytes" ]] && free_gb=$(bytes_to_gb "$free_bytes")
|
||||
fi
|
||||
fi
|
||||
|
||||
local entry
|
||||
entry=$(jq -n \
|
||||
--arg protocol "$protocol" \
|
||||
--arg source "$source" \
|
||||
--arg mount "$target" \
|
||||
--arg fs "$fstype" \
|
||||
--arg opts "$options" \
|
||||
--arg total "${total_gb:-}" \
|
||||
--arg used "${used_gb:-}" \
|
||||
--arg free "${free_gb:-}" \
|
||||
'{
|
||||
protocol: ( $protocol | select(. != "") ),
|
||||
source: $source,
|
||||
mount_point: $mount,
|
||||
fs_type: $fs,
|
||||
options: ( $opts | select(. != "") ),
|
||||
total_gb: ( if $total == "" then null else ($total | tonumber?) end ),
|
||||
used_gb: ( if $used == "" then null else ($used | tonumber?) end ),
|
||||
free_gb: ( if $free == "" then null else ($free | tonumber?) end )
|
||||
}')
|
||||
|
||||
NETWORK_SHARES_INFO=$(echo "$NETWORK_SHARES_INFO" | jq --argjson e "$entry" '. + [$e]')
|
||||
count=$((count + 1))
|
||||
done < /proc/mounts
|
||||
|
||||
if (( count > 0 )); then
|
||||
log_info "Partages réseau détectés: $count"
|
||||
else
|
||||
log_info "Aucun partage réseau monté"
|
||||
fi
|
||||
}
|
||||
|
||||
#=========================================================
|
||||
# Étape 6 : Réseau
|
||||
#=========================================================
|
||||
@@ -625,7 +962,7 @@ collect_network_info() {
|
||||
local ip_addr
|
||||
ip_addr=$(ip -4 addr show "$iface" | awk '/inet /{print $2}' | cut -d/ -f1 | head -1)
|
||||
|
||||
local speed="" wol_supported=""
|
||||
local speed="" wol_supported="" driver="" ssid=""
|
||||
if [[ "$type" = "ethernet" && -x /usr/sbin/ethtool ]]; then
|
||||
local e
|
||||
e=$(sudo ethtool "$iface" 2>/dev/null || true)
|
||||
@@ -643,6 +980,39 @@ collect_network_info() {
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$type" = "wifi" ]] && command -v iw &>/dev/null; then
|
||||
local iw_info
|
||||
iw_info=$(iw dev "$iface" link 2>/dev/null || true)
|
||||
if echo "$iw_info" | grep -q "SSID"; then
|
||||
ssid=$(echo "$iw_info" | awk -F': ' '/SSID/ {print $2; exit}' | sed 's/[[:space:]]*$//')
|
||||
fi
|
||||
|
||||
local bitrate_line
|
||||
bitrate_line=$(echo "$iw_info" | awk -F': ' '/tx bitrate/ {print $2; exit}' | xargs)
|
||||
if [[ -n "$bitrate_line" ]]; then
|
||||
local br_value=$(echo "$bitrate_line" | awk '{print $1}')
|
||||
local br_unit=$(echo "$bitrate_line" | awk '{print $2}')
|
||||
if [[ "$br_value" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
|
||||
if [[ "$br_unit" =~ ^MBit/s$ ]]; then
|
||||
speed=$(printf "%.0f" "$br_value")
|
||||
elif [[ "$br_unit" =~ ^GBit/s$ ]]; then
|
||||
speed=$(awk "BEGIN {printf \"%.0f\", $br_value * 1000}")
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if command -v ethtool &>/dev/null; then
|
||||
local ethtool_info
|
||||
ethtool_info=$(sudo ethtool -i "$iface" 2>/dev/null || true)
|
||||
if [[ -n "$ethtool_info" ]]; then
|
||||
driver=$(echo "$ethtool_info" | awk -F: '/driver:/ {gsub(/^[ \t]+/,"",$2); print $2; exit}')
|
||||
fi
|
||||
fi
|
||||
if [[ -z "$driver" && -L "/sys/class/net/$iface/device/driver" ]]; then
|
||||
driver=$(basename "$(readlink -f "/sys/class/net/$iface/device/driver")" 2>/dev/null)
|
||||
fi
|
||||
|
||||
# Convertir wol_supported en booléen ou null pour jq
|
||||
local wol_json="null"
|
||||
if [[ "$wol_supported" == "true" ]]; then
|
||||
@@ -658,6 +1028,8 @@ collect_network_info() {
|
||||
--arg mac "$mac" \
|
||||
--arg ip "${ip_addr:-}" \
|
||||
--arg speed "$speed" \
|
||||
--arg driver "$driver" \
|
||||
--arg ssid "$ssid" \
|
||||
--argjson wol "$wol_json" \
|
||||
'{
|
||||
name: $name,
|
||||
@@ -665,6 +1037,8 @@ collect_network_info() {
|
||||
mac: $mac,
|
||||
ip_address: ( $ip | select(. != "") ),
|
||||
speed_mbps: ( ( $speed | tonumber? ) // null ),
|
||||
driver: ( $driver | select(. != "") ),
|
||||
ssid: ( $ssid | select(. != "") ),
|
||||
wake_on_lan: $wol
|
||||
}' 2>/dev/null || echo '{}')
|
||||
|
||||
@@ -675,7 +1049,14 @@ collect_network_info() {
|
||||
log_warn "Interface $iface: JSON invalide, ignorée"
|
||||
fi
|
||||
|
||||
log_info "Interface: $iface ($type) - IP: ${ip_addr:-N/A}"
|
||||
local log_line="Interface: $iface ($type) - IP: ${ip_addr:-N/A}"
|
||||
if [[ -n "$speed" ]]; then
|
||||
log_line+=" - Speed: ${speed}Mbps"
|
||||
fi
|
||||
if [[ "$type" = "wifi" && -n "$ssid" ]]; then
|
||||
log_line+=" - SSID: $ssid"
|
||||
fi
|
||||
log_info "$log_line"
|
||||
done
|
||||
|
||||
NETWORK_INFO="$network_array"
|
||||
@@ -693,27 +1074,54 @@ run_benchmarks() {
|
||||
local cpu_bench="null"
|
||||
if command -v sysbench &>/dev/null; then
|
||||
log_info "Benchmark CPU en cours..."
|
||||
local cpu_res
|
||||
cpu_res=$(sysbench cpu --cpu-max-prime=20000 --threads="$(nproc)" run 2>&1 || true)
|
||||
local eps time_s
|
||||
eps=$(echo "$cpu_res" | awk '/events per second/ {print $4}')
|
||||
time_s=$(echo "$cpu_res" | awk '/total time:/ {gsub(/s/,"",$3); print $3}')
|
||||
[[ -z "$eps" ]] && eps=0
|
||||
|
||||
# Test single-core (1 thread)
|
||||
log_info "→ Test single-core (1 thread)..."
|
||||
local cpu_single
|
||||
cpu_single=$(sysbench cpu --cpu-max-prime=20000 --threads=1 run 2>&1 || true)
|
||||
local eps_single
|
||||
eps_single=$(echo "$cpu_single" | awk '/events per second/ {print $4}')
|
||||
[[ -z "$eps_single" ]] && eps_single=0
|
||||
local cpu_score_single
|
||||
cpu_score_single=$(safe_bc "scale=2; $eps_single / 100")
|
||||
log_info " Single-core: ${eps_single} events/sec (score: ${cpu_score_single})"
|
||||
|
||||
# Test multi-core (tous les threads)
|
||||
log_info "→ Test multi-core ($(nproc) threads)..."
|
||||
local cpu_multi
|
||||
cpu_multi=$(sysbench cpu --cpu-max-prime=20000 --threads="$(nproc)" run 2>&1 || true)
|
||||
local eps_multi time_s
|
||||
eps_multi=$(echo "$cpu_multi" | awk '/events per second/ {print $4}')
|
||||
time_s=$(echo "$cpu_multi" | awk '/total time:/ {gsub(/s/,"",$3); print $3}')
|
||||
[[ -z "$eps_multi" ]] && eps_multi=0
|
||||
[[ -z "$time_s" ]] && time_s=0
|
||||
local cpu_score_multi
|
||||
cpu_score_multi=$(safe_bc "scale=2; $eps_multi / 100")
|
||||
log_info " Multi-core: ${eps_multi} events/sec (score: ${cpu_score_multi})"
|
||||
|
||||
# Score global = moyenne des deux
|
||||
local cpu_score
|
||||
cpu_score=$(safe_bc "scale=2; $eps / 100")
|
||||
cpu_score=$(safe_bc "scale=2; ($cpu_score_single + $cpu_score_multi) / 2")
|
||||
|
||||
cpu_bench=$(jq -n \
|
||||
--arg eps "$eps" \
|
||||
--arg eps "$eps_multi" \
|
||||
--arg eps_single "$eps_single" \
|
||||
--arg eps_multi "$eps_multi" \
|
||||
--arg time "$time_s" \
|
||||
--arg score "$cpu_score" \
|
||||
--arg score_single "$cpu_score_single" \
|
||||
--arg score_multi "$cpu_score_multi" \
|
||||
'{
|
||||
events_per_sec: ($eps | tonumber? // 0),
|
||||
events_per_sec_single: ($eps_single | tonumber? // 0),
|
||||
events_per_sec_multi: ($eps_multi | tonumber? // 0),
|
||||
duration_s: ($time | tonumber? // 0),
|
||||
score: ($score | tonumber? // 0)
|
||||
score: ($score | tonumber? // 0),
|
||||
score_single: ($score_single | tonumber? // 0),
|
||||
score_multi: ($score_multi | tonumber? // 0)
|
||||
}')
|
||||
|
||||
log_info "CPU: ${eps} events/sec (score: ${cpu_score})"
|
||||
log_info "CPU Global: score ${cpu_score} (single: ${cpu_score_single}, multi: ${cpu_score_multi})"
|
||||
else
|
||||
log_warn "sysbench non disponible - CPU bench ignoré"
|
||||
fi
|
||||
@@ -935,13 +1343,46 @@ run_benchmarks() {
|
||||
send_benchmark_payload() {
|
||||
log_step "Construction du payload JSON et envoi au serveur"
|
||||
|
||||
# Si SERVER_URL n’a pas de schéma, on préfixe par http://
|
||||
# Si SERVER_URL n'a pas de schéma, on préfixe par http://
|
||||
local base_url="$SERVER_URL"
|
||||
if [[ "$base_url" != http*://* ]]; then
|
||||
base_url="http://$base_url"
|
||||
fi
|
||||
local api_url="${base_url%/}/api/benchmark"
|
||||
|
||||
# Validation des variables JSON avant envoi (éviter les variables vides qui causent des erreurs jq)
|
||||
# Si DEBUG_PAYLOAD=1, on affiche les variables pour diagnostic
|
||||
if [[ "${DEBUG_PAYLOAD:-0}" == "1" ]]; then
|
||||
echo -e "${BLUE}════════════════════════════════════════════════════════${NC}"
|
||||
echo -e "${YELLOW}DEBUG: Validation des variables JSON${NC}"
|
||||
echo -e "${BLUE}════════════════════════════════════════════════════════${NC}"
|
||||
for var in SYSTEM_INFO CPU_INFO RAM_INFO GPU_INFO MOTHERBOARD_INFO STORAGE_INFO PARTITION_INFO NETWORK_INFO PCI_INFO USB_INFO NETWORK_SHARES_INFO BENCHMARK_RESULTS; do
|
||||
local val="${!var}"
|
||||
if [[ -z "$val" ]]; then
|
||||
echo -e "${RED}✗ $var est VIDE${NC}"
|
||||
elif echo "$val" | jq empty 2>/dev/null; then
|
||||
echo -e "${GREEN}✓ $var est JSON valide${NC} (${#val} chars)"
|
||||
else
|
||||
echo -e "${RED}✗ $var est JSON INVALIDE${NC}: ${val:0:100}..."
|
||||
fi
|
||||
done
|
||||
echo -e "${BLUE}════════════════════════════════════════════════════════${NC}"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
[[ -z "$SYSTEM_INFO" ]] && SYSTEM_INFO="null"
|
||||
[[ -z "$CPU_INFO" ]] && CPU_INFO="null"
|
||||
[[ -z "$RAM_INFO" ]] && RAM_INFO="null"
|
||||
[[ -z "$GPU_INFO" ]] && GPU_INFO="null"
|
||||
[[ -z "$MOTHERBOARD_INFO" ]] && MOTHERBOARD_INFO="null"
|
||||
[[ -z "$STORAGE_INFO" ]] && STORAGE_INFO="[]"
|
||||
[[ -z "$PARTITION_INFO" ]] && PARTITION_INFO="[]"
|
||||
[[ -z "$NETWORK_INFO" ]] && NETWORK_INFO="[]"
|
||||
[[ -z "$PCI_INFO" ]] && PCI_INFO="[]"
|
||||
[[ -z "$USB_INFO" ]] && USB_INFO="[]"
|
||||
[[ -z "$NETWORK_SHARES_INFO" ]] && NETWORK_SHARES_INFO="[]"
|
||||
[[ -z "$BENCHMARK_RESULTS" ]] && BENCHMARK_RESULTS="null"
|
||||
|
||||
local payload
|
||||
payload=$(
|
||||
jq -n \
|
||||
@@ -952,7 +1393,11 @@ send_benchmark_payload() {
|
||||
--argjson gpu "$GPU_INFO" \
|
||||
--argjson mb "$MOTHERBOARD_INFO" \
|
||||
--argjson storage "$STORAGE_INFO" \
|
||||
--argjson partitions "$PARTITION_INFO" \
|
||||
--argjson network "$NETWORK_INFO" \
|
||||
--argjson pci "$PCI_INFO" \
|
||||
--argjson usb "$USB_INFO" \
|
||||
--argjson shares "$NETWORK_SHARES_INFO" \
|
||||
--argjson bench "$BENCHMARK_RESULTS" \
|
||||
'
|
||||
{
|
||||
@@ -1025,9 +1470,13 @@ send_benchmark_payload() {
|
||||
temperature_c
|
||||
}
|
||||
],
|
||||
partitions: []
|
||||
partitions: $partitions
|
||||
},
|
||||
|
||||
pci_devices: $pci,
|
||||
usb_devices: $usb,
|
||||
network_shares: $shares,
|
||||
|
||||
network: {
|
||||
interfaces: [
|
||||
$network[]
|
||||
@@ -1037,7 +1486,8 @@ send_benchmark_payload() {
|
||||
mac,
|
||||
ip: .ip_address,
|
||||
speed_mbps,
|
||||
driver: null,
|
||||
driver: (.driver // null),
|
||||
ssid: (.ssid // null),
|
||||
wake_on_lan
|
||||
}
|
||||
]
|
||||
@@ -1053,7 +1503,11 @@ send_benchmark_payload() {
|
||||
|
||||
os: (
|
||||
$system.os
|
||||
+ { virtualization_type: "none" }
|
||||
+ {
|
||||
hostname: $system.hostname,
|
||||
virtualization_type: "none",
|
||||
desktop_environment: (.session_type // .display_server // null)
|
||||
}
|
||||
),
|
||||
|
||||
sensors: {
|
||||
@@ -1110,7 +1564,13 @@ send_benchmark_payload() {
|
||||
echo -e "${GREEN}✓${NC} Payload sauvegardé dans: ${debug_file}"
|
||||
echo ""
|
||||
|
||||
read -p "Appuyez sur Entrée pour continuer l'envoi ou Ctrl+C pour annuler..."
|
||||
# Demander confirmation seulement si on a un terminal interactif
|
||||
if [[ -t 0 ]]; then
|
||||
read -p "Appuyez sur Entrée pour continuer l'envoi ou Ctrl+C pour annuler..."
|
||||
else
|
||||
log_warn "Mode non-interactif détecté - envoi automatique dans 2 secondes..."
|
||||
sleep 2
|
||||
fi
|
||||
fi
|
||||
|
||||
log_info "Envoi du payload vers: $api_url"
|
||||
@@ -1144,7 +1604,47 @@ send_benchmark_payload() {
|
||||
# MAIN
|
||||
#=========================================================
|
||||
|
||||
parse_args() {
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--server)
|
||||
SERVER_URL="$2"
|
||||
shift 2
|
||||
;;
|
||||
--token)
|
||||
API_TOKEN="$2"
|
||||
shift 2
|
||||
;;
|
||||
--iperf-server)
|
||||
IPERF_SERVER="$2"
|
||||
shift 2
|
||||
;;
|
||||
--debug)
|
||||
DEBUG_PAYLOAD=1
|
||||
shift
|
||||
;;
|
||||
--help|-h)
|
||||
echo "Usage: $0 [OPTIONS]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --server URL Backend server URL (default: $SERVER_URL)"
|
||||
echo " --token TOKEN API authentication token"
|
||||
echo " --iperf-server IP iperf3 server IP (default: $IPERF_SERVER)"
|
||||
echo " --debug Enable debug mode (shows full JSON payload)"
|
||||
echo " --help, -h Show this help message"
|
||||
echo ""
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
log_warn "Option inconnue: $1 (ignorée)"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
parse_args "$@"
|
||||
check_sudo
|
||||
check_dependencies
|
||||
|
||||
|
||||
0
scripts/resultat_bench_aorus.md
Normal file → Executable file
0
scripts/resultat_bench_aorus.md
Normal file → Executable file
Reference in New Issue
Block a user