Re: [dwm] Statusbar gadget: cpubar

From: Alexandre Boily <alexandreboily_AT_gmail.com>
Date: Tue, 19 Jun 2007 12:50:54 +0000 (UTC)

Robert Manea <rob.manea@...> writes:

>
> Used with dzen it could looks like this:
> http://omploader.org/file/xmonad-cpubar.png
>

Some days ago I hacked a ruby script to monitor my network connection. By a
happy coincidence, I happen to use the same characters.

Here is my script. It also displays CPU temperature and the date.

#!/usr/bin/ruby

PIPE = "/home/boily/.dwm-status"
INTERFACE = "eth0"
RXMAX = 600
TXMAX = 200
CPUTEMPFILE = "/sys/bus/i2c/devices/0-004c/temp2_input"
DATETIME = "%d.%m.%Y - %H:%M"

def probar(new, last, max)
    diff = ((new - last) / max * 10).round
    if diff > 10 then
        diff = 10
    end
    return "[" + "=" * diff + " " * (10 - diff) + "]"
end

RXFILE = "/sys/class/net/#{INTERFACE}/statistics/rx_bytes"
TXFILE = "/sys/class/net/#{INTERFACE}/statistics/tx_bytes"

rx = File.read(RXFILE).to_f / 1024
tx = File.read(TXFILE).to_f / 1024

while not `pidof dwm`.chomp.empty?
    rxnew = File.read(RXFILE).to_f / 1024
    txnew = File.read(TXFILE).to_f / 1024

    cputemp = File.read(CPUTEMPFILE).to_f / 1000
    datetime = Time.now.strftime(DATETIME)

    File.open(PIPE, 'w') do |ligne|
        ligne.print "<-%s ->%s - %.1f°C - %s\n" % [probar(rxnew, rx, RXMAX),
probar(txnew, tx, TXMAX), cputemp, datetime]
    end

    sleep 1

    rx = rxnew
    tx = txnew
end
Received on Tue Jun 19 2007 - 15:38:57 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:44:48 UTC