Skip to content

Instantly share code, notes, and snippets.

@0xjairo
Last active September 3, 2022 03:04
Show Gist options
  • Save 0xjairo/fb5e749ced15dd5d3d986194eca398e2 to your computer and use it in GitHub Desktop.
Save 0xjairo/fb5e749ced15dd5d3d986194eca398e2 to your computer and use it in GitHub Desktop.
GeekTool System Monitor
#!/bin/bash
# Modified from:
# http://www.macosxtips.co.uk/geeklets/system/comprehensive-system-monitor-yosemite/
# Make sure you change the following variable
# to match the network interface you would like to monitor
nic=en3
echo ------- System Information ------
# Find current bandwith in each pipe
myvar1=`netstat -bI ${nic} | awk "/${nic}/"'{print $7;exit}'`
myvar3=`netstat -bI ${nic} | awk "/${nic}/"'{print $10;exit}'`
sleep 1
# Find current bandwith in each pipe after a second.
myvar2=`netstat -bI ${nic} | awk "/${nic}/"'{print $7;exit}'`
myvar4=`netstat -bI ${nic} | awk "/${nic}/"'{print $10;exit}'`
# Find the difference between each pipe after 1 second.
subin=$(($myvar2 - $myvar1))
subout=$(($myvar4 - $myvar3))
# Convert the bytes to kilobytes
kbin=`echo "scale=2; $subin/1024;" | bc`
kbout=`echo "scale=2; $subout/1024;" | bc`
# Current CPU usage
cpu="`ps -A -o %cpu | awk '{s+=$1} END {print s "%"}'`"
# Current Memory Usage
mem="`ps -A -o %mem | awk '{s+=$1} END {print s "%"}'`"
# Current Disk Usage
hdd="`df -h | grep -E "disk1\s+" | awk '{print $3}' | sed 's/Gi$//'` GB"
echo "CPU:$cpu Mem:$mem Disk:$hdd"
echo
# Current IP Address
# Current Network Traffic
echo "IP address: `ipconfig getifaddr ${nic}`"
echo "Up:$kbout KB/s Down:$kbin KB/s"
# Current uptime
echo Uptime: `uptime | sed -E "s/^[0-9]+:[0-9]+[[:space:]]+up //" | sed -E "s/, [0-9] users.*//"`
echo
# Install iStats for the following to work:
# gem install iStats
# Current CPU Temp
istats cpu
# Current Fan speed
istats fan speed
echo
# Battery
istats battery time
istats battery temp
istats battery charge
# Top 10 processes
echo
echo --------- Top Processes ---------
ps -ecrwwo "command pid %cpu %mem" | head -n 11
@0xjairo
Copy link
Author

0xjairo commented Aug 26, 2016

Script intended to be called from GeekTool and originally modified from
http://www.macosxtips.co.uk/geeklets/system/comprehensive-system-monitor-yosemite/

@0xjairo
Copy link
Author

0xjairo commented Aug 26, 2016

Obligatory screenshot:
image
Font: Source Code Pro

@siceinformatica
Copy link

thx 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment