fix: Update netifyd collector for netifyd 5.x stats format
- Collect available stats from status.json (flows_active, flow_count, cpu, memory, interface stats) instead of expecting individual flows - Save current stats to /tmp/netifyd-stats.json - Maintain history in /tmp/netifyd-stats-history.json (up to 24h) - Fix architecture detection in plugin-setup script Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a9a01ced95
commit
c9f3b2a5f8
@ -1,42 +1,63 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Netifyd Flow Data Collector
|
# Netifyd Stats Collector
|
||||||
# Reads from netifyd Unix socket and maintains a local flow cache
|
# Collects network statistics from netifyd status.json
|
||||||
|
# Note: netifyd 5.x doesn't export individual flows locally
|
||||||
|
|
||||||
NETIFYD_SOCKET="/var/run/netifyd/netifyd.sock"
|
NETIFYD_STATUS="/var/run/netifyd/status.json"
|
||||||
FLOW_CACHE="/tmp/netifyd-flows.json"
|
STATS_CACHE="/tmp/netifyd-stats-history.json"
|
||||||
MAX_FLOWS=1000
|
STATS_CURRENT="/tmp/netifyd-stats.json"
|
||||||
|
MAX_ENTRIES=1440 # 24 hours at 1 min intervals
|
||||||
|
|
||||||
# Check if netifyd is running
|
# Check if netifyd is running
|
||||||
if ! pidof netifyd >/dev/null 2>&1; then
|
if ! pidof netifyd >/dev/null 2>&1; then
|
||||||
echo "[]" > "$FLOW_CACHE"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if socket exists
|
# Check if status file exists
|
||||||
if [ ! -S "$NETIFYD_SOCKET" ]; then
|
if [ ! -f "$NETIFYD_STATUS" ]; then
|
||||||
echo "[]" > "$FLOW_CACHE"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Read from Unix socket and collect flow data
|
# Get current timestamp
|
||||||
# Note: netifyd socket outputs status info, not real-time flows
|
TIMESTAMP=$(date +%s)
|
||||||
# We need to use netifyd CLI to get flow information
|
|
||||||
|
|
||||||
# Try to get flow data from netifyd status
|
# Extract current stats from netifyd
|
||||||
if [ -f "/var/run/netifyd/status.json" ]; then
|
if command -v jq >/dev/null 2>&1; then
|
||||||
# Extract flows if available, otherwise create empty array
|
# Build current stats snapshot
|
||||||
if command -v jq >/dev/null 2>&1; then
|
CURRENT=$(jq -c --arg ts "$TIMESTAMP" '{
|
||||||
jq -c 'if .flows then .flows else [] end' /var/run/netifyd/status.json > "$FLOW_CACHE" 2>/dev/null || echo "[]" > "$FLOW_CACHE"
|
timestamp: ($ts | tonumber),
|
||||||
else
|
flows_active: (.flows_active // 0),
|
||||||
cp /var/run/netifyd/status.json "$FLOW_CACHE"
|
flow_count: (.flow_count // 0),
|
||||||
|
uptime: (.uptime // 0),
|
||||||
|
cpu_system: (.cpu_system // 0),
|
||||||
|
cpu_user: (.cpu_user // 0),
|
||||||
|
memrss_kb: (.memrss_kb // 0),
|
||||||
|
interfaces: (if .stats then
|
||||||
|
[.stats | to_entries[] | {
|
||||||
|
name: .key,
|
||||||
|
rx_bytes: (.value.ip_bytes // 0),
|
||||||
|
tx_bytes: (.value.wire_bytes // 0),
|
||||||
|
tcp: (.value.tcp // 0),
|
||||||
|
udp: (.value.udp // 0)
|
||||||
|
}]
|
||||||
|
else [] end)
|
||||||
|
}' "$NETIFYD_STATUS" 2>/dev/null)
|
||||||
|
|
||||||
|
if [ -n "$CURRENT" ] && [ "$CURRENT" != "null" ]; then
|
||||||
|
# Save current stats
|
||||||
|
echo "$CURRENT" > "$STATS_CURRENT"
|
||||||
|
|
||||||
|
# Append to history
|
||||||
|
if [ -f "$STATS_CACHE" ]; then
|
||||||
|
# Add new entry and trim to max
|
||||||
|
jq -c --argjson new "$CURRENT" '. + [$new] | if length > '"$MAX_ENTRIES"' then .[-('"$MAX_ENTRIES"'):] else . end' "$STATS_CACHE" > "$STATS_CACHE.tmp" 2>/dev/null && mv "$STATS_CACHE.tmp" "$STATS_CACHE"
|
||||||
|
else
|
||||||
|
echo "[$CURRENT]" > "$STATS_CACHE"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "[]" > "$FLOW_CACHE"
|
# Fallback without jq - just copy status
|
||||||
fi
|
cp "$NETIFYD_STATUS" "$STATS_CURRENT"
|
||||||
|
|
||||||
# Keep only the most recent flows
|
|
||||||
if [ -f "$FLOW_CACHE" ] && command -v jq >/dev/null 2>&1; then
|
|
||||||
jq "if length > $MAX_FLOWS then .[-$MAX_FLOWS:] else . end" "$FLOW_CACHE" > "$FLOW_CACHE.tmp" 2>/dev/null && mv "$FLOW_CACHE.tmp" "$FLOW_CACHE"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user