#!/bin/bash
da=$(date +%Y%m%d%H%M%S)
da1=$(date +%Y%m%d)
echo "=====start file $da=====" >>/logs/reso/log/$da1"_"resource.log
echo "date|totmem|usedmem|availmem|totcpu|ucpu|syscpu|iowait|real1cpu%|real1mem%|real1RSS|real2cpu%|real2mem%|real2RSS|real3cpu%|realmem%|real3RSS" >>/logs/reso/log/$da1"_"resource.log
totmem=$(free | grep Mem | awk -F " " '{print $2}')
while true; do
da2=$(date +%Y%m%d%H%M%S)
da3=$(date +%Y%m%d)
usedmem=$(free | grep 'buffers/cache' | awk -F " " '{print $3}')
availmem=$(free | grep Mem | awk -F " " '{print $4+$6+$7}')
cpu=$(mpstat 2 2 | tail -1 | awk -F " " '{print 100-$11"|"$3"|"$5"|"$6}')
real1=$(ps aux | grep java | grep gate-web | grep -v grep | awk -F" " '{print $3"|"$4"|"$6}')
real2=$(ps aux | grep java | grep external-web | grep -v grep | awk -F" " '{print $3"|"$4"|"$6}')
real3=$(ps aux | grep java | grep cbpp | grep -v grep | awk -F" " '{print $3"|"$4"|"$6}')
real4=$(ps aux | grep java | grep tlo | grep -v grep | awk -F" " '{print $3"|"$4"|"$6}')
real5=$(ps aux | grep java | grep cli | grep -v grep | awk -F" " '{print $3"|"$4"|"$6}')
real6=$(ps aux | grep 'nginx: master' | grep -v grep | awk -F" " '{print $3"|"$4"|"$6}')
real7=$(ps aux | grep 'nginx: worker' | grep -v grep | awk -F" " '{print $3"|"$4"|"$6}')
#echo&5sec
echo $da2"|"$totmem"|"$usedmem"|"$availmem"|"$cpu"|"$real1"|"$real2"|"$real3"|"$real4"|"$real5"|"$real6"|"$real7 >>/logs/reso/log/$da3"_"resource.log
sleep 1
done