Need Help Using Top With GeekTool...

Joined
Oct 18, 2009
Messages
110
Reaction score
8
Points
18
Ok, this is a little involved so buckle up. I've recently started using GeekTool (3.0 RC5) Tynsoe projects.

I have successfully created a shell Geeklet that uses Top to display a user defined number of processes and their CPU and RAM usage. This is very good information to have, but I would also like to see a summary of the overall RAM and CPU usage in a separate Geeklet.

Nick Young at Keynote 2 Keynote has done this on his system as shown on his blog: Ultimate GeekTool Setup - Pimp Your Desktop Part 2 at Keynote 2 Keynote

He lists the following command (note that he included uptime in his summary):
uptime | awk '{print "UPTIME : " $3 " " $4 " " $5 " " }'; top -l 1 | awk '/PhysMem/ {print "RAM : " $8 " "}' ; top -l 2 | awk '/CPU usage/ && NR > 5 {print $6, $7=":", $8, $9="user ", $10, $11="sys ", $12, $13}'

When I run that command I get an error. A friend of mine noticed that & should just be & and > should be >. I made those changes as below:
uptime | awk '{print "UPTIME : " $3 " " $4 " " $5 " " }'; top -l 1 | awk '/PhysMem/ {print "RAM : " $8 " "}' ; top -l 2 | awk '/CPU usage/ && NR > 5 {print $6, $7=":", $8, $9="user ", $10, $11="sys ", $12, $13}'

I now get the following result:
UPTIME : 5 days, 23:40,
RAM : 1844M
sys, : idle user sys

A couple of observations. First, his screenshot (see his blog) shows his RAM as 1.47G whereas mine is shown as 1844M. I prefer the G notation, but I can live with M if no one has a solution. Second, I'm not sure if that refers to RAM used or RAM available. Third, and most disturbing is that my command shows labels for CPU usage, but no actual percentages. I have been unable to find a fix for this. Finally, you notice that his screen shot shows the final line labeled as "CPU :" just as the other two are labeled "UPTIME :" and "RAM :". I made a further change to my command to "fix" this, but I don't know if I have broken something else in the process.

So my final command is:
uptime | awk '{print "UPTIME: " $3 " " $4 " " $5 " " }'; top -l 1 | awk '/PhysMem/ {print "RAM: " $8 " "}' ; top -l 2 | awk '/CPU usage/ && NR > 5 {print "CPU: " $8, $9="user ", $10, $11="sys ", $12, $13}'

and gives me the following output:
UPTIME: 5 days, 23:44,
RAM: 1906M
CPU: idle user sys

Any and all help you can provide would be appreciated.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Give this a read.

EDIT: On second thought, what I have might work for you:
Code:
top -l1 | grep "CPU usage"; top -l1 | grep "PhysMem"
Sorry, can't remember where I found that. Set that to refresh however you want it to refresh.
 
OP
ArrowJ
Joined
Oct 18, 2009
Messages
110
Reaction score
8
Points
18
Ok, that is so much simpler. I am not a command line guru so I have no idea why someone would choose the other way. I did notice something weird.

When I run top from the prompt it shows a significantly higher idle percentage (well, the other numbers are off too) compared to when I run top -l1 | grep "CPU usage"; top -l1 | grep "PhysMem" from the prompt or in GeekTool...

For instance, right now terminal shows:
10/24/60 (in percentages user, sys, idle)
and GeekTool (set to refresh every 3 seconds) shows:
15/85/0 (in percentages user, sys, idle)

So I wonder if the readings are useful or not...the PhysMem readouts are the spot on.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
CPU usage changes constantly. Try running the command I posted earlier and running it right away again. My guess is that the subtle changes in CPU usage is the cause of the discrepancy.
 
OP
ArrowJ
Joined
Oct 18, 2009
Messages
110
Reaction score
8
Points
18
I don't know...the differences aren't so subtle. Check out this screenshot. The one on the desktop is GeekTool running the command you provided. It updates every three seconds...I wait till it updates and snap the screen. The differences are large. If you look closely you see that the PhysMem is almost exactly the same in terminal and Geektool. I have no idea why it would do that, but the command you gave seems to react well to what I'm doing on the computer.

http://bit.ly/6b1uOA
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top