Updated the system information script. Changed decimal places for memory to 1, added in list of top 5 memory users.
This commit is contained in:
@@ -21,12 +21,26 @@ celsius_to_fahrenheit() {
|
|||||||
local celsius="$1"
|
local celsius="$1"
|
||||||
[[ -z "$celsius" || "$celsius" == "--" ]] && echo "--" && return
|
[[ -z "$celsius" || "$celsius" == "--" ]] && echo "--" && return
|
||||||
[[ ! "$celsius" =~ ^-?[0-9]+(\.[0-9]+)?$ ]] && echo "--" && return
|
[[ ! "$celsius" =~ ^-?[0-9]+(\.[0-9]+)?$ ]] && echo "--" && return
|
||||||
|
|
||||||
local fahrenheit
|
local fahrenheit
|
||||||
fahrenheit=$(echo "scale=1; ($celsius * 9/5) + 32" | bc -l)
|
fahrenheit=$(echo "scale=1; ($celsius * 9/5) + 32" | bc -l)
|
||||||
echo "$fahrenheit"
|
echo "$fahrenheit"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Get top memory using processes
|
||||||
|
get_top_memory_users() {
|
||||||
|
local topCount=5
|
||||||
|
local memoryList
|
||||||
|
|
||||||
|
memoryList=$(ps axo rss,comm,pid \
|
||||||
|
| awk '{ procList[$2] += $1; } END \
|
||||||
|
{ for (proc in procList) { printf("%d\t%s\n", procList[proc],proc); }}' \
|
||||||
|
| sort -n | tail -n "$topCount" | sort -rn \
|
||||||
|
| awk '{$1/=1024;printf "%.0fMB\t",$1}{print $2}')
|
||||||
|
|
||||||
|
echo "$memoryList"
|
||||||
|
}
|
||||||
|
|
||||||
update_system_data() {
|
update_system_data() {
|
||||||
# CPU usage
|
# CPU usage
|
||||||
cpuUsage=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}')
|
cpuUsage=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}')
|
||||||
@@ -52,14 +66,14 @@ update_system_data() {
|
|||||||
[[ "$tempCelsius" != "--" && "$tempCelsius" != "null" ]] && cpuTemp=$(celsius_to_fahrenheit "$tempCelsius") || cpuTemp="--"
|
[[ "$tempCelsius" != "--" && "$tempCelsius" != "null" ]] && cpuTemp=$(celsius_to_fahrenheit "$tempCelsius") || cpuTemp="--"
|
||||||
|
|
||||||
# Memory usage
|
# Memory usage
|
||||||
memoryTotal=$(free -m | awk '/^Mem:/{print $2/1024}')
|
memoryTotal=$(free -m | awk '/^Mem:/{printf("%.1f", $2/1024)}')
|
||||||
memoryUsed=$(free -m | awk '/^Mem:/{print $3/1024}')
|
memoryUsed=$(free -m | awk '/^Mem:/{printf("%.1f", $3/1024)}')
|
||||||
memoryPercent=$(free | awk '/^Mem:/{printf("%.1f", $3/$2 * 100)}')
|
memoryPercent=$(free | awk '/^Mem:/{printf("%.1f", $3/$2 * 100)}')
|
||||||
|
|
||||||
# Swap usage
|
# Swap usage
|
||||||
swapTotal=$(free -m | awk '/^Swap:/{print $2/1024}')
|
swapTotal=$(free -m | awk '/^Swap:/{printf("%.1f", $2/1024)}')
|
||||||
swapUsed=$(free -m | awk '/^Swap:/{print $3/1024}')
|
swapUsed=$(free -m | awk '/^Swap:/{printf("%.1f", $3/1024)}')
|
||||||
[[ "$swapTotal" -gt 0 ]] && swapPercent=$(free | awk '/^Swap:/{printf("%.1f", $3/$2 * 100)}') || swapPercent=0
|
[[ "$swapTotal" != "0.0" ]] && swapPercent=$(free | awk '/^Swap:/{printf("%.1f", $3/$2 * 100)}') || swapPercent=0
|
||||||
|
|
||||||
# Disk usage
|
# Disk usage
|
||||||
diskTotal=$(df -h / | awk 'NR==2 {print $2}')
|
diskTotal=$(df -h / | awk 'NR==2 {print $2}')
|
||||||
@@ -73,7 +87,11 @@ update_system_data() {
|
|||||||
|
|
||||||
display_system_info() {
|
display_system_info() {
|
||||||
update_system_data
|
update_system_data
|
||||||
|
|
||||||
|
# Get top memory users
|
||||||
|
local topMemoryUsers
|
||||||
|
topMemoryUsers=$(get_top_memory_users)
|
||||||
|
|
||||||
# Create the system information text with proper line breaks
|
# Create the system information text with proper line breaks
|
||||||
systemInfoText="System Information
|
systemInfoText="System Information
|
||||||
|
|
||||||
@@ -85,6 +103,9 @@ Memory
|
|||||||
Usage: ${memoryUsed} / ${memoryTotal} GB (${memoryPercent}%)
|
Usage: ${memoryUsed} / ${memoryTotal} GB (${memoryPercent}%)
|
||||||
Swap: ${swapUsed} / ${swapTotal} GB (${swapPercent}%)
|
Swap: ${swapUsed} / ${swapTotal} GB (${swapPercent}%)
|
||||||
|
|
||||||
|
Top Memory Users
|
||||||
|
${topMemoryUsers}
|
||||||
|
|
||||||
Disk (Root Partition)
|
Disk (Root Partition)
|
||||||
Usage: ${diskUsed} / ${diskTotal} GB (${diskPercent}%)
|
Usage: ${diskUsed} / ${diskTotal} GB (${diskPercent}%)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user