Client
#!/bin/bash#get_memory-Infoa= ' Free-m|grep Mem|awk'{print$2}'' #total-Memoryb= ' Free-m|grep Mem|awk'{print$3}'' #used-memorymem_percent= ' awk'begin{printf "%.2f%\n", ('$b'/'$a') *100}'' #used-memory-%#echo $mem _percent#get_network_infoping-W5-C1 114.114.114.114>/dev/NULL 2>&1if[$?-eq0];then Net_status="0"ElseNet_status="1"Fi#echo $net _status#get_squid_process_statussquid_status= ' Systemctl status Squid|grep Active|awk'{print$2}'`if["$squid _status"="Active"];then Squid_status_code="0"ElseSquid_status_code="1"Fi#echo $squid _status_codeecho"\ "memory\": \ ""$mem _percent"\",\""Net_status\":\""$net _status"\",\""Squid_status\":\""$squid _status_code"\""
Service side:
#!/bin/bashmachine_ip=$1Machine_port=$2F1= ' cat/proc/sys/kernel/random/uuid ' F2= ' cat/proc/sys/kernel/random/uuid ' F3= ' cat/proc/sys/kernel/random/UUID ' RM-rf/tmp/. $f 1.txt/tmp/. $f 2.txt/tmp/. $f 3.txttouch/tmp/. $f 1.txt/tmp/. $f 2.txt/tmp/. $f 3.txt{#echo"Get Machine_status"Machine_status= ' Ssh-o connecttimeout=6-P $machine _port [email protected] $machine _IP'sh/root/get_machine_info.sh'' Len= ' echo $machine _STATUS|WC-C 'if[$len-GTTen];then echo $machine _status>/tmp/. $f 1.txtElseEcho"\ "memory\": \ ""1"\",\""Net_status\":\""1"\",\""Squid_status\":\""1"\"">/tmp/. $f 1.txt fi}&{#echo"Get WAN IP"Host= ' Ssh-o connecttimeout=3-P $machine _port [email protected] $machine _IP'sh/root/get_wan_ip.sh'|awk-f:'{print$1}'' #echo $host #ssh-O connecttimeout=3[Email protected] $host"Date">/dev/NULL#echo"Test WAN IP for"Ping-W3-C1$host >/dev/NULL 2>&1 if[$?-eq0];then #proxy_ip_port_status= ' echo"\ "proxy_ip\": \ "0\", \ ""Proxy_port\": \ "1\" 'Echo"\ "proxy_ip\": \ "0\", \ ""Proxy_port\": \ "1\" >/tmp/. $f 3.txt Else#proxy_ip_port_status= ' echo"\ "proxy_ip\": \ "1\", \ ""Proxy_port\": \ "0\" 'Echo Echo"\ "proxy_ip\": \ "1\", \ ""Proxy_port\": \ "1\" >/tmp/. $f 3.txtfi}&{#echo"Get Proxy_ip_port"Proxy_ip_port= ' Ssh-o connecttimeout=3-P $machine _port [email protected] $machine _IP'sh/root/get_wan_ip.sh'` if[$?-eq0] && ["$proxy _ip_port"!="NULL"];then #echo"Get Curl Result"result= ' Curl-i-M5-X $proxy _ip_port-o/dev/NULL-s-w%{http_code} map.baidu.com 'if[$result-eq $];then Proxy_ip_port_status= ' echo"\ "proxy_ip\": \ "0\", \ ""Proxy_port\": \ "0\" ' Else#echo"Get WAN IP"#host= ' Ssh-o connecttimeout=3-P $machine _port [email protected] $machine _IP'sh/root/get_wan_ip.sh'|awk-f:'{print$1}'' #ssh-O connecttimeout=3[Email protected] $host"Date">/dev/NULL#echo"Test WAN IP for" #if[$?-eq 0];then# Proxy_ip_port_status= ' echo"\ "proxy_ip\": \ "0\", \ ""Proxy_port\": \ "1\" ' #else# Proxy_ip_port_status= ' echo"\ "proxy_ip\": \ "1\", \ ""Proxy_port\": \ "0\" '#fi f3v= ' cat/tmp/. $f 3.TXT|WC-C ' while(($f 3v <4)) Dof3v= ' cat/tmp/. $f 3.TXT|WC-c ' Done Proxy_ip_port_status= ' cat/tmp/. $f 3.txt ' fiElseProxy_ip_port_status= ' echo"\ "proxy_ip\": \ "1\", \ ""Proxy_port\": \ "1\" 'fi echo $proxy _ip_port_status>/tmp/. $f 2.txt}&wait Proxy_ip_port_status= ' cat/tmp/. $f 2.txt ' Machine_status= ' cat/tmp/. $f 1.txt ' rm-rf/tmp/. $f 1.txt/tmp/. $f 2.txt/tmp/. $f 3.txt#echo $machine _status#echo $proxy _ip_port_statusecho"{"$machine _status","$proxy _ip_port_status"}"
Linux Dial +squid monitoring script