QuecManager 1.0.2 BETA

- Added signal graphs for RSRP, RSRQ, and SINR
- Added ethernet connection details
- Added memory usage details
- Added ping graph

Known bug:
Signal graphs may sometimes show inaccurate values. It seems to be a fetching error but Ill try to find the real root cause as soon as possible

Co-Authored-By: Russel Yasol <73575327+dr-dolomite@users.noreply.github.com>
This commit is contained in:
Cameron Thompson
2024-12-17 19:11:26 -05:00
parent f145802509
commit b981b4a519
63 changed files with 266 additions and 84 deletions

View File

@@ -4,8 +4,8 @@
echo "Content-Type: application/json"
echo ""
# Ping 8.8.8.8 with 5 packets and capture the result
if ping -c 5 8.8.8.8 > /dev/null 2>&1; then
# Ping 8.8.8.8 with 2 packets and capture the result
if ping -c 2 8.8.8.8 > /dev/null 2>&1; then
# Ping was successful
echo '{"connection": "ACTIVE"}'
else

View File

@@ -0,0 +1,20 @@
#!/bin/sh
# Set the content type to JSON
echo "Content-Type: application/json"
echo ""
# Run ethtool on eth0 and capture the output
ethtool_output=$(ethtool eth0)
# Extract Link Speed
speed=$(echo "$ethtool_output" | grep "Speed:" | awk '{print $2}')
# Extract Link Status
link_status=$(echo "$ethtool_output" | grep "Link detected:" | awk '{print $3}')
# Extract Auto-negotiation status
auto_negotiation=$(echo "$ethtool_output" | grep "Auto-negotiation:" | awk '{print $2}')
# Create JSON output
echo "{\"link_speed\": \"$speed\", \"link_status\": \"$link_status\", \"auto_negotiation\": \"$auto_negotiation\"}"

View File

@@ -0,0 +1,30 @@
#!/bin/sh
# Ensure the script outputs proper CGI headers
echo "Content-Type: application/json"
echo ""
# Directory where JSON files are stored (adjust as needed)
JSON_DIR="/tmp/signal_graphs/"
# Function to safely read JSON file
read_json_file() {
local file="$1"
if [ -f "$file" ]; then
cat "$file"
else
echo "[]" # Return empty array if file doesn't exist
fi
}
# Collect signal metrics from JSON files
RSRP=$(read_json_file "${JSON_DIR}/rsrp.json")
RSRQ=$(read_json_file "${JSON_DIR}/rsrq.json")
SINR=$(read_json_file "${JSON_DIR}/sinr.json")
# Combine metrics into a single JSON object
printf '{
"rsrp": %s,
"rsrq": %s,
"sinr": %s
}' "$RSRP" "$RSRQ" "$SINR"

View File

@@ -0,0 +1,69 @@
#!/bin/sh
# Ensure the directory exists
LOGDIR="/tmp/signal_graphs"
mkdir -p "$LOGDIR"
# Maximum number of entries
MAX_ENTRIES=10
# Interval between logs (in seconds)
INTERVAL=25
# Function to clean and extract actual output from atinout
clean_atinout_output() {
# Remove first line (echoed command), last line (OK), and trim whitespace
sed -n '2,/^OK$/p' | sed '$d' | tr -d '\r' | xargs
}
# Function to log signal metrics
log_signal_metric() {
local COMMAND="$1"
local FILENAME="$2"
local LOGFILE="$LOGDIR/$FILENAME"
# Ensure log directory exists
mkdir -p "$(dirname "$LOGFILE")"
# Get current timestamp
TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
# Run the AT command and capture its output, then clean it
SIGNAL_OUTPUT=$(echo "$COMMAND" | atinout - /dev/smd11 - | clean_atinout_output)
# Ensure the file exists and is a valid JSON array
if [ ! -s "$LOGFILE" ]; then
echo "[]" > "$LOGFILE"
fi
# Prepare new JSON entry
ESCAPED_TIMESTAMP=$(printf '%s' "$TIMESTAMP" | sed 's/"/\\"/g')
ESCAPED_OUTPUT=$(printf '%s' "$SIGNAL_OUTPUT" | sed 's/"/\\"/g')
# Use jq with a more robust approach
jq --arg datetime "$ESCAPED_TIMESTAMP" \
--arg output "$ESCAPED_OUTPUT" \
'
# Ensure the input is always an array
if type == "array" then .
else []
end |
# Add new entry
. + [{"datetime": $datetime, "output": $output}] |
# Trim to max entries
.[-'"$MAX_ENTRIES"':]
' "$LOGFILE" > "${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "$LOGFILE"
}
# Trap to handle script termination gracefully
cleanup() {
echo "Stopping signal logging..."
exit 0
}
trap cleanup SIGINT SIGTERM
# Continuous logging loop
echo "Starting continuous signal metrics logging (Press Ctrl+C to stop)..."
while true; do
# Log RSRP
log_signal_metric "AT+QRSRP" "rsrp.json"
# Log RSRQ
log_signal_metric "AT+QRSRQ" "rsrq.json"
# Log SINR
log_signal_metric "AT+QSINR" "sinr.json"
# Wait for the specified interval
sleep "$INTERVAL"
done

View File

@@ -0,0 +1,15 @@
#!/bin/sh
# Set the content type to JSON
echo "Content-Type: application/json"
echo ""
# Run free command and capture the output, using -b for bytes
free_output=$(free -b)
# Extract memory information using awk
# Skip the header, take the Mem: line, and extract total, used, and available
memory_info=$(echo "$free_output" | awk '/Mem:/ {print "{\"total\": " $2 ", \"used\": " $3 ", \"available\": " $7 "}"}')
# Output the JSON
echo "$memory_info"

View File

@@ -0,0 +1,24 @@
#!/bin/sh
# Set the content type to JSON
echo "Content-Type: application/json"
echo ""
# Ping 8.8.8.8 with 5 packets and capture the full output
ping_result=$(ping -c 5 8.8.8.8)
# Check if ping was successful
if [ $? -eq 0 ]; then
# Extract the average latency using awk
avg_latency=$(echo "$ping_result" | awk '/avg/ {split($4, a, "/"); print int(a[2])}')
# If average latency was extracted, return it
if [ ! -z "$avg_latency" ]; then
echo "{\"connection\": \"ACTIVE\", \"latency\": $avg_latency}"
else
echo '{"connection": "ACTIVE", "latency": 0}'
fi
else
# Ping failed
echo '{"connection": "INACTIVE", "latency": 0}'
fi

View File

@@ -0,0 +1,8 @@
#!/bin/sh
export HOME=/tmp/home
# Create named pipe for speedtest output if it doesn't exist
[ ! -p /tmp/realtime_spd.json ] && mkfifo /tmp/realtime_spd.json
# Run speedtest in background
/usr/bin/speedtest --accept-license -f json -p yes --progress-update-interval=100 > /tmp/realtime_spd.json

View File

@@ -0,0 +1,13 @@
#!/bin/sh
echo "Content-Type: text/event-stream"
echo "Cache-Control: no-cache"
echo "Connection: keep-alive"
echo ""
# Use cat to read from the FIFO
cat /tmp/realtime_spd.json | while read line; do
echo "data: $line"
echo
sleep 0.1
done

View File

@@ -0,0 +1,10 @@
#!/bin/sh
# /www/cgi-bin/start_speedtest.sh
echo "Content-Type: application/json"
echo ""
# Run speedtest in background
/www/cgi-bin/home/speedtest/speedtest.sh
# Immediately return a success response
echo '{"status":"started"}'