轻量级监控平台之内存监控

轻量级监控平台之内存监控脚本

#!/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}"'"}'

架构设计@工程设计@服务稳定性之路

发布了159 篇原创文章 · 获赞 69 · 访问量 35万+

猜你喜欢

转载自blog.csdn.net/u010504064/article/details/103166785