From: Siraaj Khandkar Date: Wed, 1 Aug 2018 19:47:02 +0000 (-0400) Subject: Split-out ip addr parser X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=0819928a2ed96fc0d56613ae16169489972fa5b3;p=khatus.git Split-out ip addr parser --- diff --git a/bin/khatus b/bin/khatus index ead9dbd..da0c78c 100755 --- a/bin/khatus +++ b/bin/khatus @@ -256,6 +256,7 @@ main() { cmd_sens_fan="khatus_sensor_fan $fan_path" cmd_sens_bluetooth="khatus_sensor_bluetooth_power $dir_bin" cmd_sens_mpd_state="khatus_sensor_mpd_state $dir_bin" + cmd_sens_net_addr_io="khatus_sensor_net_addr_io $dir_bin" # TODO: Redirect each worker's stderr to a dedicated log file pipe="$file_pipe" @@ -271,7 +272,7 @@ main() { fork_poller $interval_inp_volume "$pipe" "$dir_bin" "$log" khatus_sensor_volume 'in:VOLUME' fork_poller $interval_inp_bluetooth "$pipe" "$dir_bin" "$log" "$cmd_sens_bluetooth" 'in:BLUETOOTH_POWER' fork_poller $interval_inp_net_wifi "$pipe" "$dir_bin" "$log" khatus_sensor_net_wifi_status 'in:NET_WIFI_STATUS' - fork_poller $interval_inp_net_io "$pipe" "$dir_bin" "$log" khatus_sensor_net_addr_io 'in:NET_ADDR_IO' + fork_poller $interval_inp_net_io "$pipe" "$dir_bin" "$log" "$cmd_sens_net_addr_io" 'in:NET_ADDR_IO' fork_poller $interval_inp_disk_space "$pipe" "$dir_bin" "$log" "$cmd_sens_disk_space" 'in:DISK_SPACE' fork_poller $interval_inp_disk_io "$pipe" "$dir_bin" "$log" "$cmd_sens_disk_io" 'in:DISK_IO' fork_poller $interval_inp_loadavg "$pipe" "$dir_bin" "$log" khatus_sensor_loadavg 'in:LOAD_AVG' diff --git a/bin/khatus_parse_ip_addr b/bin/khatus_parse_ip_addr new file mode 100755 index 0000000..bc833b2 --- /dev/null +++ b/bin/khatus_parse_ip_addr @@ -0,0 +1,37 @@ +#! /usr/bin/awk -f + +/^[0-9]+:/ { + sub(":$", "", $1) + sub(":$", "", $2) + sequence = $1 + interface = $2 + interfaces[sequence] = interface +} + +/^ +inet [0-9]/ { + sub("/[0-9]+", "", $2) + addr = $2 + addrs[interface] = addr +} + +/^ +RX: / {transfer_direction = "r"} +/^ +TX: / {transfer_direction = "w"} + +/^ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ *$/ { + io[interface, transfer_direction] = $1; +} + +END { + for (seq=1; seq<=sequence; seq++) { + interface = interfaces[seq] + label = substr(interface, 1, 1) + addr = addrs[interface] + if (addr) { + curr_read = io[interface, "r"] + curr_write = io[interface, "w"] + print(interface, addr, curr_write, curr_read) + } else { + print(interface) + } + } +} diff --git a/bin/khatus_sensor_net_addr_io b/bin/khatus_sensor_net_addr_io index 48b9b07..dd9086c 100755 --- a/bin/khatus_sensor_net_addr_io +++ b/bin/khatus_sensor_net_addr_io @@ -2,39 +2,6 @@ set -e -ip -s addr \ -| awk ' - /^[0-9]+:/ { - sub(":$", "", $1) - sub(":$", "", $2) - sequence = $1 - interface = $2 - interfaces[sequence] = interface - } +dir_bin="$1" - /^ +inet [0-9]/ { - sub("/[0-9]+", "", $2) - addr = $2 - addrs[interface] = addr - } - - /^ +RX: / {transfer_direction = "r"} - /^ +TX: / {transfer_direction = "w"} - - /^ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ *$/ { - io[interface, transfer_direction] = $1; - } - - END { - for (seq=1; seq<=sequence; seq++) { - interface = interfaces[seq] - label = substr(interface, 1, 1) - if (addrs[interface]) { - curr_read = io[interface, "r"] - curr_write = io[interface, "w"] - print(interface, addrs[interface], curr_write, curr_read) - } else { - print(interface) - } - } - }' +ip -s addr | "$dir_bin"/khatus_parse_ip_addr