Closed dud0n closed 3 years ago
If from box installation
# iostat -d | awk 'BEGIN {check=0;count=0;array[0]=0;} {if(check==1 && $1 != ""){array[count]=$1;count=count+1;}if($1=="Device:"){check=1;}} END {printf("{\n\t\"data\":[\n");for(i=0;i<count;++i){printf("\t\t{\n\t\t\t\"{#HARDDISK}\":\"%s\"}", array[i]); if(i+1<count){printf(",\n");}} printf("]}\n");}'
Console out:
{
"data":[
]}
sysstat version 11.7.3
At least in iostat 11.6.1 (Ubuntu 18.04 LTS), there is the option -o JSON
. I think the scripts should be re-worked to use machine-readable output of iostat instead of trying to parse the output format intended for humans, as the format can change (or as seen here, is changing).
I merged in a modified template/script in #72. I also added a regular expression in the script to work with optional colon in #82, I think this issue is now fixed in #82.
In the iostat version >= 12, in the "Device" section, the ":" sign was removed therefore parsing does not work and the script cannot get a list of devices. I propose a solution: [iostat.conf] iostat -d | awk 'BEGIN {check = 0; count = 0; array [0] = 0;} {if (check == 1 && $ 1! = "") {array [count] = $ 1; count = count + 1;} if ($ 1 == "Device:" || $ 1 == "Device") {check = 1;}} END {printf ("{\ n \ t \" data \ ": [\ n"); for (i = 0; i <count; ++ i) {printf ("\ t \ t {\ n \ t \ t \ t \" {# HARDDISK} \ ": \"% s \ "}", array [i]) ; if (i + 1 <count) {printf (", \ n");}} printf ("]} \ n")}}
[iostat-collect.sh] DISK = $ ($ IOSTAT -x 1 "$ SECONDS" | awk 'BEGIN {check = 0;} {if (check == 1 && $ 1 == "avg-cpu:") {check = 0} if (check == 1 && $ 1! = "") {print $ 0} if ($ 1 == "Device:" || $ 1 == "Device") {check = 1}} | | tr '\ n' '| )