qosify-status 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/sh
  2. . /usr/share/libubox/jshn.sh
  3. dev_status() {
  4. tc -s qdisc sh dev "$1" root
  5. echo
  6. }
  7. common_status() {
  8. json_get_vars ifname ingress egress
  9. [ -n "$ifname" ] || return
  10. [ "$egress" -gt 0 ] && {
  11. echo "egress status:"
  12. dev_status "$ifname"
  13. }
  14. [ "$ingress" -gt 0 ] && {
  15. echo "ingress status:"
  16. dev_status "$(printf %.16s "ifb-$ifname")"
  17. }
  18. }
  19. is_active() {
  20. json_get_vars active
  21. [ "${active:-0}" -gt 0 ]
  22. }
  23. device_status() {
  24. local name="$2"
  25. json_select "$name"
  26. if is_active; then
  27. status="active"
  28. else
  29. status="not found"
  30. fi
  31. echo "===== device $name: $status ====="
  32. is_active && common_status
  33. json_select ..
  34. }
  35. interface_status() {
  36. local name="$2"
  37. json_select "$name"
  38. if is_active; then
  39. status="active"
  40. elif ubus -S -t 0 wait_for "network.interface.$name"; then
  41. status="down"
  42. else
  43. status="not found"
  44. fi
  45. echo "===== interface $name: $status ====="
  46. is_active && common_status
  47. json_select ..
  48. }
  49. json_load "$(ubus call qosify status)"
  50. json_for_each_item device_status devices
  51. json_for_each_item interface_status interfaces