監控cpu與memory指令碼
#!/bin/bash
#################Begin of input_declare#################
#Get Cpu Value
CPU_get=$(/usr/bin/sar -u 1 1 | awk 'NR==4{print $8}')
cpu_idle=$(echo ${CPU_get})
CpuUsedCal=$(echo "scale=2;100-${cpu_idle}"|bc)
#Get Memory Value
MemTotal_get=$(cat /proc/meminfo | awk 'NR==1{print $2}')
MemFree_get=$(cat /proc/meminfo | awk 'NR==2{print $2}')
Buffers_get=$(cat /proc/meminfo | awk 'NR==3{print $2}')
Cached_get=$(cat /proc/meminfo | awk 'NR==4{print $2}')
MemTotal=$(echo ${MemTotal_get})
MemFree=$(echo ${MemFree_get})
Buffers=$(echo ${Buffers_get})
Cached=$(echo ${Cached_get})
MEM_cal=$(echo "scale=2;100*(${MemTotal}-${MemFree}-${Buffers}-${Cached})/${MemTotal}"|bc)
MemUsedPerc=$(echo ${MEM_cal})
#Set Time Format
v_time=$(date "+%F %T")
v_mon=$(date +%Y%m)
v_del_mon=$(date -d "12 months ago" +%Y%m)
#Set Path
v_cpu_path=/data/log/cpu_used_perc_logs/
v_mem_path=/data/log/mem_used_perc_logs/
#################End of input_declare###################
#################Begin of main#################
if [ -d ${v_cpu_path} ];then
echo "${v_time}" >> ${v_cpu_path}cpu_used_perc${v_mon}.log
echo "${CpuUsedCal}%" >> ${v_cpu_path}cpu_used_perc${v_mon}.log
else
mkdir -p ${v_cpu_path}
fi
if [ -f ${v_cpu_path}cpu_used_perc${v_del_mon}.log ];then
rm -f ${v_cpu_path}cpu_used_perc${v_del_mon}.log
fi
if [ -d ${v_mem_path} ];then
echo "${v_time}" >> ${v_mem_path}mem_used_perc${v_mon}.log
echo "${MemUsedPerc}%" >> ${v_mem_path}mem_used_perc${v_mon}.log
else
mkdir -p ${v_mem_path}
fi
if [ -f ${v_mem_path}mem_used_perc${v_del_mon}.log ];then
rm -f ${v_mem_path}mem_used_perc${v_del_mon}.log
fi
#################end of main###################
#################Begin of input_declare#################
#Get Cpu Value
CPU_get=$(/usr/bin/sar -u 1 1 | awk 'NR==4{print $8}')
cpu_idle=$(echo ${CPU_get})
CpuUsedCal=$(echo "scale=2;100-${cpu_idle}"|bc)
#Get Memory Value
MemTotal_get=$(cat /proc/meminfo | awk 'NR==1{print $2}')
MemFree_get=$(cat /proc/meminfo | awk 'NR==2{print $2}')
Buffers_get=$(cat /proc/meminfo | awk 'NR==3{print $2}')
Cached_get=$(cat /proc/meminfo | awk 'NR==4{print $2}')
MemTotal=$(echo ${MemTotal_get})
MemFree=$(echo ${MemFree_get})
Buffers=$(echo ${Buffers_get})
Cached=$(echo ${Cached_get})
MEM_cal=$(echo "scale=2;100*(${MemTotal}-${MemFree}-${Buffers}-${Cached})/${MemTotal}"|bc)
MemUsedPerc=$(echo ${MEM_cal})
#Set Time Format
v_time=$(date "+%F %T")
v_mon=$(date +%Y%m)
v_del_mon=$(date -d "12 months ago" +%Y%m)
#Set Path
v_cpu_path=/data/log/cpu_used_perc_logs/
v_mem_path=/data/log/mem_used_perc_logs/
#################End of input_declare###################
#################Begin of main#################
if [ -d ${v_cpu_path} ];then
echo "${v_time}" >> ${v_cpu_path}cpu_used_perc${v_mon}.log
echo "${CpuUsedCal}%" >> ${v_cpu_path}cpu_used_perc${v_mon}.log
else
mkdir -p ${v_cpu_path}
fi
if [ -f ${v_cpu_path}cpu_used_perc${v_del_mon}.log ];then
rm -f ${v_cpu_path}cpu_used_perc${v_del_mon}.log
fi
if [ -d ${v_mem_path} ];then
echo "${v_time}" >> ${v_mem_path}mem_used_perc${v_mon}.log
echo "${MemUsedPerc}%" >> ${v_mem_path}mem_used_perc${v_mon}.log
else
mkdir -p ${v_mem_path}
fi
if [ -f ${v_mem_path}mem_used_perc${v_del_mon}.log ];then
rm -f ${v_mem_path}mem_used_perc${v_del_mon}.log
fi
#################end of main###################
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28371090/viewspace-1180479/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- stap監控cpu指令碼小結指令碼
- 監控使用高cpu的sql語句指令碼SQL指令碼
- 監控指令碼指令碼
- mysql監控指令碼MySql指令碼
- DBA監控指令碼指令碼
- session指令碼監控Session指令碼
- 埠監控指令碼指令碼
- oracle 監控指令碼Oracle指令碼
- listener監聽監控指令碼指令碼
- 【SQL監控】SQL完全監控的指令碼SQL指令碼
- ogg監控指令碼指令碼
- stap監控IO指令碼指令碼
- 【shell】磁碟監控指令碼指令碼
- PowerShell 指令碼來監控 CPU、記憶體和磁碟使用情況:指令碼記憶體
- mysql 的一個監控指令碼,監控heartbeatMySql指令碼
- aix cpu監控AI
- mysql mon 的一個監控指令碼,監控heartbeatMySql指令碼
- 如何用bash shell 指令碼監控 Linux記憶體、磁碟和 CPU?指令碼Linux記憶體
- PostgreSQL之鎖監控指令碼SQL指令碼
- Oracle DBA常用監控指令碼Oracle指令碼
- memcached程式埠監控指令碼指令碼
- Nagios 監控ESXI指令碼iOS指令碼
- 資料庫監控指令碼資料庫指令碼
- (Datagurad)監控指令碼指令碼
- 監控session數量指令碼Session指令碼
- 監控硬碟空間指令碼硬碟指令碼
- 監控sqlldr執行指令碼SQL指令碼
- 監控資料庫指令碼資料庫指令碼
- cacti自定義監控指令碼指令碼
- 監控系統告警指令碼集合指令碼
- 監控oracle表空間指令碼Oracle指令碼
- Goldengate for nrpe監控指令碼Go指令碼
- systemtap的網路監控指令碼指令碼
- 指令碼監控MySQL伺服器指令碼MySql伺服器
- [zt]資料庫監控指令碼資料庫指令碼
- LINUX主機監控指令碼Linux指令碼
- 資料庫監控指令碼(一)資料庫指令碼
- 資料庫監控指令碼(二)資料庫指令碼