Skip to content

Commit 678d18b

Browse files
committed
Use numfmt instead of own function
Signed-off-by: Kalle Fagerberg <[email protected]>
1 parent f40f707 commit 678d18b

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

textfile_collector.sh

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,13 @@ FILEPATH=${TEXTFILE_PATH:=/shared_vol/scrape.txt}
44
INTERVAL=${COLLECT_INTERVAL:=10}
55
PROVISIONERS=${PROVISIONER_WHITELIST:=openebs.io/local}
66

7-
## calculate_pv_capacity obtains the size of a PV in bytes
8-
function calculate_pv_capacity(){
9-
if [[ ${size_in_spec} =~ "i" ]]; then
10-
unit=$(echo "${size_in_spec: -2}")
11-
else
12-
unit=$(echo "${size_in_spec: -1}")
13-
fi
14-
15-
case "${unit}" in
16-
17-
g|gi) echo $((1024*1024*1024*$(echo $1 | tr -d ${unit})))
18-
;;
19-
m|mi) echo $((1024*1024*$(echo $1 | tr -d ${unit})))
20-
;;
21-
k|ki) echo $((1024*$(echo $1 | tr -d ${unit})))
22-
;;
23-
b|bi) echo $1 | tr -d ${unit}
24-
;;
25-
*) echo 0
26-
;;
27-
esac
28-
}
29-
307
## collect_pv_capacity_metrics collects the PV capacity metrics
318
function collect_pv_capacity_metrics(){
329
for i in ${pv_list[@]}
3310
do
3411
pvc_name=$(kubectl get pv ${i} -o custom-columns=:spec.claimRef.name --no-headers | tr '[:upper:]' '[:lower:]')
3512
size_in_spec=$(kubectl get pv ${i} -o custom-columns=:spec.capacity.storage --no-headers | tr '[:upper:]' '[:lower:]')
36-
size_in_bytes=$(calculate_pv_capacity ${size_in_spec};)
13+
size_in_bytes=$(numfmt --from=auto --to=none ${size_in_spec};)
3714
echo "pv_capacity_bytes{persistentvolume=\"${i}\",persistentvolumeclaim=\"${pvc_name}\"} ${size_in_bytes}"
3815
done
3916
}

0 commit comments

Comments
 (0)