lesovsky / zabbix-extensions

Zabbix additional monitoring modules
BSD 3-Clause "New" or "Revised" License
316 stars 230 forks source link

Trouble with parsing iostat v12 #64

Closed dud0n closed 3 years ago

dud0n commented 5 years ago

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' '| )

blablabla-bla2009 commented 4 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

stephankn commented 4 years ago

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).

stephankn commented 3 years ago

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.