32

CPU,Memory & Disk Usage Meter

Posted in System by poedba 1213 days ago

This Geeklet show the current CPU, Memory and Disk usage on a simple meter that represents the current percentage.  This geeklet was last updated on 07/01/2011.  Fixed issues to more accurately reflect CPU, Memory and Disk Usage.

screenshot

To change the colors, fine the lines that look like this...

echo "\33[1;34m*\33[0m\c"

Change 34 to any of the following for different colors.

30 - Black; 31 - Red; 32 - Green; 33 - Yellow; 34 - Blue; 35 - Purple; 36 - Light Blue; 37 - White; 39 - Grey;

Also, you can change the * on tihs line to show another character.

Geeklet files to download

Comments

User Avatar
hobs 1179 days ago
This has an error because it does assignment to self myDisk=`expr 100-$myDisk` which bash hates. Check your console logs for "myDisk command not found" and you will see what I mean.

If you assign that value in a new variable and reference it later and unset it later, works fine.
User Avatar
thelowbrow 1171 days ago
I really like this one, but was wondering what I have to modify to change the colored asterisk from purple to black?

Thanks
User Avatar
poedba 1117 days ago
LowBrow,

I updated the attached geeklet for accuracy also, I've included intructions for changing the color.  Let me know if everything works out.
User Avatar
mrbeast87 1157 days ago
This is the most amazing geeklet I've ever seen!

The problem is the CPU usage is not accurate. You're using "top -l 1" to get the CPU usage, but as you can read in the manual: Note that the first sample displayed will have an invalid %CPU displayed for each process, as it is calculated using the delta between samples.

Wich means you just get the random sample. Using "top -l 2", considering only the second output would do the job. But I don't know how to do it... Can anybody solve this?Cheers
User Avatar
poedba 1117 days ago
MrBeast87,

I noticed that the CPU looked weird too.  To say that it is not accurate isn't a completely accurate statement.  However, the measure being displayed wasn't what I wanted and from the sounds of it, you either.  Anyway I changed the calculation to show the expected results.  Let me know if this looks better.
User Avatar
onemanzu 453 days ago
I was constantly having issues with the way the cpu was calculated as well, no way my computer was using 70% cpu constantly.

here was my solution.

cpu1=$(top -l 2 | awk '/CPU usage/{i++} i==2{print; exit;}' | awk '{print $7}' | head -c2)

myCPU=$(echo $((100 - $cpu1)))
User Avatar
black 1052 days ago
Running this on Lion I get the following error message:

(standard_in) 1: parse error

Memory Usage \c

./test.sh: line 31: [: 5: unary operator expected

...

.expr: syntax error

./test.sh: line 54: myDisk: command not found

Disk Usage \c

./test.sh: line 57: [: 5: unary operator expected

The only colored stars are in the CPU Usage row, Memory Usage and Disk usage are not working.

Any ideas on why?
User Avatar
Fleek 1035 days ago
My guess is the paths are different. A lot of paths were changed from Snow Leopard to Lion. Unfortunately I don't know enough about the code to change it.

Hopefully the original developer will come back and give us a fix.
User Avatar
poedba 1025 days ago
Sorry for taking so long to respond. I've uploaded a new version of this. I'm not sure why this was trying to call test.sh but I believe I've removed all references.
User Avatar
mulcahey 985 days ago
Thanks for posting the asterisk color-change info. Is there any way to change it to orange?

Thanks.
User Avatar
hellomelon 836 days ago
No there is no way, at least not the way this geeklet is coded, since the geeklet uses the 'echo' command which only supports the colors mentioned
User Avatar
ajimix 805 days ago
If memory isn't working you should add this line after line 39.

So line 40 will be like this...

myUsedPer=`echo $myUsedPer | sed 's/,/./g'`

The problem is that some systems use "," as decimal separator and that line changes it to "."
User Avatar
Monophonic 608 days ago
I like these, but how can I use a separate font? Anytime I use a font other than what the geeklet came with, the spacing gets offset. Is there anyway to distance the text from the bar and make everything even?
User Avatar
YourFloorIsLava 565 days ago
I have the same question. It seems Courier (and other typewriter fonts, I'd imagine) also works for the spacing, but I haven't found how to add spaces to compensate for other font types.

Edit: Found it! You can change the spacing before the symbols by adding spaces or tabs before "\c" on the lines:

echo "CPU Usage \c"

echo "Memory Usage \c"

echo "Disk Usage \c"

And you can change the space between the symbols and the percentages the same way by modifying the lines:

echo " $myCPU%\c"

echo " $myUsedPer%\c"

echo " $myDisk%\c"

Hope this helps!
User Avatar
slim 466 days ago
Hi poedba, I realise this is pretty old by now, but I have just discovered it and I was wondering how I would go about changing the size of the Asterisks within the line of code, kind of like how you described changing the font colours, because that was really easy to follow. I have tried trial and error but haven't stumbled across the right value yet.

Hope you can reply! Thanks.

Log in to comment or register here.