iopsys-feed/qosmngr/files/usr/libexec/rpcd/qos

180 lines
3.3 KiB
Bash
Executable file

#!/bin/sh
. /usr/share/libubox/jshn.sh
bcom_get_queue_stats() {
json_init
json_add_array "queues"
i=0
while :
do
ifname=$(uci -q get qos.@queue[$i].ifname)
# if ifname is empty that is good enough to break
if [ -z "$ifname" ];then
break
fi
order=$(uci -q get qos.@queue[$i].precedence)
stats="$(tmctl getqstats --devtype 0 --if $ifname --qid $order)"
ret="$(echo $stats | awk '{print substr($0,0,5)}')"
#check tmctl ERROR condition
if [ $ret == 'ERROR' ]; then
i=$((i + 1))
continue
fi
json_add_object ""
json_add_string "qid" "$order"
json_add_string "iface" "$ifname"
IFS=$'\n'
for stat in $stats; do
pname="$(echo $stat | awk '{print$1}')"
if [ $pname == 'ret' ]; then
continue
fi
val="$(echo $stat | awk '{print$2}')"
# remove trailing : from the name
pname="${pname::-1}"
# convert to iopsyswrt names
case "$pname" in
txPackets)
json_add_string "tx_packets" "$val"
;;
txBytes)
json_add_string "tx_bytes" "$val"
;;
droppedPackets)
json_add_string "tx_dropped_packets" "$val"
;;
droppedBytes)
json_add_string "tx_dropped_bytes" "$val"
;;
esac
done
json_close_object
i=$((i + 1))
done
json_close_array
json_dump
}
bcom_get_eth_q_stats() {
i=0
key_ifname=$1
key_queue=$2
json_init
json_add_array "queues"
while :
do
ifname=$(uci -q get qos.@queue[$i].ifname)
# if ifname is empty that is good enough to break
if [ -z "$ifname" ];then
break
fi
order=$(uci -q get qos.@queue[$i].precedence)
#proceed only if given interface and queue matches
if [ $ifname != $key_ifname ] || [ $order != $key_queue ]; then
i=$((i + 1))
continue
fi
stats="$(tmctl getqstats --devtype 0 --if $ifname --qid $order)"
ret="$(echo $stats | awk '{print substr($0,0,5)}')"
#check tmctl ERROR condition
if [ $ret == 'ERROR' ]; then
i=$((i + 1))
continue
fi
json_add_object ""
json_add_string "qid" "$order"
json_add_string "iface" "$ifname"
IFS=$'\n'
for stat in $stats; do
pname="$(echo $stat | awk '{print$1}')"
if [ $pname == 'ret' ]; then
continue
fi
val="$(echo $stat | awk '{print$2}')"
# remove trailing : from the name
pname="${pname::-1}"
# convert to iopsyswrt names
case "$pname" in
txPackets)
json_add_string "tx_packets" "$val"
;;
txBytes)
json_add_string "tx_bytes" "$val"
;;
droppedPackets)
json_add_string "tx_dropped_packets" "$val"
;;
droppedBytes)
json_add_string "tx_dropped_bytes" "$val"
;;
esac
done
json_close_object
i=$((i + 1))
done
json_close_array
json_dump
}
get_queue_stats() {
if [ "$(which tmctl)" ]; then
bcom_get_queue_stats
fi
}
get_eth_q_stats() {
if [ "$(which tmctl)" ]; then
param1=$1
param2=$2
echo "param1: $param1 param2: $param2" >> /usr/libexec/rpcd/output
bcom_get_eth_q_stats $param1 $param2
fi
}
case "$1" in
list)
echo '{ "eth_q_stats": { "eth": "str", "queue": "str", }, "queue_stats": { } }'
;;
call)
case "$2" in
eth_q_stats)
# read the arguments
read input;
json_load "$input"
json_get_var iface eth
json_get_var q queue
echo "arg1: $iface" > /usr/libexec/rpcd/output
echo "arg2: $q" >> /usr/libexec/rpcd/output
get_eth_q_stats $iface $q
;;
queue_stats)
get_queue_stats
;;
esac
;;
esac