计算上滚动的总吞吐量 [英] Calculate throughput on a rolling total

查看:140
本文介绍了计算上滚动的总吞吐量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道,如果是在我的系统缺少咖啡因与否,但我不能为我的生活搞清楚这样做的正确的方法是(数学)的东西。

I'm not sure if it's the lack of caffeine in my system or not, but I can't for the life of me figure out what the correct way of doing this is (math).

我已经得到了一个记录的ethtool解析的值的脚本-S每一个'X'(6本次测试过程中)秒,直到它的手动停止。我得如何计算的迭代等的code,但我无法弄清楚如何正确每秒计算平均字节。

I've got a script that records the values of a parsed ethtool -S every 'x' (6 during this test) seconds until it's manually stopped. I've got the code on how to calculate iterations etc, but I can't figure out how to correctly calculate average bytes per second.

下面是输出的样子:

Fri Jun  8 23:48:35 GMT 2012 {{{
============== Network Statistics ===============
IFNAME     rx_bytes        tx_bytes
eth0      27840111418      3083391508
eth4      6153013050      18478875401
eth5      686368648      238683883
eth6      53863181321      2119523154
eth7      23127231747      84602654827
eth8      399517273166      1686004510

Fri Jun  8 23:48:41 GMT 2012 {{{
============== Network Statistics ===============
IFNAME     rx_bytes        tx_bytes
eth0      27840118248      3083392896
eth4      6153014438      18478876789
eth5      686370036      238685271
eth6      53863182709      2119524542
eth7      23127238019      84602660337
eth8      399519325260      1686018706

正如我们所看到的字节都递增,我将有成千上万的这种迭代的。

As we can see the bytes have all incremented, and I'm going to have thousands of iterations of this.

什么是的在每个接口的基础上完全这些数字正确的方式计算平均每秒字节(我最终还是会通过其移动到Mbps的* 0.00000762939453)。

What's the correct way of totally these numbers on a per interface basis and calculating the average bytes per second ( I'll eventually move it to mbps via * 0.00000762939453).

我用尽了一切至今未能...悲惨:\\

Everything I've tried has so far failed...miserably :\

感谢您的时间/耐心/援助!

Thank you for your time/patience/assistance!

:
我目前的认为的我需要做的就是删除RX原值/ TX字节正常化的数据。我现在的(丑陋的)字符串拉动初始的总和是这样的:

: What I currently think I need to do is remove the original value for rx/tx bytes to normalize the data. My current (ugly) string for pulling the initial sum is this:

int1_rx_bytes=`cat $logfile | grep $int1 | awk '{print $2}' | awk '{sum+=$1} END {printf "%f", sum}'`

我会在哪里把原来的号码有减法的目的呢?作为参考,我有一个名为变量$ int1_orig_rx_bytes已

Where would I put the original number there for subtraction purposes? For reference, I've got a variable named $int1_orig_rx_bytes already

推荐答案

这两个脚本未经测试。

有关移动平均线:

awk 'BEGIN {
    period = 10
    pcount=1
}
NR == 1 {
    baserx = $2
    basetx = $3
}
{
    rx[$1, pcount] = $2 - baserx
    tx[$1, pcount] = $3 - basetx
    ifaces[$1]
    if (c >= period) {
        rxsum = txsum = 0
        for (iface in ifaces) {
            for (i = 1; i <= period; i++) {
                rxsum += rx[iface, i]
                txsum += tx[iface, i]
            }
            print iface, rxsum / period, txsum / period
        }
    } else {
        c++
    }
    pcount = (pcount + 1) % period + 1
}'

编辑:

对于一个普通的所有条目的:

For an average of all entries:

awk '
NR == 1 {
    baserx = $2
    basetx = $3
}
{
    rx[$1] += $2 - baserx
    tx[$1] += $3 - basetx
}
END {
    for (iface in rx) {
        print iface, rx[iface] / NR, tx[iface] / NR
    }
}'

订单的条目将被输出不能保证。如果你有 GAWK 您可以添加将采取照顾排序的功能,也可以使用排序工具。

The order that entries will be output is not guaranteed. If you have gawk you can add a sort function that will take care of that or you can use the sort utility.

编辑2:

这纠正了各种问题与上面的第二个版本。

This corrects all kinds of problems with the second version above.

awk '
    BEGIN {
        OFMT = "%.4f"
    }

    /^[[:blank:]]*$/ { next }

    ! ($1 in prevrx) {
        prevrx[$1] = $2
        prevtx[$1] = $3
        next
    }
    {
        count[$1]++
        drx = $2 - prevrx[$1]
        dtx = $3 - prevtx[$1]
        rx[$1] += drx
        tx[$1] += dtx
        prevrx[$1] = $2
        prevtx[$1] = $3
    }
    END {
        for (iface in rx) {
            print iface, rx[iface] / count[iface], tx[iface] / count[iface]
        }
}'

这篇关于计算上滚动的总吞吐量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆