-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_pool_ceph.sh
More file actions
171 lines (147 loc) · 6.32 KB
/
Copy pathbenchmark_pool_ceph.sh
File metadata and controls
171 lines (147 loc) · 6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
!/bin/bash
# Benchmark Ceph sécurisé avec affichage des résultats dans un tableau
POOL="pool_test"
TEMP_POOL="${POOL}_bench"
DURATION=30
THREADS=16
BLOCK_WRITE="4M"
BLOCK_READ="4K"
OBJ_TEST="obj_test_bench"
PG_NUM=128 # Nombre de placement groups (ajustez selon votre cluster)
# Option debug (décommenter pour activer)
# DEBUG=1
echo "=== Benchmark Ceph sécurisé sur pool temporaire $TEMP_POOL ==="
# Vérification et création du pool principal si nécessaire
echo "Vérification du pool principal $POOL..."
if ! ceph osd pool ls | grep -q "^${POOL}$"; then
echo "❌ Pool $POOL introuvable. Création en cours..."
if ceph osd pool create $POOL $PG_NUM 2>/dev/null; then
echo "✅ Pool $POOL créé avec succès ($PG_NUM PGs)"
else
echo "❌ Erreur lors de la création du pool $POOL"
exit 1
fi
else
echo "✅ Pool $POOL existe déjà"
fi
# Création du pool temporaire si nécessaire
echo "Création du pool temporaire $TEMP_POOL..."
if ! ceph osd pool create $TEMP_POOL $PG_NUM 2>/dev/null; then
echo "[i] Pool temporaire déjà existant ou erreur de création"
fi
# Fonction pour extraire les métriques de rados bench
parse_bench() {
local out="$1"
local test_name="$2"
# Debug: afficher la sortie pour diagnostic
if [[ -n "$DEBUG" ]]; then
echo "[DEBUG] $test_name - Sortie complète:" >&2
echo "$out" >&2
echo "--- Fin sortie $test_name ---" >&2
fi
if [[ "$out" == *"error"* ]] || [[ "$out" == *"Error"* ]] || [[ "$out" == *"Invalid"* ]]; then
echo "[ERROR] $test_name - Erreur détectée:" >&2
echo "$out" | head -5 >&2
fi
# Parsing spécifique selon le format de sortie de rados bench
local bw=""
local iops=""
local lat=""
# Recherche de "Bandwidth (MB/sec): XXX"
bw=$(echo "$out" | grep "Bandwidth (MB/sec):" | awk -F':' '{print $2}' | sed 's/[^0-9.]//g')
# Recherche de "Average IOPS: XXX"
iops=$(echo "$out" | grep "Average IOPS:" | awk -F':' '{print $2}' | sed 's/[^0-9.]//g')
# Recherche de "Average Latency(s): XXX" (multiplier par 1000 pour avoir en ms)
lat=$(echo "$out" | grep "Average Latency(s):" | awk -F':' '{print $2}' | sed 's/[^0-9.]//g')
if [[ -n "$lat" ]] && [[ "$lat" != "0" ]]; then
lat=$(echo "$lat * 1000" | bc -l 2>/dev/null | cut -d'.' -f1)
fi
# Debug des valeurs extraites
if [[ -n "$DEBUG" ]]; then
echo "[DEBUG] $test_name - BW: $bw, IOPS: $iops, LAT: $lat" >&2
fi
# Valeurs par défaut si pas trouvées
echo "${bw:-0} ${iops:-0} ${lat:-0}"
}
# 1️⃣ Write benchmark
echo "[1/4] Écriture sur objet test..."
echo "Exécution du benchmark d'écriture..."
W=$(rados bench $DURATION write -p $TEMP_POOL -t $THREADS -b $BLOCK_WRITE --no-cleanup 2>&1)
read WB IOPS_W LAT_W <<< "$(parse_bench "$W" "WRITE")"
# 2️⃣ Seq Read benchmark
echo "[2/4] Lecture séquentielle..."
echo "Objets disponibles dans le pool:"
rados ls -p $TEMP_POOL | head -5
S=$(rados bench $DURATION seq -p $TEMP_POOL -t $THREADS 2>&1)
read SB IOPS_S LAT_S <<< "$(parse_bench "$S" "SEQ_READ")"
# 3️⃣ Rand Read benchmark
echo "[3/4] Lecture aléatoire..."
R=$(rados bench $DURATION rand -p $TEMP_POOL -t $THREADS 2>&1)
read RB IOPS_R LAT_R <<< "$(parse_bench "$R" "RAND_READ")"
# 4️⃣ Nettoyage
echo "[4/4] Nettoyage..."
rados cleanup -p $TEMP_POOL 2>/dev/null
echo "Objets nettoyés."
# 5️⃣ Affichage des résultats avec formatage amélioré
echo
echo "=== Résumé Benchmark Ceph ==="
echo
# Fonction pour formater les nombres
format_number() {
local num="$1"
if [[ "$num" =~ ^[0-9]+\.?[0-9]*$ ]] && [ "${num%.*}" -gt 0 ]; then
printf "%.2f" "$num"
else
echo "N/A"
fi
}
# Conversion latence en millisecondes si nécessaire
convert_latency() {
local lat="$1"
if [[ "$lat" =~ ^[0-9]+\.?[0-9]*$ ]] && [ "${lat%.*}" -gt 0 ]; then
# Si la valeur est < 1, c'est probablement en secondes, convertir en ms
if (( $(echo "$lat < 1" | bc -l 2>/dev/null || echo 0) )); then
echo "$(echo "$lat * 1000" | bc -l 2>/dev/null | xargs printf "%.2f")"
else
printf "%.2f" "$lat"
fi
else
echo "N/A"
fi
}
# Variables formatées
WB_F=$(format_number "$WB")
IOPS_W_F=$(format_number "$IOPS_W")
LAT_W_F=$(convert_latency "$LAT_W")
SB_F=$(format_number "$SB")
IOPS_S_F=$(format_number "$IOPS_S")
LAT_S_F=$(convert_latency "$LAT_S")
RB_F=$(format_number "$RB")
IOPS_R_F=$(format_number "$IOPS_R")
LAT_R_F=$(convert_latency "$LAT_R")
# Tableau formaté
printf "┌─────────────────────────────┬───────────────┬─────────────────┬───────────────┐\n"
printf "│ %-27s │ %-13s │ %-15s │ %-13s │\n" "Métrique" "MB/s" "Latence (ms)" "IOPS"
printf "├─────────────────────────────┼───────────────┼─────────────────┼───────────────┤\n"
printf "│ %-27s │ %13s │ %15s │ %13s │\n" "Écriture" "$WB_F" "$LAT_W_F" "$IOPS_W_F"
printf "│ %-27s │ %13s │ %15s │ %13s │\n" "Lecture Séquentielle" "$SB_F" "$LAT_S_F" "$IOPS_S_F"
printf "│ %-27s │ %13s │ %15s │ %13s │\n" "Lecture Aléatoire" "$RB_F" "$LAT_R_F" "$IOPS_R_F"
printf "└─────────────────────────────┴───────────────┴─────────────────┴───────────────┘\n"
echo
echo "ℹ️ Paramètres utilisés:"
echo " - Durée: ${DURATION}s"
echo " - Threads: $THREADS"
echo " - Taille bloc écriture: $BLOCK_WRITE"
echo " - Pool principal: $POOL"
echo " - Pool temporaire: $TEMP_POOL ($PG_NUM PGs)"
echo " - Objets créés: $(rados ls -p $TEMP_POOL 2>/dev/null | wc -l) objets"
echo
echo "✅ Benchmark terminé."
# Option pour supprimer le pool temporaire
read -p "Supprimer le pool temporaire $TEMP_POOL ? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Suppression du pool temporaire..."
ceph osd pool delete $TEMP_POOL $TEMP_POOL --yes-i-really-really-mean-it 2>/dev/null
echo "Pool temporaire supprimé."
fi