-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmegacli.sh
executable file
·271 lines (233 loc) · 8.04 KB
/
megacli.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
#!/bin/bash
#Path to megacli
MEGACLI="/opt/MegaRAID/MegaCli/MegaCli64"
NAMESPACE="megacli"
#Adapter
ADP_OUT=`$MEGACLI -AdpAllInfo -aALL -NoLog| grep -E "(^Adapter|Virtual Drives|Degraded| Offline|Physical Devices|Disks|Critical Disks|Failed Disks)"`
#All about disks
VD_PDID_ERRORS=`$MEGACLI -ldpdinfo -aALL -NoLog| grep -E "(Id|State |Media Error|Firmware state)"`
#Battery info
BBU_OUT=`$MEGACLI -AdpBbuCmd -aAll -NoLog| grep -E "(BBU status for Adapter|^Voltage|^Current|Battery State|Battery Replacement required|^Remaining Capacity|^Full Charge Capacity|^Max Error)"`
adapter=0
bat_voltage=()
bat_amp=()
bat_state=()
bat_replacment=()
bat_remaining_cap=()
bat_full_cap=()
bat_max_error=()
adp_vd_count=()
adp_vd_degraded=()
adp_vd_offline=()
adp_pd_count=()
adp_pd_disks=()
adp_pd_critical_disks=()
adp_pd_failed_disks=()
while read bbu_line
do
exp="$(expr match "$bbu_line" '^BBU status for Adapter:[[:blank:]]*\([[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
adapter=$exp
continue
fi
exp="$(expr match "$bbu_line" '^Voltage:[[:blank:]]*\([[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
bat_voltage[$adapter]=$exp
continue
fi
exp="$(expr match "$bbu_line" '^Current:[[:blank:]]*\(-*[[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
bat_amp[$adapter]=$exp
continue
fi
exp="$(expr match "$bbu_line" '^Battery State:[[:blank:]]*\([a-zA-Z\(\)]\+\).*')"
if [ -n "${exp}" ]
then
if [[ $exp == "Optimal" ]]
then
bat_state[$adapter]=1
elif [[ $exp == "Degraded(Charging)" ]]
then
bat_state[$adapter]=2
elif [[ $exp == "Learning" ]]
then
bat_state[$adapter]=3
else
bat_state[$adapter]=0
fi
continue
fi
exp="$(expr match "$bbu_line" 'Battery Replacement required[[:blank:]]*:[[:blank:]]*\([[:alpha:]]\+\).*')"
if [ -n "${exp}" ]
then
if [[ $exp == "No" ]]
then
bat_replacment[$adapter]=0
else
bat_replacment[$adapter]=1
fi
continue
fi
exp="$(expr match "$bbu_line" '^Remaining Capacity:[[:blank:]]*\([[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
bat_remaining_cap[$adapter]=$exp
continue
fi
exp="$(expr match "$bbu_line" '^Full Charge Capacity:[[:blank:]]*\([[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
bat_full_cap[$adapter]=$exp
continue
fi
exp="$(expr match "$bbu_line" '^Max Error =[[:blank:]]*\([[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
bat_max_error[$adapter]=$exp
continue
fi
done <<< "${BBU_OUT}"
while read adp_line
do
exp="$(expr match "$adp_line" '^Adapter #[[:blank:]]*\([[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
adapter=$exp
continue
fi
exp="$(expr match "$adp_line" '^Virtual Drives[[:blank:]]*:[[:blank:]]*\([[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
adp_vd_count[$adapter]=$exp
continue
fi
exp="$(expr match "$adp_line" 'Degraded[[:blank:]]*:[[:blank:]]*\([[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
adp_vd_degraded[$adapter]=$exp
continue
fi
exp="$(expr match "$adp_line" 'Offline[[:blank:]]*:[[:blank:]]*\([[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
adp_vd_offline[$adapter]=$exp
continue
fi
exp="$(expr match "$adp_line" '^Physical Devices[[:blank:]]*:[[:blank:]]*\([[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
adp_pd_count[$adapter]=$exp
continue
fi
exp="$(expr match "$adp_line" 'Disks[[:blank:]]*:[[:blank:]]*\([[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
adp_pd_disks[$adapter]=$exp
continue
fi
exp="$(expr match "$adp_line" 'Critical Disks[[:blank:]]*:[[:blank:]]*\([[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
adp_pd_critical_disks[$adapter]=$exp
continue
fi
exp="$(expr match "$adp_line" 'Failed Disks[[:blank:]]*:[[:blank:]]*\([[:digit:]]\+\).*')"
if [ -n "${exp}" ]
then
adp_pd_failed_disks[$adapter]=$exp
continue
fi
done <<< "${ADP_OUT}"
printBBU() {
echo "# HELP ${NAMESPACE}_bbu_voltage BBU Voltage mV."
echo "# TYPE ${NAMESPACE}_bbu_voltage gauge"
for index in ${!bat_voltage[*]}
do
echo "${NAMESPACE}_bbu_voltage{adapter=\"${index}\"} ${bat_voltage[$index]}"
done
echo "# HELP ${NAMESPACE}_bbu_amp_current BBU Current mA."
echo "# TYPE ${NAMESPACE}_bbu_amp_current gauge"
for index in ${!bat_amp[*]}
do
echo "${NAMESPACE}_bbu_amp_current{adapter=\"${index}\"} ${bat_amp[$index]}"
done
echo "# HELP ${NAMESPACE}_bbu_bat_state Battery State."
echo "# TYPE ${NAMESPACE}_bbu_bat_state gauge"
for index in ${!bat_state[*]}
do
echo "${NAMESPACE}_bbu_bat_state{adapter=\"${index}\"} ${bat_state[$index]}"
done
echo "# HELP ${NAMESPACE}_bbu_bat_replacment Battery needs to be replaced."
echo "# TYPE ${NAMESPACE}_bbu_bat_replacment gauge"
for index in ${!bat_replacment[*]}
do
echo "${NAMESPACE}_bbu_bat_replacment{adapter=\"${index}\"} ${bat_replacment[$index]}"
done
echo "# HELP ${NAMESPACE}_bbu_remaining_cap BBU Remaining Capacity mAh."
echo "# TYPE ${NAMESPACE}_bbu_remaining_cap gauge"
for index in ${!bat_remaining_cap[*]}
do
echo "${NAMESPACE}_bbu_remaining_cap{adapter=\"${index}\"} ${bat_remaining_cap[$index]}"
done
echo "# HELP ${NAMESPACE}_bbu_full_cap BBU Full Charge Capacity mAh."
echo "# TYPE ${NAMESPACE}_bbu_full_cap gauge"
for index in ${!bat_full_cap[*]}
do
echo "${NAMESPACE}_bbu_full_cap{adapter=\"${index}\"} ${bat_full_cap[$index]}"
done
echo "# HELP ${NAMESPACE}_bbu_max_error Battery Max Error percent."
echo "# TYPE ${NAMESPACE}_bbu_max_error gauge"
for index in ${!bat_max_error[*]}
do
echo "${NAMESPACE}_bbu_max_error{adapter=\"${index}\"} ${bat_max_error[$index]}"
done
}
printADP() {
echo "# HELP ${NAMESPACE}_adp_vd_count Adapter Virtual Drives count."
echo "# TYPE ${NAMESPACE}_adp_vd_count gauge"
for index in ${!adp_vd_count[*]}
do
echo "${NAMESPACE}_adp_vd_count{adapter=\"${index}\"} ${adp_vd_count[$index]}"
done
echo "# HELP ${NAMESPACE}_adp_vd_degraded_count Adapter Virtual Drives Degraded count."
echo "# TYPE ${NAMESPACE}_adp_vd_degraded_count gauge"
for index in ${!adp_vd_degraded[*]}
do
echo "${NAMESPACE}_adp_vd_degraded_count{adapter=\"${index}\"} ${adp_vd_degraded[$index]}"
done
echo "# HELP ${NAMESPACE}_adp_vd_offline_count Adapter Virtual Drives Offline count."
echo "# TYPE ${NAMESPACE}_adp_vd_offline_count gauge"
for index in ${!adp_vd_offline[*]}
do
echo "${NAMESPACE}_adp_vd_offline_count{adapter=\"${index}\"} ${adp_vd_offline[$index]}"
done
echo "# HELP ${NAMESPACE}_adp_pd_count Adapter Physical Devices count."
echo "# TYPE ${NAMESPACE}_adp_pd_count gauge"
for index in ${!adp_pd_count[*]}
do
echo "${NAMESPACE}_adp_pd_count{adapter=\"${index}\"} ${adp_pd_count[$index]}"
done
echo "# HELP ${NAMESPACE}_adp_pd_disks_count Adapter Physical Disks count."
echo "# TYPE ${NAMESPACE}_adp_pd_disks_count gauge"
for index in ${!adp_pd_disks[*]}
do
echo "${NAMESPACE}_adp_pd_disks_count{adapter=\"${index}\"} ${adp_pd_disks[$index]}"
done
echo "# HELP ${NAMESPACE}_adp_pd_critical_disks_count Adapter Physical Critical Disks count."
echo "# TYPE ${NAMESPACE}_adp_pd_critical_disks_count gauge"
for index in ${!adp_pd_critical_disks[*]}
do
echo "${NAMESPACE}_adp_pd_critical_disks_count{adapter=\"${index}\"} ${adp_pd_critical_disks[$index]}"
done
echo "# HELP ${NAMESPACE}_adp_pd_failed_disks_count Adapter Physical Failed Disks count."
echo "# TYPE ${NAMESPACE}_adp_pd_failed_disks_count gauge"
for index in ${!adp_pd_failed_disks[*]}
do
echo "${NAMESPACE}_adp_pd_failed_disks_count{adapter=\"${index}\"} ${adp_pd_failed_disks[$index]}"
done
}
printBBU
printADP