Statistiques system & software

De BlaxWiki
Aller à la navigationAller à la recherche

Ce petit script est interessant à être cronné toutes les 5 minutes, il récupère des stats sur la mémoire, process httpd, cpu

#!/bin/bash

DATE=`date +%Y%m%d%H%M`
MEM=`free -o | grep Mem: | sed -e 's/Mem: //'`
SWAP=`free -o | grep Swap: | sed -e 's/Swap: //'`
HTTPD=`ps -ef | grep apache | wc -l`
CPU=`ps -u mysql -o %cpu | grep -v CPU`

if [ ! -r /home/claranet/stat.txt ]
then
  echo DATE MEMTOTAL MEMUSED MEMFREE MEMSHARED MEMBUF MEMCACHED SWAPTOTAL SWAPUSED SWAPFREE PROCHTTP HTTPREQ MYSQLCPU CONNMYSQL >/home/claranet/stat.txt
  fi
  echo $DATE $MEM $SWAP $HTTPD $CPU  >>/home/claranet/stat.txt