diff --git a/Makefile b/Makefile index 0fde8f01..2ba7e8e4 100644 --- a/Makefile +++ b/Makefile @@ -273,7 +273,6 @@ endif echo 'FLM_WAN_PPPOE_USER=$(CONFIG_FLASHMAN_PPPOE_USER)' >>$(1)/usr/share/flashman_init.conf echo 'FLM_WAN_PPPOE_PASSWD=$(CONFIG_FLASHMAN_PPPOE_PASSWD)' >>$(1)/usr/share/flashman_init.conf echo 'FLM_WAN_PPPOE_SERVICE=$(CONFIG_FLASHMAN_PPPOE_SERVICE)' >>$(1)/usr/share/flashman_init.conf - echo 'FLM_USE_AUTH_SVADDR=$(CONFIG_FLASHMAN_USE_AUTH_SERVER)' >>$(1)/usr/share/flashman_init.conf echo 'FLM_CONNECTIVITY_SVADDRS_LIST=$(CONFIG_CONNECTIVITY_SVADDRS_LIST)' >>$(1)/usr/share/flashman_init.conf diff --git a/files/etc/uci-defaults/z002_flashbox-network.sh b/files/etc/uci-defaults/z002_flashbox-network.sh index 39477ec0..ca3eec71 100755 --- a/files/etc/uci-defaults/z002_flashbox-network.sh +++ b/files/etc/uci-defaults/z002_flashbox-network.sh @@ -83,7 +83,7 @@ uci set network.lan.netmask="$_lan_netmask" uci set network.lan.ip6assign="$_lan_ipv6prefix" uci set network.lan.igmp_snooping='1' uci set network.lan.stp='1' - +# Configure dmz uci set network.dmz=interface uci set network.dmz.proto='static' uci set network.dmz.netmask='24' diff --git a/files/usr/share/data_collecting.sh b/files/usr/share/data_collecting.sh index 210b7b6e..306a0fe4 100755 --- a/files/usr/share/data_collecting.sh +++ b/files/usr/share/data_collecting.sh @@ -1,61 +1,55 @@ #!/bin/sh . /usr/share/functions/device_functions.sh . /usr/share/functions/common_functions.sh +. /usr/share/functions/custom_wireless_driver.sh . /usr/share/flashman_init.conf # directory where all data related to data collecting will be stored. dataCollectingDir="/tmp/data_collecting" -# file collected data will be stored before being compressed. +# file where collected data will be stored before being compressed. rawDataFile="${dataCollectingDir}/raw" -# directory where data will be stored if compressing old data is necessary. -compressedDataDir="${dataCollectingDir}/compressed" -# takes current unix timestamp, executes ping, in burst, to $pingServerAddress server, gets current -# rx and tx bytes from wan interface and compares then with values from previous calls to calculate -# cross traffic. If latency collecting is enabled, extracts the individual icmp request numbers and +# gets current rx and tx bytes/packets from wan interface and compares them +# with values from previous calls to calculate cross traffic +wan() { + # checking if this data collecting is enabled + + [ $burstLoss -eq 0 ] && [ $pingAndWan -eq 0 ] && return + + # bytes received by the interface. + local r=$(get_wan_bytes_statistics RX) + # bytes sent by the interface. + local t=$(get_wan_bytes_statistics TX) + + rawData="${rawData}|wanBytes $r $t" + + # burstLoss only gathers byte data + [ $pingAndWan -eq 0 ] && return + + # packets received by the interface. + r=$(get_wan_packets_statistics RX) + # packets sent by the interface. + t=$(get_wan_packets_statistics TX) + + # data to be sent. + rawData="${rawData}|wanPkts $r $t" +} + +# takes current unix timestamp, executes ping, in burst, to $pingServerAddress server. +# If latency collecting is enabled, extracts the individual icmp request numbers and # their respective ping times. Builds a string with all this information and write them to file. -collect_QoE_Monitor_data() { - # echo collecting data and writing to file. +burst() { + # checking if this data collecting is enabled + + [ $burstLoss -eq 0 ] && [ $pingAndWan -eq 0 ] && return - # getting current unix time in seconds. - local timestamp=$(date +%s) # burst ping with $pingPackets amount of packets. local pingResult=$(ping -i 0.01 -c "$pingPackets" "$pingServerAddress") # ping return value. local pingError="$?" - # Even if the ping could not be executed, we'll read the wan bytes to keep tracking the amount of bytes up and down. - - # bytes received by the interface. - local rxBytes=$(get_wan_statistics RX) - # bytes sent by the interface. - local txBytes=$(get_wan_statistics TX) - - # if last bytes are not defined. define them using the current wan interface bytes value. then we skip this measure. - if [ -z "$last_rxBytes" ] || [ -z "$last_txBytes" ]; then - # echo last bytes are undefined - # bytes received by the interface. will be used next time. - last_rxBytes="$rxBytes" - # bytes sent by the interface. will be used next time. - last_txBytes="$txBytes" - # don't write data this round. we need a full minute of bytes to calculate cross traffic. - return - fi - - # bytes received since last time. - local rx=$(($rxBytes - $last_rxBytes)) - # bytes transmitted since last time - local tx=$(($txBytes - $last_txBytes)) - # if subtraction created a negative value, it means it has overflown or interface has been restarted. - # we skip this measure. - ([ "$rx" -lt 0 ] || [ "$tx" -lt 0 ]) && return - # saves current interface bytes value as last value. - last_rxBytes=$rxBytes - # saves current interface bytes value as last value. - last_txBytes=$txBytes - # if ping could not be executed, we skip this measure. - [ "$pingError" -eq 2 ] && return; + [ "$pingError" -eq 2 ] && burstLoss=0 && pingAndWan=0 && return # An skipped measure will become missing data, for this minute, in the server. @@ -72,171 +66,189 @@ collect_QoE_Monitor_data() { # local loss=${pingResult%\% packet loss*} # removes everything after, and including, '% packet loss'. # loss=${loss##* } # removes everything before first space. - local string="$timestamp $loss $transmitted $rx $tx" # data to be sent. - - # if latency collecting is enabled. - if [ "$hasLatency" -eq 1 ]; then - # echo collecting latencies - # removing the first line and the last 4 lines. only the ping lines remain. - local latencies=$(printf "%s" "$pingResult" | head -n -4 | sed '1d' | ( - local pairs="" - local firstLine=true - # for each ping line. - while read line; do - # removes 'time=' part if it exists. - reached=${line%time=*} - # if "time=" has actually been removed, it means that line - # contains it, which also means the icmp request was fulfilled. - # if line doesn't contain 'time=', skip this line. - [ ${#reached} -lt ${#line} ] || continue - - # from the whole line, removes everything until, and including, "icmp_req=". - pingNumber=${line#*icmp_*eq=} - # removes everything after the first space. - pingNumber=${pingNumber%% *} - # from the whole line, removes everything until, and including, "time=". - pingTime=${line#*time=} - # removes everything after the first space. - pingTime=${pingTime%% *} - if [ "$firstLine" = true ]; then - firstLine=false - else - pairs="${pairs}," - fi - # concatenate to $string. - pairs="${pairs}${pingNumber}=${pingTime}" - done - # prints final $string in this sub shell back to $string. - echo $pairs)) - # appending latencies to string to be sent. - string="${string} ${latencies}" + # data to be sent. + local s="$loss $transmitted" + + # latency stats + local lat=${pingResult#*/mdev = } + + # when there is 100% packet loss there the strings remain equal + # we only want to collect latency and std when there isn't 100% loss + # if loss is 100% we just send 0 in both cases, which will be ignored by the server + if [ ${#lat} = ${#pingResult} ]; then + s="$s 0 0" + else + # removes everything before first backslash + local avg=${lat#*/} + # removes everything after first backslash + avg=${avg%%/*} + # removes everything before and including last backslash + local std=${lat##*/} + # removes everything after and including first space + std=${std%% *} + + s="$s $avg $std" fi - # printf "string is: '%s'\n" "$string" + # # if latency collecting is enabled. + # if [ "$hasLatency" -eq 1 ]; then + # # echo collecting latencies + # # removing the first line and the last 4 lines. only the ping lines remain. + # local latencies=$(printf "%s" "$pingResult" | head -n -4 | sed '1d' | ( + # local pairs="" + # local firstLine=true + # # for each ping line. + # while read line; do + # # removes 'time=' part if it exists. if it doesn't, '$reached' will be as long as '$line'. + # reached=${line%time=*} + # # if "time=" has actually been removed, it means that line + # # contains it, which also means the icmp request was fulfilled. + # # if line doesn't contain 'time=', we skip this line. + # [ ${#reached} -lt ${#line} ] || continue + + # # from the whole line, removes everything until, and including, "icmp_req=". + # pingNumber=${line#*icmp_*eq=} + # # removes everything after the first space. + # pingNumber=${pingNumber%% *} + # # from the whole line, removes everything until, and including, "time=". + # pingTime=${line#*time=} + # # removes everything after the first space. + # pingTime=${pingTime%% *} + # if [ "$firstLine" = true ]; then + # firstLine=false + # else + # pairs="${pairs}," + # fi + # # concatenate to $string. + # pairs="${pairs}${pingNumber}=${pingTime}" + # done + # # prints final $string in this sub shell back to $string. + # echo $pairs)) + # # appending latencies to string to be sent. + # [ ${#latencies} -gt 0 ] && string="${string} ${latencies}" + # fi + # appending string to file. - echo "$string" >> "$rawDataFile"; + # printf "string is: '%s'\n" "$string" + rawData="${rawData}|burstPing $s" } -# prints the size of a file, using 'ls', where full file path is given as -# first argument ($1). -fileSize() { - # file size is the information at the 1st column. - local wcline=$(wc -c "$1") - #remove suffix composed of space and anything else. - local size=${wcline% *} - echo $size -} +wifi() { + # checking if this data collecting is enabled + [ "$wifiDevices" -eq 0 ] && return -# prints the sum of the sizes of all files inside given directory path. -sumFileSizesInPath() { - # boolean that marks that at least one file exists inside given directory. - local anyFile=false - # for each file in that directory. - for i in "$1"/*; do - # if that pattern expansion exists as a file. - [ -f "$i" ] || continue - # set boolean to true. - anyFile=true - # as we have at least one file, we don't need to loop through all files. - break - done - if [ "$anyFile" = false ]; then - # if no files. - # prints zero. size of nothing is 0. - echo 0 - # result was given, we can leave function. - return 0 - fi - # if there is at least one file. - - # prints a list of sizes and files. - local wcResult=$(wc -c "$1"/*) - # if there is 2 or more files, the last line will have a "total". remove that string. - local hasTotal=${wcResult% total} - # if it has a total, it was removed. if not, nothing was removed and both strings are the same. - - # if length of string with "total" removed is smaller than original string. - if [ ${#hasTotal} -lt ${#wcResult} ]; then - # remove everything before the last word, which is the value for total, and print what remains. - echo ${hasTotal##* } - else - # if there were no total, then there was only one file, in one line of output, and the first column is the size value. - # remove everything past, and including, the first space, and print what remains. - echo ${wcResult%% *} - fi -} + # devices and their data will be stored in this string variable. + local s="" -# sum the size $rawDataFile with the size of all compressed files inside the $compressedDataDir. if that -# sum is bigger than number given in first argument ($1), compress that file and move it to $compressedDataDir. -zipFile() { - local capSize="$1" - - # if file doesn't exist, we won't have to compressed anything. - # a return of 1 means nothing has been be gzipped. - [ -f "$rawDataFile" ] || return 1 - - # size of file with raw data. - local size=$(fileSize "$rawDataFile") - # sum of file sizes in directory for compressed files. - local dirSize=$(sumFileSizesInPath "$compressedDataDir") - - # if sum is smaller than $capSize, do nothing. - # echo checking file size to zip - # a return of 1 means nothing will be gzipped. - if [ $(($size + $dirSize)) -lt $capSize ]; then return 1; fi - - # compressing file where raw data is held. - gzip "$rawDataFile" - # move newly compressed file to directory where compressed files should be. - mv "${rawDataFile}.gz" "$compressedDataDir/$(date +%s).gz" -} + local first=1 + + # 0 and 1 are the indexes for wifi interfaces: wlan0 and wlan1, or phy0 and phy1. + for i in 0 1; do + # getting wifi interface name. + # 'get_root_ifname()' is defined in /usr/share/functions/custom_wireless_driver.sh. + local w=$(get_root_ifname "$i" 2> /dev/null) + # if interface doesn't exist, skips this iteration. + [ -z "$w" ] && continue + # getting info from each connected device on wifi. + # grep returns empty when no devices are connected or if interface doesn't exist. + local iw="$(iwinfo "$w" assoclist | grep ago)" + local pr="$(iwinfo "$w" assoclist | grep RX | grep -o '[0-9]\+ Pkts')" + local pt="$(iwinfo "$w" assoclist | grep TX | grep -o '[0-9]\+ Pkts')" + + while [ ${#iw} -gt 0 ]; do + + # getting everything before the first space. + local mac=${iw%% *} + + # getting everything after the first two spaces. + local sig=${iw#* } + + # getting everything before the first occasion of ' /' + sig=${sig%% /*} + + # if unknown discard + [ "$sig" = "unknown" ] && iw=${iw#*ago} && iw=${iw#*$'\n'} && continue + + # getting everything before the first occasion of ' dBm' + sig=${sig%% dBm*} + + # getting after '(SNR '. + iw=${iw#*\(SNR } + + # getting everything before the first closing parenthesis. + local snr=${iw%%\)*} -# files are removed from $compressedDataDir until all data remaining is below number given in first -# argument ($1) as bytes. As files are named using a formatted date, pattern expansion of file -# names will always order oldest files first. This was done this way so we don't have to sort files -# by date ourselves. we let shell do the sorting. -removeOldFiles() { - local capSize="$1" - - # get the sum of sizes of all files in bytes. - local dirSize=$(sumFileSizesInPath "$compressedDataDir") - - # if $dirSize is more than given $capSize, remove oldest file. which is - # the file that shell orders as first. - for i in "$compressedDataDir"/*; do - # if we are under $capSize. do nothing. - [ $dirSize -lt $capSize ] && break; - # removes that file. - rm "$i" - # subtract that file's size from sum. - dirSize=$(($dirSize - $(fileSize "$i"))) + # if SNR equals sig we assume noise of -95dBm + [ $sig -eq $snr ] && snr=$(($sig+95)) + + # getting everything before ' ms'. + local ts=${iw%% ms*} + + # getting everything after the first space. + ts=${ts##* } + + # getting everything after 'ago'. + iw=${iw#*ago} + + # getting everything after '\n', if it exists. last line won't have it, so nothing will be changed. + # we can't add the line feed along witht the previous parameter expansion because we wouldn't match + # the last line and so we wouldn't make $iw length become zero. + iw=${iw#*$'\n'} + + # if $ts is greater than one minute, we don't use this device's info. + [ "$ts" -gt 60000 ] && continue + + local r=${pr%% *} + pr=${pr#*$'\n'} + + local t=${pt%% *} + pt=${pt#*$'\n'} + + [ -z "$r" ] && continue + [ -z "$t" ] && continue + + # if it's the first data we are storing, don't add a space before appending the data string. + [ "$first" -eq 1 ] && first=0 || s="$s " + s="${s}${i}_${mac}_${sig}_${snr}_${r}_${t}" + done done + # only send data if there is something to send + [ -z "$s" ] && wifiDevices=0 || rawData="${rawData}|wifiDevsStats ${s}" } # collect every data and stores in '$rawDataFile'. if the size of the file is # too big, compress it and move it to a directory of compressed files. If # directory of compressed files grows too big delete oldest compressed files. collectData() { - collect_QoE_Monitor_data - - # $(zipFile) returns 0 only if any amount of files has been compressed - # and, consequently, moved to the directory of compressed files. So - # $(removeOldFiles) is only executed if any new compressed file was - # created. - - # creates directory of for compressed files, if it doesn't already exists. - mkdir -p "$compressedDataDir" - zipFile $((32*1024)) && removeOldFiles $((24*1024)) - # the difference between the cap size sent to $(zipFile) and - # $(removeOldFiles) is the size left as a minimum amount for raw data - # before compressing it. This means that, if there are no compressed files, - # the uncompressed file could grow to as much as the cap size given to - # $(zipFile). but in case there is any amount of compressed files, the - # uncompressed file can grow to as much as the cap size given to $(zipFile) - # minus the sum of all the compressed files sizes. As $(removeOldFiles) - # will keep the sum of all compressed files sizes to a maximum of its given - # cap size, the difference between these two cap sizes is the minimum size - # the uncompressed file will always have available for it's growth. + # getting current unix time in seconds. + local ts=$(date +%s) + + # global variable where current raw data is stored before being written to file. + rawData="" + + # collecting all measures. + burst + wan + wifi + + # global variable that controls which measures are active + on="" + + [ "$burstLoss" -eq 1 ] && on="${on}bl " + [ "$wifiDevices" -eq 1 ] && on="${on}wd " + [ "$pingAndWan" -eq 1 ] && on="${on}p&w " + [ ${#on} -gt 0 ] && on=${on%* } + + # mapping from measurement names to collected artifacts: + # bl (burstLoss) -> burstPing, wanBytes + # p&w (pingAndWan) -> burstPing, wanBytes, wanPkts + # wd (wifiDevices) -> wifiDevsStats + + # example of an expected raw data with all measures present: + # 'bl p&w wd|213234556456|burstPing 0 100 1.246 0.161|wanBytes 12345 1234|wanPkts 1234 123|wifiDevsStats 0_D0:9C:7A:EC:FF:FF_33_285_5136' + [ -n "$rawData" ] && [ ${#on} -gt 0 ] && echo "${on}|${ts}${rawData}" >> "$rawDataFile"; + # cleaning 'rawData' value from memory. + rawData="" } # if number given as first argument ($1) isn't 0, ping server at address given @@ -257,41 +269,26 @@ checkServerState() { # sends file at given path ($1) to server at given address ($2) using $(curl) # and returns $(curl) exit code. sendToServer() { - local filepath="$1" oldData="$2" + local filepath="$1" - # defined in /usr/share/functions/device_functions.sh + # 'get_mac()' is defined in /usr/share/functions/device_functions.sh. local mac=$(get_mac); - # removing all colons in mac address. - mac=${mac//:/} status=$(curl --write-out '%{http_code}' -s -m 20 --connect-timeout 5 --output /dev/null \ -XPOST "https://$alarmServerAddress:7890/data" -H 'Content-Encoding: gzip' \ -H 'Content-Type: text/plain' -H "X-ANLIX-ID: $mac" -H "X-ANLIX-SEC: $FLM_CLIENT_SECRET" \ -H "Send-Time: $(date +%s)" --data-binary @"$filepath") curlCode="$?" - [ "$curlCode" -ne 0 ] && log "DATA_COLLECTING" "Data sent with curl exit code $curlCode" && return "$curlCode" - log "DATA_COLLECTING" "Data sent with response status code $status." + # 'log()' is defined in /usr/share/functions/common_functions.sh. + [ "$curlCode" -ne 0 ] && log "DATA_COLLECTING" "Data sent with curl exit code '${curlCode}'." && return "$curlCode" + log "DATA_COLLECTING" "Data sent with response status code '${status}'." [ "$status" -ge 200 ] && [ "$status" -lt 300 ] && return 0 return 1 } -# for each compressed file given in $compressedDataDir, send that file to a $alarmServerAddress. -# If any sending is unsuccessful, stops sending files and return it's exit code. -sendCompressedData() { - # echo going to send compressed files - # echo "$compressedDataDir"/* - # for each compressed file in the pattern expansion. - for i in "$compressedDataDir"/*; do - # if file exists, sends file and if $(curl) exit code isn't equal to 0, returns $(curl) exit code - # without deleting the file we tried to send. if $(curl) exit code is equal to 0, removes file - [ -f "$i" ] && (sendToServer "$i" "1" || return "$?") && rm "$i" - done - return 0 -} - # compresses $rawDataFile, sends it to $alarmServerAddress and deletes it. If send was # successful, remove original files, if not, keeps it. Returns the return of $(curl). -sendUncompressedData() { +upload() { # if no uncompressed file, nothing wrong, but there's nothing to do in this function. [ -f "$rawDataFile" ] || return 0 @@ -307,7 +304,7 @@ sendUncompressedData() { gzip -k "$rawDataFile" # sends compressed file. - sendToServer "$compressedTempFile" "0" + sendToServer "$compressedTempFile" # storing $(curl) exit code. local sentResult="$?" @@ -371,7 +368,7 @@ sendData() { [ -f "$lastServerStateFilePath" ] && lastServerState=$(cat "$lastServerStateFilePath") # echo lastServerState=$lastServerState - checkServerState "$lastServerState" && sendCompressedData && sendUncompressedData + checkServerState "$lastServerState" && upload local currentServerState="$?" # echo currentServerState=$currentServerState # if server stops before sending some data, current server state will differ from last server state. @@ -469,16 +466,17 @@ loop() { # making sure directory exists every time. mkdir -p "$dataCollectingDir" - # getting FQDNs every time we need to send data, this way we don't have to - # restart the service if a fqdn changes. + # getting parameters every time we need to send data, this way we don't have to + # restart the service if a parameter changes. eval $(cat /root/flashbox_config.json | jsonfilter \ -e "hasLatency=@.data_collecting_has_latency" \ -e "alarmServerAddress=@.data_collecting_alarm_fqdn" \ -e "pingServerAddress=@.data_collecting_ping_fqdn" \ - -e "pingPackets=@.data_collecting_ping_packets") - # echo json variables: \ - # hasLatency="$hasLatency", alarmServerAddress="$alarmServerAddress", \ - # pingServerAddress="$pingServerAddress", pingPackets="$pingPackets" + -e "pingPackets=@.data_collecting_ping_packets" \ + -e "burstLoss=@.data_collecting_burst_loss" \ + -e "wifiDevices=@.data_collecting_wifi_devices" \ + -e "pingAndWan=@.data_collecting_ping_and_wan" \ + ) # does everything related to collecting and storing data.` collectData diff --git a/files/usr/share/flashman_update.sh b/files/usr/share/flashman_update.sh index 1fba6414..d85e3b64 100644 --- a/files/usr/share/flashman_update.sh +++ b/files/usr/share/flashman_update.sh @@ -245,10 +245,12 @@ mem_usage=$(get_memory_usage)" json_get_var _upnp_devices_index upnp_devices_index json_get_var _vlan_index vlan_index json_get_var _data_collecting_is_active data_collecting_is_active - json_get_var _data_collecting_has_latency data_collecting_has_latency json_get_var _data_collecting_alarm_fqdn data_collecting_alarm_fqdn json_get_var _data_collecting_ping_fqdn data_collecting_ping_fqdn json_get_var _data_collecting_ping_packets data_collecting_ping_packets + json_get_var _data_collecting_burst_loss data_collecting_burst_loss + json_get_var _data_collecting_wifi_devices data_collecting_wifi_devices + json_get_var _data_collecting_ping_and_wan data_collecting_ping_and_wan json_get_var _bridge_mode_enabled bridge_mode_enabled json_get_var _bridge_mode_switch_disable bridge_mode_switch_disable json_get_var _bridge_mode_ip bridge_mode_ip @@ -517,9 +519,11 @@ mem_usage=$(get_memory_usage)" fi # updates data collecting parameters. - set_data_collecting_parameters "$_data_collecting_is_active" "$_data_collecting_has_latency" \ + set_data_collecting_parameters "$_data_collecting_is_active" \ "$_data_collecting_alarm_fqdn" "$_data_collecting_ping_fqdn" \ - "$_data_collecting_ping_packets" + "$_data_collecting_ping_packets" "$_data_collecting_burst_loss" \ + "$_data_collecting_wifi_devices" "$_data_collecting_ping_and_wan" + # Check for updates in port forward mapping # Ignore changes if in bridge mode diff --git a/files/usr/share/functions/data_collecting_functions.sh b/files/usr/share/functions/data_collecting_functions.sh index 61b72027..be2d1d5f 100644 --- a/files/usr/share/functions/data_collecting_functions.sh +++ b/files/usr/share/functions/data_collecting_functions.sh @@ -6,18 +6,22 @@ # 'saved_data_collecting_is_active' parameter. set_data_collecting_parameters() { local data_collecting_is_active="${1:-0}" - local data_collecting_has_latency="${2:-0}" - local data_collecting_alarm_fqdn="${3:-$FLM_SVADDR}" - local data_collecting_ping_fqdn="${4:-$FLM_SVADDR}" - local data_collecting_ping_packets="${5:-100}" + local data_collecting_alarm_fqdn="${2:-$FLM_SVADDR}" + local data_collecting_ping_fqdn="${3:-$FLM_SVADDR}" + local data_collecting_ping_packets="${4:-100}" + local data_collecting_burst_loss="${5:-0}" + local data_collecting_wifi_devices="${6:-0}" + local data_collecting_ping_and_wan="${7:-0}" json_cleanup json_load_file /root/flashbox_config.json json_get_var saved_data_collecting_is_active data_collecting_is_active - json_get_var saved_data_collecting_has_latency data_collecting_has_latency json_get_var saved_data_collecting_alarm_fqdn data_collecting_alarm_fqdn json_get_var saved_data_collecting_ping_fqdn data_collecting_ping_fqdn json_get_var saved_data_collecting_ping_packets data_collecting_ping_packets + json_get_var saved_data_collecting_burst_loss data_collecting_burst_loss + json_get_var saved_data_collecting_wifi_devices data_collecting_wifi_devices + json_get_var saved_data_collecting_ping_and_wan data_collecting_ping_and_wan local anyChange=false @@ -25,35 +29,49 @@ set_data_collecting_parameters() { if [ "$saved_data_collecting_is_active" != "$data_collecting_is_active" ]; then anyChange=true json_add_boolean data_collecting_is_active "$data_collecting_is_active" - log "DATA_COLLECTING" "Updated 'data_collecting_is_active' parameter to '$data_collecting_is_active'" - fi - - # Updating value if $data_collecting_has_latency has changed. - if [ "$saved_data_collecting_has_latency" != "$data_collecting_has_latency" ]; then - anyChange=true - json_add_boolean data_collecting_has_latency "$data_collecting_has_latency" - log "DATA_COLLECTING" "Updated 'data_collecting_has_latency' parameter to '$data_collecting_has_latency'" + log "DATA_COLLECTING" "Updated 'data_collecting_is_active' parameter to '$data_collecting_is_active'." fi # Updating value if $data_collecting_alarm_fqdn has changed. if [ "$saved_data_collecting_alarm_fqdn" != "$data_collecting_alarm_fqdn" ]; then anyChange=true json_add_string data_collecting_alarm_fqdn "$data_collecting_alarm_fqdn" - log "DATA_COLLECTING" "Updated 'data_collecting_alarm_fqdn' parameter to '$data_collecting_alarm_fqdn'" + log "DATA_COLLECTING" "Updated 'data_collecting_alarm_fqdn' parameter to '$data_collecting_alarm_fqdn'." fi # Updating value if $data_collecting_ping_fqdn has changed. if [ "$saved_data_collecting_ping_fqdn" != "$data_collecting_ping_fqdn" ]; then anyChange=true json_add_string data_collecting_ping_fqdn "$data_collecting_ping_fqdn" - log "DATA_COLLECTING" "Updated 'data_collecting_ping_fqdn' parameter to '$data_collecting_ping_fqdn'" + log "DATA_COLLECTING" "Updated 'data_collecting_ping_fqdn' parameter to '$data_collecting_ping_fqdn'." fi - # Updating value if $data_collecting_alarm_fqdn has changed. + # Updating value if $data_collecting_ping_packets has changed. if [ "$saved_data_collecting_ping_packets" != "$data_collecting_ping_packets" ]; then anyChange=true json_add_int data_collecting_ping_packets "$data_collecting_ping_packets" - log "DATA_COLLECTING" "Updated 'data_collecting_ping_packets' parameter to '$data_collecting_ping_packets'" + log "DATA_COLLECTING" "Updated 'data_collecting_ping_packets' parameter to '$data_collecting_ping_packets'." + fi + + # Updating value if $data_collecting_burst_loss has changed. + if [ "$saved_data_collecting_burst_loss" != "$data_collecting_burst_loss" ]; then + anyChange=true + json_add_boolean data_collecting_burst_loss "$data_collecting_burst_loss" + log "DATA_COLLECTING" "Updated 'data_collecting_burst_loss' parameter to '$data_collecting_burst_loss'." + fi + + # Updating value if $data_collecting_wifi_devices has changed. + if [ "$saved_data_collecting_wifi_devices" != "$data_collecting_wifi_devices" ]; then + anyChange=true + json_add_boolean data_collecting_wifi_devices "$data_collecting_wifi_devices" + log "DATA_COLLECTING" "Updated 'data_collecting_wifi_devices' parameter to '$data_collecting_wifi_devices'." + fi + + # Updating value if $data_collecting_ping_and_wan has changed. + if [ "$saved_data_collecting_ping_and_wan" != "$data_collecting_ping_and_wan" ]; then + anyChange=true + json_add_boolean data_collecting_ping_and_wan "$data_collecting_ping_and_wan" + log "DATA_COLLECTING" "Updated 'data_collecting_ping_and_wan' parameter to '$data_collecting_ping_and_wan'." fi # saving config json if any parameter has changed. @@ -62,12 +80,12 @@ set_data_collecting_parameters() { json_cleanup - # "true" boolean value is translated as string "1" by jshn.sh - # "false" boolean value is translated as string "0" by jshn.sh - if [ "$data_collecting_is_active" = "1" ] && [ "$data_collecting_ping_fqdn" != "" ]; then - # reload won't restart data collecting service if it's already running. - /etc/init.d/data_collecting reload - elif [ "$data_collecting_is_active" != "1" ]; then - /etc/init.d/data_collecting stop 2>/dev/null - fi + # "true" boolean value is translated as string "1" by jshn.sh when variable is read. + # "false" boolean value is translated as string "0" by jshn.sh when variable is read. + + # if data collecting service is active, reloads data_collecting service (which does + # nothing if it's already running), else stops service. data_collecting service reads + # it's configuration variables at each iteration (which happens once every minute). + [ "$data_collecting_is_active" -eq 1 ] && \ + /etc/init.d/data_collecting reload || /etc/init.d/data_collecting stop > /dev/null 2>&1 } diff --git a/files/usr/share/functions/device_functions.sh b/files/usr/share/functions/device_functions.sh index 59556e24..8c3d93bc 100644 --- a/files/usr/share/functions/device_functions.sh +++ b/files/usr/share/functions/device_functions.sh @@ -225,7 +225,7 @@ get_lan_dev_negotiated_speed() { echo "$_speed" } -get_wan_statistics() { +get_wan_bytes_statistics() { local _param=$1 if [ "$(lsmod | grep hwnat)" ] @@ -262,6 +262,20 @@ get_wan_statistics() { fi } +get_wan_packets_statistics() { + local _param=$1 + local _wan=$(get_wan_device) + if [ -f /sys/class/net/$_wan/statistics/tx_packets ] + then + case "$1" in + "TX") echo "$(cat /sys/class/net/$_wan/statistics/rx_packets)" ;; + "RX") echo "$(cat /sys/class/net/$_wan/statistics/tx_packets)" ;; + esac + else + echo "0" + fi +} + needs_reboot_change_mode() { reboot } diff --git a/files/usr/share/functions/network_functions.sh b/files/usr/share/functions/network_functions.sh index 92f6462a..ec7a870e 100644 --- a/files/usr/share/functions/network_functions.sh +++ b/files/usr/share/functions/network_functions.sh @@ -627,8 +627,8 @@ set_use_dns_proxy() { store_wan_bytes() { local _epoch=$(date +%s) - local _wan_rx=$(get_wan_statistics RX) - local _wan_tx=$(get_wan_statistics TX) + local _wan_rx=$(get_wan_bytes_statistics RX) + local _wan_tx=$(get_wan_bytes_statistics TX) json_init diff --git a/files/usr/share/keepalive.sh b/files/usr/share/keepalive.sh index e136289f..df4cb824 100755 --- a/files/usr/share/keepalive.sh +++ b/files/usr/share/keepalive.sh @@ -119,10 +119,12 @@ mem_usage=$(get_memory_usage)" json_get_var _do_newprobe do_newprobe json_get_var _mqtt_status mqtt_status json_get_var _data_collecting_is_active data_collecting_is_active - json_get_var _data_collecting_has_latency data_collecting_has_latency json_get_var _data_collecting_alarm_fqdn data_collecting_alarm_fqdn json_get_var _data_collecting_ping_fqdn data_collecting_ping_fqdn json_get_var _data_collecting_ping_packets data_collecting_ping_packets + json_get_var _data_collecting_burst_loss data_collecting_burst_loss + json_get_var _data_collecting_wifi_devices data_collecting_wifi_devices + json_get_var _data_collecting_ping_and_wan data_collecting_ping_and_wan json_close_object if [ "$_do_newprobe" = "1" ] @@ -171,9 +173,10 @@ mem_usage=$(get_memory_usage)" fi # updates data collecting parameters. - set_data_collecting_parameters "$_data_collecting_is_active" "$_data_collecting_has_latency" \ + set_data_collecting_parameters "$_data_collecting_is_active" \ "$_data_collecting_alarm_fqdn" "$_data_collecting_ping_fqdn" \ - "$_data_collecting_ping_packets" + "$_data_collecting_ping_packets" "$_data_collecting_burst_loss" \ + "$_data_collecting_wifi_devices" "$_data_collecting_ping_and_wan" elif [ $_retstatus -eq 2 ] then diff --git a/files/usr/share/lua/config.lua b/files/usr/share/lua/config.lua index 153b2247..53df79b3 100644 --- a/files/usr/share/lua/config.lua +++ b/files/usr/share/lua/config.lua @@ -112,5 +112,4 @@ function handle_config(command, data) end end end - end diff --git a/files/usr/share/mqtt.sh b/files/usr/share/mqtt.sh index 9e920741..d55f0e0b 100644 --- a/files/usr/share/mqtt.sh +++ b/files/usr/share/mqtt.sh @@ -5,7 +5,6 @@ . /usr/share/functions/dhcp_functions.sh . /usr/share/functions/api_functions.sh . /usr/share/functions/wireless_functions.sh -. /usr/share/functions/data_collecting_functions.sh case "$1" in 1) @@ -48,14 +47,6 @@ ping) log "MQTTMSG" "Running ping test" run_ping_ondemand_test ;; -datacollecting) - log "MQTTMSG" "Changing data collecting settings" - set_data_collecting_on_off "$2" - ;; -collectlatency) - log "MQTTMSG" "Changing the collecting of latencies when collecting data" - set_collect_latency "$2" - ;; status) if lock -n /tmp/get_status.lock then