Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Welcome,

I use conky to see network load statistics with sampling every 8 seconds in order to get somewhat more smooth history chart. Unfortunately, all values i get are not average for this 8 second period, but they are sampled from much smaller time span, so charts are the same choppy, as if they were sampled from 1 second or less.

Is there any way to get conky (or at least System Monitor) display system properties averaged over specified amount of time, just like Windows' task manager does?

I would like to have conky display hard drive usage from iostat, but there will be little use if it, if conky reports instant values not averaged over time.

edit: There is half-solution to the specific network problem in utility ifstat. This program if run

ifstat 8 1

does indeed give proper network load averages over 8-second interval. But, from obvious reasons, this call takes 8 second to complete. I am trying to learn enough lua to get this working.

share|improve this question
add comment

2 Answers

If you want a program to give you a good digest of network activity, vnstat is probably what you what; as I note below you can use a program called vnstati to give you a graph of a specified time frame from the vnstat database.

First, download the programs:

sudo apt-get install vnstat vnstati

Set up the database initially if the interface you want to monitor is eth0; you can use this command to update the database later:

sudo vnstat -u -i eth0

If your default interface is not eth0, you can change it either by editing the default interface entry in /etc/vnstat.conf or simply by creating a .vnstat file in your home folder and adding Interface "eth1" at the top of the file.

Vnstat monitors your network usage on the specified adapter, although you can see the live details by entering:

vnstat -l -i eth0

You can also view statistics from the command line by the hour, week, month, etc (although it is best to do a database update first with the sudo command further above). Here is an example command to display the daily usage: (substitute d for h for hourly, w for weekly)

vnstat -d -i eth0

A lot more statistical analysis is available with vnstat, see man vnstat or the Ubuntu manpages online.

See the graphs from vnstati below using the following commands to show hourly usage and daily usage: (You can also show weekly, monthly, etc, times and display the data in different ways) (Again do a database update with vnstat before running these vnstati commands)

vnstati -h -i eth1 -o net.png
vnstati -d -i eth1 -o net2.png

(The first graph is somewhat blank as I've only just started using vnstat and by the way my default interface is eth1, whereas yours is probably eth0)

For more options on vnstati and all the statistics from the vnstat database that it can output, see man vnstati and the Ubuntu manpages online.

enter image description here enter image description here

share|improve this answer
    
Thank you very much. I was rather looking for a way general way to make any system statistics being an average instead of instant values, but I understand, that there is none, and I have to solve each system information domain separately. The program you've shown looks like very interesting and I will give it a try. –  Adam Ryczkowski Sep 1 '12 at 16:35
add comment

Well, it might be very crude (i'm not an expert in scripting programming, and it is my very first program written in Lua), but it does solve my problem.

It works by calling the make-netstat in the background which calls ifstat which averages statistics for a little less than conky refresh interval (8 seconds). The results are written to temporary file, which is subsequently read in the next refresh run of conky.

Because of disk I/O it is not the recommended solution for users of SSD disks. The statistics also don't account for the 0.5 second gap which exist to prevent race conditions between make-netstat and the conky.

I created the a couple of files in ~/.conky directory. make-netstats.sh:

#!/bin/sh
ifstat -i wlan0 -n $1 1|tail -n 1 >~/.conky/wifi-stats-new.txt
cp ~/.conky/wifi-stats-new.txt ~/.conky/wifi-stats.txt

call-make-netstats.sh: (for some reasons the ,,~'' as a shortcut to home directory doesn't work, so I put full home folder path.)

#!/bin/sh
/home/adam/.conky/make-netstats.sh $1 &

netstat.lua:

do
    function conky_prepare_wlan_stats(czas)
        os.execute("/home/adam/.conky/call-make-netstats.sh " .. czas)
    end
    function conky_get_wlan_input()
        local f = io.open("/home/adam/.conky/wifi-stats.txt", "r")
        local str = f:read("*all")
        local sin = string.gsub(str, "^%s*([%d%.]+)%s*([%d%.]+)%s*","%1")
        return sin
    end
    function conky_get_wlan_output()
        local f = io.open("/home/adam/.conky/wifi-stats.txt", "r")
        local str = f:read("*all")
        local out = string.gsub(str, "^%s*([%d%.]+)%s*([%d%.]+)%s*","%2")
        return out
    end
end

And finally we use it in .conky.rc in the following way:

${font Goudy Bookletter 1911:style=Normal}WIRELESS${font} ${hr 2}
${voffset 4}${font PizzaDude Bullets:size=14}O${font}   Up: ${lua conky_get_wlan_output} ${alignr} ${voffset -10} ${lua_graph  conky_get_wlan_output 20,200 300}
${lua conky_prepare_wlan_stats 7.5} #The function prepares statistics for another refresh of conky stat. 7.5 is slightly less then 8 seconds to prevent from overlap.1

${voffset -30}${font PizzaDude Bullets:size=14}U${font}   Down: ${lua conky_get_wlan_input} ${alignr} ${voffset -10} ${lua_graph  conky_get_wlan_input 20,200 300}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.