ffho-debug-live 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/bin/sh
  2. TEMP_DATA_FILE="/tmp/ffho-live-debug.dat"
  3. LIVE_DEBUG_TARGET_HOST="fdca:ffee:ff12:a254::da7a"
  4. LIVE_DEBUG_TARGET_HOST_PORT=1338
  5. LIVE_DEBUG_GRAPHITE_DATAPATH_BASE="ffho.debug."$(lua -e 'print(require("gluon.sysconfig").primary_mac)')
  6. . /etc/openwrt_release
  7. . /usr/share/libubox/jshn.sh
  8. determine_lan_device_name() {
  9. local _iface="$1"
  10. local _var="$2"
  11. json_load "$(ubus call network.interface.${_iface} status)"
  12. json_get_var is_up "up"
  13. if [ $is_up == 1 ] ; then
  14. json_get_var $_var "device"
  15. fi
  16. json_cleanup
  17. }
  18. determine_wifi_device_name()
  19. {
  20. local _iface="$1"
  21. local _var="$2"
  22. if [ "${DISTRIB_CODENAME}" == "attitude_adjustment" ] ; then
  23. eval "$_var=\"$(uci -P/var/state get wireless.${_iface}.ifname)\""
  24. else
  25. json_load "$(ubus call network.wireless status)"
  26. json_select "radio0"
  27. json_select "interfaces"
  28. local _idx=1
  29. while json_get_type type "$_idx" && [ "$type" = object ] ; do
  30. json_select "$(( _idx++ ))"
  31. json_get_var section "section"
  32. if [ "${section}" == "${_iface}" ] ; then
  33. json_get_var $_var "ifname"
  34. break
  35. fi
  36. json_select ".."
  37. done
  38. json_cleanup
  39. fi
  40. }
  41. get_device_stats() {
  42. local _dev="$1"
  43. rx_bytes="$2"
  44. tx_bytes="$3"
  45. rx_dropped="$4"
  46. tx_dropped="$5"
  47. json_select "${_dev}"
  48. json_select "statistics"
  49. json_get_vars rx_bytes tx_bytes rx_dropped tx_dropped
  50. json_select ".." && json_select ".."
  51. }
  52. gather_device_data() {
  53. local rx_bytes
  54. local ty_bytes
  55. local rx_dropped
  56. local tx_dropped
  57. json_load "$(ubus call network.device status)"
  58. if [ -n "{$DEV_MESH_RADIO_24}" ] ; then
  59. get_device_stats ${DEV_MESH_RADIO_24} rx_bytes tx_bytes rx_dropped tx_dropped
  60. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_radio0.rx_bytes ${rx_bytes} ${timestamp}" >> ${TEMP_DATA_FILE}
  61. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_radio0.tx_bytes ${tx_bytes} ${timestamp}" >> ${TEMP_DATA_FILE}
  62. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_radio0.rx_dropped ${rx_dropped} ${timestamp}" >> ${TEMP_DATA_FILE}
  63. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_radio0.tx_dropped ${tx_dropped} ${timestamp}" >> ${TEMP_DATA_FILE}
  64. fi
  65. if [ -n "{$DEV_CLIENT_RADIO_24}" ] ; then
  66. get_device_stats ${DEV_CLIENT_RADIO_24} rx_bytes tx_bytes rx_dropped tx_dropped
  67. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.client_radio0.rx_bytes ${rx_bytes} ${timestamp}" >> ${TEMP_DATA_FILE}
  68. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.client_radio0.tx_bytes ${tx_bytes} ${timestamp}" >> ${TEMP_DATA_FILE}
  69. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.client_radio0.rx_dropped ${rx_dropped} ${timestamp}" >> ${TEMP_DATA_FILE}
  70. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.client_radio0.tx_dropped ${tx_dropped} ${timestamp}" >> ${TEMP_DATA_FILE}
  71. fi
  72. if [ -n "${DEV_MESH_VPN}" ] ; then
  73. get_device_stats ${DEV_MESH_VPN} rx_bytes tx_bytes rx_dropped tx_dropped
  74. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_vpn.rx_bytes ${rx_bytes} ${timestamp}" >> ${TEMP_DATA_FILE}
  75. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_vpn.tx_bytes ${tx_bytes} ${timestamp}" >> ${TEMP_DATA_FILE}
  76. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_vpn.rx_dropped ${rx_dropped} ${timestamp}" >> ${TEMP_DATA_FILE}
  77. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_vpn.tx_dropped ${tx_dropped} ${timestamp}" >> ${TEMP_DATA_FILE}
  78. fi
  79. json_cleanup
  80. }
  81. gather_stations_data() {
  82. if [ -n "${DEV_CLIENT_RADIO_24}" ] ; then
  83. cnt_assoc_clients=$(iwinfo ${DEV_CLIENT_RADIO_24} assoclist | grep dBm | wc -l)
  84. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.cnt_assoc_clients ${cnt_assoc_clients} ${timestamp}" >> ${TEMP_DATA_FILE}
  85. fi
  86. if [ -n "${DEV_CLIENT_RADIO_24}" ] ; then
  87. cnt_client_stations=$(iw dev ${DEV_CLIENT_RADIO_24} station dump | grep ^Station | wc -l)
  88. echo ${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.cnt_client_stations ${cnt_client_stations} ${timestamp} >> ${TEMP_DATA_FILE}
  89. fi
  90. cnt_batman_clients=$(batctl tl | tail -n +3 | grep -v "\[\.P\.\.\.\]" | wc -l)
  91. echo ${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.cnt_batman_clients ${cnt_batman_clients} ${timestamp} >> ${TEMP_DATA_FILE}
  92. if [ -n "${DEV_MESH_RADIO_24}" ] ; then
  93. cnt_neighbours=$(iw dev ${DEV_MESH_RADIO_24} station dump | grep ^Station | wc -l)
  94. echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.cnt_neighbours ${cnt_neighbours} ${timestamp}" >> ${TEMP_DATA_FILE}
  95. fi
  96. }
  97. echo "Starting live-debug ... press Ctrl+C to abort."
  98. determine_wifi_device_name "mesh_radio0" DEV_MESH_RADIO_24
  99. determine_wifi_device_name "client_radio0" DEV_CLIENT_RADIO_24
  100. determine_lan_device_name "mesh_vpn" DEV_MESH_VPN
  101. while true; do
  102. timestamp=$(date +%s)
  103. date -R -d "${timestamp}"
  104. gather_device_data
  105. gather_stations_data
  106. nc "${LIVE_DEBUG_TARGET_HOST}" "${LIVE_DEBUG_TARGET_HOST_PORT}" < ${TEMP_DATA_FILE} && /bin/rm ${TEMP_DATA_FILE}
  107. sleep 5
  108. done