Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
conky: how to overcome 32-bit data limit
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message

Joined: 14 Jun 2007
Posts: 201
Location: Helsinki, Finland

PostPosted: Wed Jul 16, 2008 8:45 pm    Post subject: conky: how to overcome 32-bit data limit Reply with quote

All you who use Conky as your system monitor, here's a very short guide how to overcome 32-bit integer limitation with data transfers.

Introduction (Skip if you know what's 32-bit data limit)
From wikipedia:
In computer architecture, 32-bit integers, memory addresses, or other data units are those that are at most 32 bits (4 octets) wide. Also, 32-bit CPU and ALU architectures are those that are based on registers, address buses, or data buses of that size. 32-bit is also a term given to a generation of computers in which 32-bit processors were the norm.
The range of integer values that can be stored in 32 bits is 0 through 4,294,967,295 or −2,147,483,648 through 2,147,483,647 using two's complement encoding. Hence, a processor with 32-bit memory addresses can directly access 4 GB of byte-addressable memory.
The external address and data buses are often wider than 32 bits but both of these are stored and manipulated internally in the processor as 32-bit quantities. For example, the Pentium Pro processor is a 32-bit machine, but the external address bus is 36 bits wide, and the external data bus is 64 bits wide.

That is the reason why for example in ifconfig the data transfer seems to start from zero after reaching about 4 gigabytes.
Here's a little presentation what's the difference between 32- and 64-bit architectures in this cituation:
~ $ calc
C-style arbitrary precision calculator (version
Calc is open software. For license details type:  help copyright
[Type "exit" to exit, or "help" for help.]

; 2^32
; 2^64
; 2^32/1024/1024
; 2^64/1024/1024
; exit

As you can see. Lines containing /1024/1024 at the end divide the resulting bytes to megabytes. Now.. if you have 64-bit computer - don't waste your time here. It will take ages to reach 17592186044416 megabytes (16777216 terabytes!!!) with current consumer targeted speeds. If you have 32-bit computer there's the 4096 megabyte (4Gb) limit. Here's how you can overcome that limit in Conky.

Bang a gong, let's get it on

What you need is vnstat. Check the URL for more info about vnstat.
You need to install it:
emerge vnstat

Then (as root) add one of your network interfaces to be monitored:
vnstat -u -i eth0
(replace eth0 with the network interface you want to be monitored)

Then I STRONGLY suggest you to edit the /etc/cron.hourly/vnstat and uncomment the lines there (instructions are inside the file).
NOTE: If you transfer much data you might want to vnstat update it's database more frequently than just once in a hour.
From 'man vnstat':
Updates needs to be executed at least as often as it is possible for the interface to generate enough traffic to wrap the kernel interface traffic counter. Otherwise it is possible that some traffic won't be seen. This isn't an issue for 64 bit kernels but at least one update every hour is always required in order to provide proper input. With 32 bit kernels the maximum time between two updates depends on how fast the interface can transfer 4 GB. Calculated theoretical times are:

10 Mbit: 54 minutes
100 Mbit: 5 minutes
1000 Mbit: 30 seconds

However, for 1000 Mbit interfaces updating once every minute is usually a working solution.

Estimated traffic values are likely to be somewhat inaccurate if daily traffic is low because only the MB counter is used to calculate the estimate.

Now all you need is a small code to add into your ~/.conkyrc (below the line where 'TEXT' reads) in the place where you want conky to show data transfers.
Here's two examples:
In megabytes use:
Tx: ${execi 60 vnstat --dumpdb | sed -e '/^totaltx;/!d' -e 's/^.*;//'}MiB | Rx: ${execi 60 vnstat --dumpdb | sed -e '/^totalrx;/!d' -e 's/^.*;//'}MiB

In gigabytes you have to use a bit more complex code (I belive there are many more simple ways to do this):
Tx: ${execi 60 ( echo "scale=1" && vnstat --dumpdb | sed -e '/^totaltx;/!d' -e 's/^.*;\(.*\)$/\1\/1024/' ) | bc}GiB | Rx: ${execi 60 ( echo "scale=1" && vnstat --dumpdb | sed -e '/^totalrx;/!d' -e 's/^.*;\(.*\)$/\1\/1024/' ) | bc}GiB

Note that I used 60 second interval here, so this won't bother your cpu too much. ;)

And finally: All the improvement's are welcome. :)
Threading support for your bash scripts.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum