This repository has been archived by the owner on Nov 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathceph-status.sh
executable file
·302 lines (273 loc) · 5.69 KB
/
ceph-status.sh
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/bin/bash
ceph_bin="/usr/bin/ceph"
rados_bin="/usr/bin/rados"
# Initialising variables
# See: http://ceph.com/docs/master/rados/operations/pg-states/
creating=0
active=0
clean=0
down=0
replay=0
splitting=0
scrubbing=0
degraded=0
inconsistent=0
peering=0
repair=0
recovering=0
backfill=0
waitBackfill=0
incomplete=0
stale=0
remapped=0
# Get data
pginfo=$(echo -n " pgmap $($ceph_bin pg stat)" | sed -n "s/.*pgmap/pgmap/p")
pgtotal=$(echo $pginfo | cut -d':' -f2 | sed 's/[^0-9]//g')
pgstats=$(echo $pginfo | cut -d':' -f3 | cut -d';' -f1| sed 's/ /\\ /g')
pggdegraded=$(echo $pginfo | sed -n '/degraded/s/.* degraded (\([^%]*\)%.*/\1/p')
if [[ "$pggdegraded" == "" ]]
then
pggdegraded=0
fi
# unfound (0.004%)
pgunfound=$(echo $pginfo | cut -d';' -f2|sed -n '/unfound/s/.*unfound (\([^%]*\)%.*/\1/p')
if [[ "$pgunfound" == "" ]]
then
pgunfound=0
fi
# write kbps B/s
rdbps=$(echo $pginfo | sed -n '/pgmap/s/.* \([0-9]* .\?\)B\/s rd.*/\1/p' | sed -e "s/K/*1000/ig;s/M/*1000*1000/i;s/G/*1000*1000*1000/i;s/E/*1000*1000*1000*1000/i" | bc)
if [[ "$rdbps" == "" ]]
then
rdbps=0
fi
# write kbps B/s
wrbps=$(echo $pginfo | sed -n '/pgmap/s/.* \([0-9]* .\?\)B\/s wr.*/\1/p' | sed -e "s/K/*1000/ig;s/M/*1000*1000/i;s/G/*1000*1000*1000/i;s/E/*1000*1000*1000*1000/i" | bc)
if [[ "$wrbps" == "" ]]
then
wrbps=0
fi
# ops
ops=$(echo $pginfo | sed -n '/pgmap/s/.* \([0-9]*\) op\/s.*/\1/p')
if [[ "$ops" == "" ]]
then
ops=0
fi
# Explode array
IFS=', ' read -a array <<< "$pgstats"
for element in "${array[@]}"
do
element=$(echo "$element" | sed 's/^ *//g')
# Get elements
number=$(echo $element | cut -d' ' -f1)
data=$(echo $element | cut -d' ' -f2)
# Agregate data
if [ "$(echo $data | grep creating | wc -l)" == 1 ]
then
creating=$(echo $creating+$number|bc)
fi
if [ "$(echo $data | grep active | wc -l)" == 1 ]
then
active=$(echo $active+$number|bc)
fi
if [ "$(echo $data | grep clean | wc -l)" == 1 ]
then
clean=$(echo $clean+$number|bc)
fi
if [ "$(echo $data | grep down | wc -l)" == 1 ]
then
down=$(echo $down+$number|bc)
fi
if [ "$(echo $data | grep replay | wc -l)" == 1 ]
then
replay=$(echo $replay+$number|bc)
fi
if [ "$(echo $data | grep splitting | wc -l)" == 1 ]
then
splitting=$(echo $splitting+$number|bc)
fi
if [ "$(echo $data | grep scrubbing | wc -l)" == 1 ]
then
scrubbing=$(echo $scrubbing+$number|bc)
fi
if [ "$(echo $data | grep degraded | wc -l)" == 1 ]
then
degraded=$(echo $degraded+$number|bc)
fi
if [ "$(echo $data | grep inconsistent | wc -l)" == 1 ]
then
inconsistent=$(echo $inconsistent+$number|bc)
fi
if [ "$(echo $data | grep peering | wc -l)" == 1 ]
then
peering=$(echo $peering+$number|bc)
fi
if [ "$(echo $data | grep repair | wc -l)" == 1 ]
then
repair=$(echo $repair+$number|bc)
fi
if [ "$(echo $data | grep recovering | wc -l)" == 1 ]
then
recovering=$(echo $recovering+$number|bc)
fi
if [ "$(echo $data | grep backfill | wc -l)" == 1 ]
then
backfill=$(echo $backfill+$number|bc)
fi
if [ "$(echo $data | grep "wait-backfill" | wc -l)" == 1 ]
then
waitBackfill=$(echo $waitBackfill+$number|bc)
fi
if [ "$(echo $data | grep incomplete | wc -l)" == 1 ]
then
incomplete=$(echo $incomplete+$number|bc)
fi
if [ "$(echo $data | grep stale | wc -l)" == 1 ]
then
stale=$(echo $stale+$number|bc)
fi
if [ "$(echo $data | grep remapped | wc -l)" == 1 ]
then
remapped=$(echo $remapped+$number|bc)
fi
done
ceph_osd_count=$($ceph_bin osd dump |grep "^osd"| wc -l)
function ceph_osd_up_percent()
{
OSD_DOWN=$($ceph_bin osd dump |grep "^osd"| awk '{print $1 " " $2 " " $3}'|grep up|wc -l)
COUNT=$(echo "scale=2; $OSD_DOWN*100/$ceph_osd_count" |bc)
if [[ "$COUNT" != "" ]]
then
echo $COUNT
else
echo "0"
fi
}
function ceph_osd_in_percent()
{
OSD_DOWN=$($ceph_bin osd dump |grep "^osd"| awk '{print $1 " " $2 " " $3}'|grep in|wc -l)
COUNT=$(echo "scale=2; $OSD_DOWN*100/$ceph_osd_count" | bc)
if [[ "$COUNT" != "" ]]
then
echo $COUNT
else
echo "0"
fi
}
function ceph_mon_get_active()
{
ACTIVE=$($ceph_bin status|sed -n '/monmap/s/.* \([0-9]*\) mons.*/\1/p')
if [[ "$ACTIVE" != "" ]]
then
echo $ACTIVE
else
echo 0
fi
}
# Return the value
case $1 in
health)
status=$($ceph_bin health | awk '{print $1}')
case $status in
HEALTH_OK)
echo 1
;;
HEALTH_WARN)
echo 2
;;
HEALTH_ERR)
echo 3
;;
*)
echo -1
;;
esac
;;
rados_total)
$rados_bin df | grep "total space"| awk '{print $3}'
;;
rados_used)
$rados_bin df | grep "total used"| awk '{print $3}'
;;
rados_free)
$rados_bin df | grep "total avail"| awk '{print $3}'
;;
mon)
ceph_mon_get_active
;;
count)
echo $ceph_osd_count
;;
up)
ceph_osd_up_percent
;;
"in")
ceph_osd_in_percent
;;
degraded_percent)
echo $pggdegraded
;;
pgtotal)
echo $pgtotal
;;
creating)
echo $creating
;;
active)
echo $active
;;
clean)
echo $clean
;;
down)
echo $down
;;
replay)
echo $replay
;;
splitting)
echo $splitting
;;
scrubbing)
echo $scrubbing
;;
degraded)
echo $degraded
;;
inconsistent)
echo $inconsistent
;;
peering)
echo $peering
;;
repair)
echo $repair
;;
recovering)
echo $recovering
;;
backfill)
echo $backfill
;;
waitBackfill)
echo $waitBackfill
;;
incomplete)
echo $incomplete
;;
stale)
echo $stale
;;
remapped)
echo $remapped
;;
ops)
echo $ops
;;
wrbps)
echo $wrbps
;;
rdbps)
echo $rdbps
;;
esac