輕量級監控平臺以內存監控腳本shell
#!/bin/bash #進程監控腳本 #功能需求: 上報當前服務的內存數據 . /etc/profile . ~/.bash_profile cd ~ pushurl="https://lightmonitorapi.test.cn/push/servermem" #獲取內存總大小 mem_total=`free -m | awk 'NR==2{print $2}'` #echo "總內存大小=$mem_total" #獲取內存使用大小 mem_use=`free -m | awk 'NR==2{print $3}'` #echo "已使用大小=$mem_use" #echo "內存使用率=$mem_use_rate%" mem_left=`free -m | awk 'NR==2{print $4}'` #echo "剩餘內存=$mem_left m" buffers=`free -m | awk 'NR==2{print $6}'` caches=`free -m | awk 'NR==2{print $7}'` ip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d '/') msg=$mem_total"m-"$mem_use"m-"$mem_left"m-"$buffers"m-"$caches"m" ticket=$(cat /opt/shell/ticket.txt) curl $pushurl \ -H "Accept: application/json" \ -H 'Content-Type: application/json' \ -d \ '{"ip": "'"${ip}"'", "ticket": "'"${ticket}"'", "data": "'"${msg}"'"}'
架構設計@工程設計@服務穩定性之路json