簡體   English   中英

限速 Ubuntu 基於流量

[英]Limit Speed in Ubuntu based on traffic

我遇到了一個腳本,即 Wondershaper

腳本很棒,但是有什么方法可以讓它更聰明?

就像它在某些流量通過后運行?

說每天設置1TB,一旦達到1TB,腳本會自動開啟?

我曾想過設置 crn 工作,

凌晨 12 點清除 Wondershaper,每隔 15 分鍾檢查服務器當天是否超過 1TB 限制,如果是,則運行限制器,

但我不知道如何設置第二部分,我如何設置一種方式,使限制器在超過 1TB 后運行?

刪除代碼

wondershaper -ca eth0

限制代碼

wondershaper -a eth0 -u 154000

我為此制作了一個自定義腳本,因為無法在系統內執行此操作,我必須發揮創造力並對數據中心進行 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

您可以隨時根據自己的喜好更新它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM