mirror of
https://github.com/techarkit/shell-scripting-tutorial.git
synced 2025-07-28 23:28:40 +00:00
Collect Multiple Servers CPU, Memory & Disk Usage
Collect Multiple Servers CPU, Memory & Disk Usage in Single file.
This commit is contained in:
28
CpuMemDisk.sh
Normal file
28
CpuMemDisk.sh
Normal file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
## Collect Multiple Servers CPU, MEM and DISK Utilization and store in single file
|
||||
# Purpose: To Collect Multiple Servers CPU, MEM, DISK usage in single report
|
||||
# Version:1.0
|
||||
# Created Date: 2019-05-02
|
||||
# Modified Date:
|
||||
# WebSite: https://server-computer.com
|
||||
# Author: Ankam Ravi Kumar
|
||||
|
||||
HOSTNAME=$(hostname)
|
||||
DATET=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
CPUUSAGE=$(top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 | awk '{print $2}' |awk -F. '{print $1}')
|
||||
MEMUSAGE=$(free | grep Mem | awk '{print $3/$2 * 100.0}')
|
||||
DISKUSAGE=$(df -h / | awk '{print $5}' |tail -n 1 |sed 's/%//g')
|
||||
|
||||
echo 'HostName, Date&Time, CPU(%), MEM(%), DISK(%)' >> /opt/usagereport
|
||||
echo "$HOSTNAME, $DATET, $CPUUSAGE, $MEMUSAGE, $DISKUSAGE" >> /opt/usagereport
|
||||
|
||||
for i in `cat /scripts/hostlist`
|
||||
do
|
||||
RHOST=$(ssh $i hostname)
|
||||
RDATET=$(ssh $i 'date "+%Y-%m-%d %H:%M:%S"')
|
||||
RCPUUSAGE=$(ssh $i top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 | awk '{print $2}' |awk -F. '{print $1}')
|
||||
RMEMUSAGE=$(ssh $i free | grep Mem | awk '{print $3/$2 * 100.0}')
|
||||
RDISKUSAGE=$(ssh $i df -P / |column -t | awk '{print $5}' |tail -n 1 |sed 's/%//g')
|
||||
|
||||
echo "$RHOST, $RDATET, $RCPUUSAGE, $RMEMUSAGE, $RDISKUSAGE" >> /opt/usagereport
|
||||
done
|
Reference in New Issue
Block a user