【问题标题】:Limit Speed in Ubuntu based on traffic根据流量限制Ubuntu中的速度
【发布时间】:2020-05-28 15:12:56
【问题描述】:

我遇到了一个脚本,即 Wondershaper

脚本很棒,但是有什么方法可以让它更聪明?

喜欢在某些流量通过后运行?

说每天设置1TB,一旦达到1TB,脚本自动开启?

我考虑过设置crn job,

在凌晨 12 点清除 Wondershaper,并在 15 分钟间隔内检查服务器是否超过了当天的 1TB 限制,如果是,则运行限制器,

但我不知道如何设置第二部分,我该如何设置一种方式,让限制器在超过 1TB 后运行?

删除代码

wondershaper -ca eth0

限制代码

wondershaper -a eth0 -u 154000

【问题讨论】:

    标签: performance ubuntu bandwidth-throttling


    【解决方案1】:

    我为此制作了一个自定义脚本,因为无法在系统内执行此操作,我必须发挥创造力并对数据中心进行 API 调用,然后运行 ​​cron 作业。

    我还使用bashjson 来运行它。我附上了下面的脚本。

    date=$(date +%F)
    url='API URL /metrics/datatraffic?from='
    url1='T00:00:00Z&to='
    url2='T23:59:59Z&aggregation=SUM'
    final="$url$date$url1$date$url2"
    
    wget --no-check-certificate -O output.txt \
      --method GET \
      --timeout=0 \
      --header 'X-Lsw-Auth: API AUTH' \
       $final
    
    sed 's/[][]//g' output.txt >> test1.json // will remove '[]' from the code just to make things easier for bashjson to understand
    down=$(/root/bashjson/bashjson.sh test1.json metrics DOWN_PUBLIC values value) // outputs the data to variable
    up=$(/root/bashjson/bashjson.sh test1.json metrics UP_PUBLIC values value)
    
    
    newdown=$(printf "%.14f" $down)
    newup=$(printf "%.14f" $up)
    
    
    upp=$(printf "%.0f\n" "$newup") // removes scientific notation as bash does not like it
    downn=$(printf "%.0f\n" "$newdown")
    
    if (($upp>800000000000 | bc))
    then
    wondershaper -a eth0 -u 100000 //main command to limit
    else
    echo uppworks
    fi
    
    if (($downn>500000000000 | bc))
    then
    wondershaper -a eth0 -d 100000
    else
    echo downworks
    fi
    
    rm -rf output.txt test1.json
    
    echo $upp
    echo $downn
    

    您可以随时根据自己的喜好进行更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-14
      • 2012-12-14
      • 1970-01-01
      • 2021-11-11
      • 1970-01-01
      • 2018-12-30
      • 2019-12-25
      • 1970-01-01
      相关资源
      最近更新 更多