]> arthur.barton.de Git - netdata.git/blob - tests/stress.sh
stress test for netdata server
[netdata.git] / tests / stress.sh
1 #!/bin/bash
2
3 # set the host to connect to
4 if [ ! -z "$1" ]
5         then
6         host="$1"
7 else
8         host="http://127.0.0.1:19999"
9 fi
10 echo "using netdata server at: $host"
11
12 charts=($(curl "$host/netdata.conf" 2>/dev/null | grep "^\[" | cut -d '[' -f 2 | cut -d ']' -f 1 | grep -v ^global$ | grep -v "^plugin" | sort -u))
13 if [ "${#charts[@]}" -eq 0 ]
14         then
15         echo "Cannot download charts from server: $host"
16         exit 1
17 fi
18
19 update_every="$(curl "$host/netdata.conf" 2>/dev/null | grep "update every = " | head -n 1 | cut -d '=' -f 2)"
20 [ $[ update_every + 1 - 1] -eq 0 ] && update_every=1
21
22 entries="$(curl "$host/netdata.conf" 2>/dev/null | grep "history = " | head -n 1 | cut -d '=' -f 2)"
23 [ $[ entries + 1 - 1] -eq 0 ] && entries=3600
24
25 modes=("average" "max")
26 formats=("jsonp" "json" "ssv" "csv" "datatable" "datasource" "tsv" "ssvcomma" "html" "array")
27 options="flip|jsonwrap"
28
29 now=$(date +%s)
30 first=$[now - (entries * update_every)]
31 duration=$[now - first]
32
33 file="$(mktemp /tmp/netdata-stress-XXXXXXXX)"
34 cleanup() {
35         echo "cleanup"
36         [ -f $file ] && rm $file
37 }
38 trap cleanup EXIT
39
40 while [ 1 = 1 ]
41 do
42         echo "curl --compressed --keepalive-time 120 --header \"Connection: keep-alive\" \\" >$file
43         for x in {1..100}
44         do
45                 dt=$[RANDOM * duration / 32767]
46                 st=$[RANDOM * duration / 32767]
47                 et=$[ st + dt ]
48                 [ $et -gt $now ] && st=$[ now - dt ]
49
50                 points=$[RANDOM * 2000 / 32767 + 2]
51                 st=$[first + st]
52                 et=$[first + et]
53
54                 mode=$[RANDOM * ${#modes[@]} / 32767]
55                 mode="${modes[$mode]}"
56
57                 chart=$[RANDOM * ${#charts[@]} / 32767]
58                 chart="${charts[$chart]}"
59
60                 format=$[RANDOM * ${#formats[@]} / 32767]
61                 format="${formats[$format]}"
62
63                 echo "--url \"$host/api/v1/data?chart=$chart&mode=$mode&format=$format&options=$options&after=$st&before=$et&points=$points\" \\"
64         done >>$file
65         bash $file >/dev/null
66 done