mirror of
https://github.com/netweak/agent.git
synced 2024-12-16 21:46:58 -05:00
fix!: agent.sh not pushing out data
This commit is contained in:
parent
2a582a23f3
commit
54af98f609
1 changed files with 26 additions and 44 deletions
70
agent.sh
70
agent.sh
|
@ -182,63 +182,45 @@ then
|
||||||
cpu_gap=$(($cpu-${data[1]}))
|
cpu_gap=$(($cpu-${data[1]}))
|
||||||
io_gap=$(($io-${data[2]}))
|
io_gap=$(($io-${data[2]}))
|
||||||
idle_gap=$(($idle-${data[3]}))
|
idle_gap=$(($idle-${data[3]}))
|
||||||
|
load_cpu=$(((1000*($cpu_gap-$idle_gap)/$cpu_gap+5)/10))
|
||||||
if [[ $cpu_gap > "0" ]]
|
load_io=$(((1000*($io_gap-$idle_gap)/$cpu_gap+5)/10))
|
||||||
then
|
|
||||||
load_cpu=$(((1000*($cpu_gap-$idle_gap)/$cpu_gap+5)/10))
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $io_gap > "0" ]]
|
|
||||||
then
|
|
||||||
load_io=$(((1000*($io_gap-$idle_gap)/$io_gap+5)/10))
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $rx > ${data[4]} ]]
|
|
||||||
then
|
|
||||||
rx_gap=$(($rx-${data[4]}))
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $tx > ${data[5]} ]]
|
|
||||||
then
|
|
||||||
tx_gap=$(($tx-${data[5]}))
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# System load cache
|
echo "$time $cpu $io $idle" > /etc/netweak/cache
|
||||||
echo "$time $cpu $io $idle $rx $tx" > /etc/netweak/cache
|
|
||||||
|
|
||||||
# Prepare load variables
|
# Ping to external servers
|
||||||
rx_gap=$(prep $(num "$rx_gap"))
|
ping_eu=$(prep $(int "$(ping -c 1 -w 1 ping.online.net | grep time= | awk '{ print $8 }' | cut -d= -f2)"))
|
||||||
tx_gap=$(prep $(num "$tx_gap"))
|
ping_us=$(prep $(int "$(ping -c 1 -w 1 ping.chi.att.com | grep time= | awk '{ print $8 }' | cut -d= -f2)"))
|
||||||
load_cpu=$(prep $(num "$load_cpu"))
|
ping_as=$(prep $(int "$(ping -c 1 -w 1 mirror.hk.leaseweb.net | grep time= | awk '{ print $8 }' | cut -d= -f2)"))
|
||||||
load_io=$(prep $(num "$load_io"))
|
|
||||||
|
|
||||||
# Get network latency
|
|
||||||
ping_eu=$(prep $(num "$(ping -c 2 -w 2 ping-eu.netweak.com | grep rtt | cut -d'/' -f4 | awk '{ print $3 }')"))
|
|
||||||
ping_us=$(prep $(num "$(ping -c 2 -w 2 ping-us.netweak.com | grep rtt | cut -d'/' -f4 | awk '{ print $3 }')"))
|
|
||||||
ping_as=$(prep $(num "$(ping -c 2 -w 2 ping-as.netweak.com | grep rtt | cut -d'/' -f4 | awk '{ print $3 }')"))
|
|
||||||
|
|
||||||
# Build data for post
|
# Build data for post
|
||||||
data_post="token=${auth[0]}&data=$(base "$version") $(base "$uptime") $(base "$sessions") $(base "$processes") $(base "$processes_array") $(base "$file_handles") $(base "$file_handles_limit") $(base "$os_kernel") $(base "$os_name") $(base "$os_arch") $(base "$cpu_name") $(base "$cpu_cores") $(base "$cpu_freq") $(base "$ram_total") $(base "$ram_usage") $(base "$swap_total") $(base "$swap_usage") $(base "$disk_array") $(base "$disk_total") $(base "$disk_usage") $(base "$connections") $(base "$nic") $(base "$ipv4") $(base "$ipv6") $(base "$rx") $(base "$tx") $(base "$rx_gap") $(base "$tx_gap") $(base "$load") $(base "$load_cpu") $(base "$load_io") $(base "$ping_eu") $(base "$ping_us") $(base "$ping_as")"
|
data_post="token=${auth[0]}&data=$(base "$version") $(base "$uptime") $(base "$sessions") $(base "$processes") $(base "$processes_array") $(base "$file_handles") $(base "$file_handles_limit") $(base "$os_kernel") $(base "$os_name") $(base "$os_arch") $(base "$cpu_name") $(base "$cpu_cores") $(base "$cpu_freq") $(base "$ram_total") $(base "$ram_usage") $(base "$swap_total") $(base "$swap_usage") $(base "$disk_array") $(base "$disk_total") $(base "$disk_usage") $(base "$connections") $(base "$nic") $(base "$ipv4") $(base "$ipv6") $(base "$rx") $(base "$tx") $(base "$rx_gap") $(base "$tx_gap") $(base "$load") $(base "$load_cpu") $(base "$load_io") $(base "$ping_eu") $(base "$ping_us") $(base "$ping_as")"
|
||||||
|
|
||||||
# API request with automatic termination
|
# Write data_post to a temporary file
|
||||||
|
tmp_file=$(mktemp)
|
||||||
|
echo "$data_post" > "$tmp_file"
|
||||||
|
|
||||||
|
# API request with automatic termination, using --post-file
|
||||||
if [ -n "$(command -v timeout)" ]
|
if [ -n "$(command -v timeout)" ]
|
||||||
then
|
then
|
||||||
timeout -s SIGKILL 30 wget -q -o /dev/null -O /etc/netweak/log/agent.log -T 25 --post-data "$data_post" --no-check-certificate "https://api.netweak.com/agent/report"
|
timeout -s SIGKILL 30 wget -q -o /etc/netweak/log/agent.log -T 25 --post-file="$tmp_file" --no-check-certificate "https://api.netweak.com/agent/report"
|
||||||
else
|
else
|
||||||
wget -q -o /dev/null -O /etc/netweak/log/agent.log -T 25 --post-data "$data_post" --no-check-certificate "https://api.netweak.com/agent/report"
|
wget -q -o /etc/netweak/log/agent.log -T 25 --post-file="$tmp_file" --no-check-certificate "https://api.netweak.com/agent/report"
|
||||||
wget_pid=$!
|
wget_pid=$!
|
||||||
wget_counter=0
|
wget_counter=0
|
||||||
wget_timeout=30
|
wget_timeout=30
|
||||||
|
|
||||||
while kill -0 "$wget_pid" && (( wget_counter < wget_timeout ))
|
while kill -0 "$wget_pid" && (( wget_counter < wget_timeout ))
|
||||||
do
|
do
|
||||||
sleep 1
|
sleep 1
|
||||||
(( wget_counter++ ))
|
(( wget_counter++ ))
|
||||||
done
|
done
|
||||||
|
|
||||||
kill -0 "$wget_pid" && kill -s SIGKILL "$wget_pid"
|
kill -0 "$wget_pid" && kill -s SIGKILL "$wget_pid"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Clean up temporary file
|
||||||
|
rm -f "$tmp_file"
|
||||||
|
|
||||||
# Finished
|
# Finished
|
||||||
exit 1
|
exit 1
|
||||||
|
|
Loading…
Reference in a new issue