Skip to content

Commit 6234ac1

Browse files
committed
add netload
1 parent 91423ab commit 6234ac1

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

netload/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM alpine:3.14.0
2+
MAINTAINER LWQ kenan3015@gmail.com
3+
4+
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
5+
&& apk add --update --no-cache bash wget \
6+
&& rm -rf /var/cache/apk/*
7+
8+
ADD main.sh /tmp/main.sh

netload/main.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#! /bin/bash
2+
3+
##
4+
# 循环下载文件,目的是增加网络负载
5+
# 使用 ./main.sh 300k 5 http://localhost:8080/file.txt
6+
# 其中300k是下载速度上限,作为参数传递给wget --limit-rate
7+
# 5是sleep时间,单位是秒,如果为0则不sleep,一直循环下载
8+
# http://localhost:8080/file.txt 是下载文件的url地址
9+
##
10+
set -ex
11+
12+
# 默认参数
13+
limit_rate=500k
14+
file_url=k8s-master:6000/netload.txt
15+
interval=1 #默认秒
16+
file_name=netload
17+
18+
# 使用信息
19+
usage(){
20+
cat <<-EOF
21+
Usage: ./main.sh 300k 5 http://localhost:8080/file.txt
22+
Flags:
23+
300k 下载速度上限,作为参数传递给wget --limit-rate
24+
5 是sleep时间,单位是秒,如果为0则不sleep,一直循环下载
25+
http://localhost:8080/file.txt 下载文件的url地址
26+
Node:
27+
必须按顺序指定3个参数,且参数类型要符合规范
28+
EOF
29+
}
30+
31+
# 主执行逻辑
32+
main() {
33+
for (( ; ; ))
34+
do
35+
# wget --no-proxy --limit-rate=$limit_rate -O $file_name $file_url
36+
wget --limit-rate=$limit_rate -O $file_name $file_url
37+
rm $file_name
38+
if (($interval >= 1));then
39+
sleep $interval
40+
fi
41+
done
42+
}
43+
44+
# 参数
45+
if test $# -eq 3;then
46+
limit_rate=$1
47+
interval=$2
48+
file_url=$3
49+
main
50+
else
51+
usage
52+
exit
53+
fi

netload/start.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#! /bin/bash
2+
3+
docker run -d --name netload \
4+
netload:v1 \
5+
/tmp/main.sh 300k 1 https://wangdoc.com/bash/condition.html

0 commit comments

Comments
 (0)