3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
12 # Measure storage capacity and scale of a host
15 OUTPUT_FILE=/tmp/storagecapacity-out.log
20 fdisk -l | grep '^Disk.*bytes$' | awk -F [:,\ ] '{print $2,$7}' > $OUTPUT_FILE
23 # write the disk size to stdout in json format
26 DEVICENUM=`awk 'END{print NR}' $OUTPUT_FILE`
27 DISKSIZE=`awk 'BEGIN{cnt=0;} {cnt=cnt+$2} END{print cnt}' $OUTPUT_FILE`
29 \"Number of devices\":\"$DEVICENUM\", \
30 \"Total disk size\":\"$DISKSIZE bytes\" \
37 echo -n "" > $OUTPUT_FILE
38 blkdevices=`fdisk -l | grep '^Disk.*bytes$' | awk -F [:,\ ] '{print $2}'`
39 blkdevices=($blkdevices)
40 for bd in "${blkdevices[@]}";do
41 blk_size=`blockdev --getbsz $bd`
42 echo '"'$bd'" '$blk_size >> $OUTPUT_FILE
46 # write the block size to stdout in json format
49 BLK_SIZE_STR=`awk 'BEGIN{r="{";} {r=r""$1":"$2","} END{print r}' $OUTPUT_FILE`
50 BLK_SIZE_STR=${BLK_SIZE_STR%,}"}"