diff --git a/ffho/ffho-debug/ReadMe.md b/ffho/ffho-debug/ReadMe.md index 266969cfb547d53f79f3cd0c705bbb7a17d58f75..18518d61ed5ed8817883182cfc87850bcc780cb5 100644 --- a/ffho/ffho-debug/ReadMe.md +++ b/ffho/ffho-debug/ReadMe.md @@ -12,16 +12,12 @@ site.conf **debugserver.port:** - destination port for debug reports -**debugserver.liveport: optional** -- destination port for `ffho-debug-live` - ### example ```lua { debugserver = { host = { 'debugreport.ffho.net' }, port = 1337, - liveport = 1338, }, ... }, diff --git a/ffho/ffho-debug/files/bin/ffho-debug b/ffho/ffho-debug/files/bin/ffho-debug index 4b865c7a7c7b08a7013f126c701cd9ea5077e9fa..cf206d2010f3819f3fa5bb788ae5c56b17f716cd 100755 --- a/ffho/ffho-debug/files/bin/ffho-debug +++ b/ffho/ffho-debug/files/bin/ffho-debug @@ -4,10 +4,71 @@ debugdata = "" ATH9K_DEBUGFS_DIR="/sys/kernel/debug/ieee80211/phy0/ath9k" PATH_DBG_REPORT='/tmp/debug-report.txt' -local nixio = require('nixio'), require('nixio.util'), require('nixio.fs') +local nixio = require('nixio'), require('nixio.util') +local util = require("luci.util") +local fs = require("nixio.fs") +local ltn12 = require 'luci.ltn12' +local sys = require("luci.sys") +local json = require("luci.jsonc") +local platform_info = require("platform_info") +local site = require 'gluon.site_config' +local ip = require 'luci.ip' +local uci = require('luci.model.uci').cursor() + +-- some usefull functions +local hostname = sys.hostname() +local model = platform_info.get_model() +local release = util.trim(fs.readfile("/lib/gluon/release") or "") +local version = util.trim(fs.readfile("/lib/gluon/gluon-version") or "") +local primary_mac = require('gluon.sysconfig').primary_mac + +local contact = uci:get_first('gluon-node-info', 'owner', 'contact', '') +if contact == '' then + contact = "none" +end +local autoupdater = uci:get('autoupdater', 'settings', 'branch') +if uci:get_bool('autoupdater', 'settings', 'enabled') == false then + autoupdater = "disabled (" .. autoupdater .. ")" +end + +local addresses = "" +for line in io.lines('/proc/net/if_inet6') do + local matches = { line:match('^' .. string.rep('(%x%x%x%x)', 8) .. string.rep(' %x%x', 4) .. '%s+([^%s]+)$') } + if matches[9] == 'br-client' then + addresses = addresses .. " " .. ip.IPv6(string.format('%s:%s:%s:%s:%s:%s:%s:%s', unpack(matches))):string():lower() .. "\n" + end +end + +local data = io.open('/proc/meminfo'):read('*a') +local fields = {} +for k, v in data:gmatch('([^\n:]+):%s*(%d+) kB') do + fields[k] = tonumber(v) +end + +local function location() + local text = 'none' + local locationid = uci:get_first('gluon-node-info', 'location') + if locationid then + local location = uci:get_all('gluon-node-info', locationid) + if uci:get_bool('gluon-node-info', locationid, 'share_location') and location.latitude and location.longitude then + text = location.latitude .. ', ' .. location.longitude + end + end + return text +end + +local function ip_proto(address) + if address:match("%.") then + return "IPv4" + end + if address:match(":") then + return "IPv6" + end + return "???" +end -- wrapper for calling systemcommands -function cmd(_command) +local function cmd(_command) local f = io.popen(_command) local l = f:read("*a") f:close() @@ -15,7 +76,7 @@ function cmd(_command) end -- read contents of a given file -function readFile(_file) +local function readFile(_file) local f = io.open(_file, "r") if f~=nil then local l = f:read("*a") @@ -26,19 +87,8 @@ function readFile(_file) end end --- iterate through list -function list_iter (_table) - local i = 0 - local n = table.getn(_table) - return function () - i = i + 1 - if i <= n then return _table[i] end - end -end - -localMode = false - -- Should we enter local mode? +localMode = false if arg[1] == '-l' then localMode = true end @@ -47,18 +97,25 @@ end local oldReport = nixio.open(PATH_DBG_REPORT, "r") if oldReport==nil then -- no existing debugreport, let's generate a new one - + -- inform the User ;) print('-- Hello, Mr. Dillinger. Thank you for coming back early.') print('-- Sit right there; make yourself comfortable. Remember the time we spent play chess together?') - + -- first of all, collect some generic information about the system debugdata = debugdata .. "---- BEGIN SYSTEM INFORMATION ----\n" - debugdata = debugdata .. cmd("uname -n") - debugdata = debugdata .. cmd("cat /lib/gluon/release") - debugdata = debugdata .. cmd("cat /tmp/sysinfo/model") - debugdata = debugdata .. cmd("uptime") - debugdata = debugdata .. cmd("date") + debugdata = debugdata .. "Hostname: " .. hostname .. "\n" + debugdata = debugdata .. "Community: " .. site.site_name .. "\n" + debugdata = debugdata .. "Model: " .. model .. "\n" + debugdata = debugdata .. "Firmware: " .. release .. " / " .. version .. "\n" + debugdata = debugdata .. "MAC: " .. primary_mac .. "\n" + debugdata = debugdata .. "Contact: " .. contact .. "\n" + debugdata = debugdata .. "Uptime: " .. util.trim(sys.exec("uptime | sed 's/^ \+//'")) .. "\n" + debugdata = debugdata .. "Autoupdater: " .. autoupdater .. "\n" + debugdata = debugdata .. "Location: " .. location() .. "\n" + debugdata = debugdata .. "IPs: " .. util.trim(addresses) .. "\n" + debugdata = debugdata .. "Memory: " .. string.format("%.1f %% used, %.1f %% free\n",(fields.MemTotal-fields.MemFree)/fields.MemTotal*100,fields.MemFree/fields.MemTotal*100) + debugdata = debugdata .. cmd("ps w") debugdata = debugdata .. "---- END SYSTEM INFORMATION ----\n\n" @@ -67,64 +124,90 @@ if oldReport==nil then debugdata = debugdata .. cmd("uci show | grep -v '\.key' | grep -v '\.secret'") debugdata = debugdata .. "---- END UCI VARIABLES ----\n\n" + -- show cron jobs + debugdata = debugdata .. "---- BEGIN CRON JOBS ----\n" + debugdata = debugdata .. cmd("grep -r \"\" /usr/lib/micron.d/ | sed -e \"s/:/:\n/\"") + debugdata = debugdata .. "---- END CRON JOBS ----\n\n" + -- now get some information about the network status - debugdata = debugdata .. "---- BEGIN IP AND ROUTUNG INFORMATION ----\n" - debugdata = debugdata .. cmd("ip addr show") + debugdata = debugdata .. cmd("ip addr show") debugdata = debugdata .. cmd("ip route show") debugdata = debugdata .. cmd("ip -6 route show") debugdata = debugdata .. "---- BEGIN IP AND ROUTUNG INFORMATION ----\n\n" - debugdata = debugdata .. "---- BEGIN FIREWALL INFORMATION ----\n" - debugdata = debugdata .. cmd("iptables -t raw -L -v") - debugdata = debugdata .. cmd("iptables -t filter -L -v") - debugdata = debugdata .. cmd("iptables -t nat -L -v") - debugdata = debugdata .. cmd("iptables -t mangle -L -v") - debugdata = debugdata .. cmd("ip6tables -t raw -L -v") - debugdata = debugdata .. cmd("ip6tables -t filter -L -v") - debugdata = debugdata .. cmd("ip6tables -t mangle -L -v") - debugdata = debugdata .. "---- BEGIN FIREWALL INFORMATION ----\n\n" - -- get wireless status debugdata = debugdata .. "---- BEGIN WIRELESS INFORMATION ----\n" - debugdata = debugdata .. cmd("iw phy phy0 info") - debugdata = debugdata .. cmd("iw dev ibss0 info") - debugdata = debugdata .. cmd("iw dev ibss0 station dump") - debugdata = debugdata .. cmd("iw dev client0 station dump") - debugdata = debugdata .. cmd("iwinfo phy0 scan") - debugdata = debugdata .. cmd("iwinfo ibss0 info") - debugdata = debugdata .. cmd("iwinfo client0 info") - debugdata = debugdata .. cmd("iwinfo ibss0 assoclist") - debugdata = debugdata .. cmd("iwinfo client0 assoclist") + debugdata = debugdata .. cmd("iwinfo ibss0 info 2>&1") + debugdata = debugdata .. cmd("iwinfo client0 info 2>&1") + debugdata = debugdata .. cmd("iwinfo ibss1 info 2>&1") + debugdata = debugdata .. cmd("iwinfo client1 info 2>&1") + debugdata = debugdata .. cmd("iwinfo ibss0 assoclist 2>&1") + debugdata = debugdata .. cmd("iwinfo ibss1 assoclist 2>&1") debugdata = debugdata .. "---- END WIRELESS INFORMATION ----\n\n" - - -- try to get some more information about wlan hardware status - debugdata = debugdata .. "---- BEGIN HARDWARE STATUS ----\n" - _files = {"reset", "queues", "interrupt"} - for file in list_iter(_files) do - debugdata = debugdata .. readFile(ATH9K_DEBUGFS_DIR .. "/" .. file) + -- get batman status + debugdata = debugdata .. "---- BEGIN BATMAN STATUS ----\n" + debugdata = debugdata .. cmd("batctl gwl") + debugdata = debugdata .. cmd("batctl tl") + debugdata = debugdata .. "---- END BATMAN STATUS ----\n\n" + + -- get fastd status + debugdata = debugdata .. "---- BEGIN FASTD STATUS ----\n" + if string.len(util.exec("ip -f inet address show dev br-wan | grep global")) >= 2 then + debugdata = debugdata .. "IPv4 configured\n" + else + debugdata = debugdata .. "IPv4 not configured\n" end - - -- sleep ten seconds and read interrupt again - os.execute("sleep 10") - debugdata = debugdata .. readFile(ATH9K_DEBUGFS_DIR .. "/interrupt") - - _files = {"ani", "base_eeprom", "dma", "dump_nfcal", "misc", "modal_eeprom", "phy_err", "recv", "xmit"} - for file in list_iter(_files) do - debugdata = debugdata .. readFile(ATH9K_DEBUGFS_DIR .. "/" .. file) + + if string.len(util.exec("ip -f inet6 address show dev br-wan | grep global")) >= 2 then + debugdata = debugdata .. "IPv6 configured\n" + else + debugdata = debugdata .. "IPv6 not configured\n" end - debugdata = debugdata .. "---- END HARDWARE STATUS ----\n\n" - -- get batman status - debugdata = debugdata .. "---- BEGIN BATMAN AND FASTD STATUS ----\n" - debugdata = debugdata .. cmd("batctl gwl") - debugdata = debugdata .. cmd("batctl tl") - - -- finally get fastd status - os.execute("killall -USR1 fastd 2>/dev/null") + local stat, fastd_status = pcall( + function() + local fastd_sock = nixio.socket('unix', 'stream') + assert(fastd_sock:connect('/var/run/fastd.mesh_vpn.socket')) + + decoder = json.new() + ltn12.pump.all(ltn12.source.file(fastd_sock), decoder:sink()) + return decoder:get() + end + ) + + if stat then + debugdata = debugdata .. string.format("fastd running for %.3f seconds\n", fastd_status.uptime/1000) + + local peers = 0 + local connections = 0 + for key, peer in pairs(fastd_status.peers) do + peers = peers+1 + + if peer.connection then + connections = connections+1 + end + end + debugdata = debugdata .. string.format("There are %i peers configured, of which %i are connected:\n", peers, connections) + + for key, peer in pairs(fastd_status.peers) do + debugdata = debugdata .. peer.name .. ": " + if peer.connection then + debugdata = debugdata .. string.format("connected for %.3f seconds via %s\n", peer.connection.established/1000, ip_proto(peer.address)) + else + debugdata = debugdata .. "not connected\n" + end + end + else + debugdata = debugdata .. "fastd not running\n" + end + debugdata = debugdata .. "---- END FASTD STATUS ----\n\n" + + -- get log + debugdata = debugdata .. "---- BEGIN LOGREAD ----\n" debugdata = debugdata .. cmd("logread") - debugdata = debugdata .. "---- END BATMAN AND FASTD STATUS ----\n\n" + debugdata = debugdata .. "---- END LOGREAD ----\n\n" debugdata = debugdata .. "---- BEGIN DMESG KERNEL LOG ----\n" debugdata = debugdata .. cmd("dmesg") @@ -132,7 +215,7 @@ if oldReport==nil then else print('Orphaned debug-report file found.') print('-- You wouldn\'t want me to dig up Flynn\'s file and read it up on a VDT at The Times, would you?') - debugdata = oldReport:readall() + debugdata = oldReport:readall() oldReport:close() end @@ -149,7 +232,7 @@ else local sent = 0 local reportname = nil local port = siteConfig.debugserver.port - for host in list_iter(siteConfig.debugserver.host) do + for host in ipairs(siteConfig.debugserver.host) do print('Trying to deliver debug-report to: ' .. host) local sock = nixio.connect(host, port, "inet6", "stream") if sock then diff --git a/ffho/ffho-debug/files/bin/ffho-debug-live b/ffho/ffho-debug/files/bin/ffho-debug-live deleted file mode 100755 index 71e37bd917bbc199319301f74c41e3107a3816a0..0000000000000000000000000000000000000000 --- a/ffho/ffho-debug/files/bin/ffho-debug-live +++ /dev/null @@ -1,134 +0,0 @@ -#!/bin/sh - -TEMP_DATA_FILE="/tmp/ffho-live-debug.dat" -LIVE_DEBUG_TARGET_HOST="fdca:ffee:ff12:a254::da7a" -LIVE_DEBUG_TARGET_HOST_PORT=1338 -LIVE_DEBUG_GRAPHITE_DATAPATH_BASE="ffho.debug."$(lua -e 'print(require("gluon.sysconfig").primary_mac)') - -. /etc/openwrt_release -. /usr/share/libubox/jshn.sh - -determine_lan_device_name() { - local _iface="$1" - local _var="$2" - - json_load "$(ubus call network.interface.${_iface} status)" - json_get_var is_up "up" - if [ $is_up == 1 ] ; then - json_get_var $_var "device" - fi - - json_cleanup -} - - -determine_wifi_device_name() -{ - local _iface="$1" - local _var="$2" - - if [ "${DISTRIB_CODENAME}" == "attitude_adjustment" ] ; then - eval "$_var=\"$(uci -P/var/state get wireless.${_iface}.ifname)\"" - else - json_load "$(ubus call network.wireless status)" - json_select "radio0" - json_select "interfaces" - - local _idx=1 - while json_get_type type "$_idx" && [ "$type" = object ] ; do - json_select "$(( _idx++ ))" - json_get_var section "section" - if [ "${section}" == "${_iface}" ] ; then - json_get_var $_var "ifname" - break - fi - json_select ".." - done - - json_cleanup - fi -} - - -get_device_stats() { - local _dev="$1" - rx_bytes="$2" - tx_bytes="$3" - rx_dropped="$4" - tx_dropped="$5" - json_select "${_dev}" - json_select "statistics" - json_get_vars rx_bytes tx_bytes rx_dropped tx_dropped - - json_select ".." && json_select ".." -} - - -gather_device_data() { - local rx_bytes - local ty_bytes - local rx_dropped - local tx_dropped - json_load "$(ubus call network.device status)" - - if [ -n "{$DEV_MESH_RADIO_24}" ] ; then - get_device_stats ${DEV_MESH_RADIO_24} rx_bytes tx_bytes rx_dropped tx_dropped - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_radio0.rx_bytes ${rx_bytes} ${timestamp}" >> ${TEMP_DATA_FILE} - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_radio0.tx_bytes ${tx_bytes} ${timestamp}" >> ${TEMP_DATA_FILE} - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_radio0.rx_dropped ${rx_dropped} ${timestamp}" >> ${TEMP_DATA_FILE} - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_radio0.tx_dropped ${tx_dropped} ${timestamp}" >> ${TEMP_DATA_FILE} - fi - - if [ -n "{$DEV_CLIENT_RADIO_24}" ] ; then - get_device_stats ${DEV_CLIENT_RADIO_24} rx_bytes tx_bytes rx_dropped tx_dropped - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.client_radio0.rx_bytes ${rx_bytes} ${timestamp}" >> ${TEMP_DATA_FILE} - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.client_radio0.tx_bytes ${tx_bytes} ${timestamp}" >> ${TEMP_DATA_FILE} - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.client_radio0.rx_dropped ${rx_dropped} ${timestamp}" >> ${TEMP_DATA_FILE} - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.client_radio0.tx_dropped ${tx_dropped} ${timestamp}" >> ${TEMP_DATA_FILE} - fi - - if [ -n "${DEV_MESH_VPN}" ] ; then - get_device_stats ${DEV_MESH_VPN} rx_bytes tx_bytes rx_dropped tx_dropped - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_vpn.rx_bytes ${rx_bytes} ${timestamp}" >> ${TEMP_DATA_FILE} - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_vpn.tx_bytes ${tx_bytes} ${timestamp}" >> ${TEMP_DATA_FILE} - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_vpn.rx_dropped ${rx_dropped} ${timestamp}" >> ${TEMP_DATA_FILE} - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.mesh_vpn.tx_dropped ${tx_dropped} ${timestamp}" >> ${TEMP_DATA_FILE} - fi - - json_cleanup -} - - -gather_stations_data() { - if [ -n "${DEV_CLIENT_RADIO_24}" ] ; then - cnt_assoc_clients=$(iwinfo ${DEV_CLIENT_RADIO_24} assoclist | grep dBm | wc -l) - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.cnt_assoc_clients ${cnt_assoc_clients} ${timestamp}" >> ${TEMP_DATA_FILE} - fi - - if [ -n "${DEV_CLIENT_RADIO_24}" ] ; then - cnt_client_stations=$(iw dev ${DEV_CLIENT_RADIO_24} station dump | grep ^Station | wc -l) - echo ${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.cnt_client_stations ${cnt_client_stations} ${timestamp} >> ${TEMP_DATA_FILE} - fi - - cnt_batman_clients=$(batctl tl | tail -n +3 | grep -v "\[\.P\.\.\.\]" | wc -l) - echo ${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.cnt_batman_clients ${cnt_batman_clients} ${timestamp} >> ${TEMP_DATA_FILE} - - if [ -n "${DEV_MESH_RADIO_24}" ] ; then - cnt_neighbours=$(iw dev ${DEV_MESH_RADIO_24} station dump | grep ^Station | wc -l) - echo "${LIVE_DEBUG_GRAPHITE_DATAPATH_BASE}.cnt_neighbours ${cnt_neighbours} ${timestamp}" >> ${TEMP_DATA_FILE} - fi -} - - -echo "Starting live-debug ... press Ctrl+C to abort." -determine_wifi_device_name "mesh_radio0" DEV_MESH_RADIO_24 -determine_wifi_device_name "client_radio0" DEV_CLIENT_RADIO_24 -determine_lan_device_name "mesh_vpn" DEV_MESH_VPN -while true; do - timestamp=$(date +%s) - date -R -d "${timestamp}" - gather_device_data - gather_stations_data - nc "${LIVE_DEBUG_TARGET_HOST}" "${LIVE_DEBUG_TARGET_HOST_PORT}" < ${TEMP_DATA_FILE} && /bin/rm ${TEMP_DATA_FILE} - sleep 5 -done diff --git a/ffho/ffho-debug/files/usr/lib/micron.d/ffho-debug b/ffho/ffho-debug/files/usr/lib/micron.d/ffho-debug deleted file mode 100644 index 5a6c01a7bc6d019e6f9684af6d5267aaf9bf1d60..0000000000000000000000000000000000000000 --- a/ffho/ffho-debug/files/usr/lib/micron.d/ffho-debug +++ /dev/null @@ -1 +0,0 @@ -*/15 * * * * /bin/ffho-send-stored-debug