]> arthur.barton.de Git - netdata.git/blob - tests/stress.sh
572dc7d19c6ea546372f58fea2b4d0b267d61750
[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 # to compare equal things, set the entries to 3600 max
26 [ $entries -gt 3600 ] && entries=3600
27
28 if [ $entries -ne 3600 ]
29         then
30         echo >&2 "You are running a test for a history of $entries entries."
31 fi
32
33 modes=("average" "max")
34 formats=("jsonp" "json" "ssv" "csv" "datatable" "datasource" "tsv" "ssvcomma" "html" "array")
35 options="flip|jsonwrap"
36
37 now=$(date +%s)
38 first=$[now - (entries * update_every)]
39 duration=$[now - first]
40
41 file="$(mktemp /tmp/netdata-stress-XXXXXXXX)"
42 cleanup() {
43         echo "cleanup"
44         [ -f $file ] && rm $file
45 }
46 trap cleanup EXIT
47
48 while [ 1 = 1 ]
49 do
50         echo "curl --compressed --keepalive-time 120 --header \"Connection: keep-alive\" \\" >$file
51         for x in {1..100}
52         do
53                 dt=$[RANDOM * duration / 32767]
54                 st=$[RANDOM * duration / 32767]
55                 et=$[ st + dt ]
56                 [ $et -gt $now ] && st=$[ now - dt ]
57
58                 points=$[RANDOM * 2000 / 32767 + 2]
59                 st=$[first + st]
60                 et=$[first + et]
61
62                 mode=$[RANDOM * ${#modes[@]} / 32767]
63                 mode="${modes[$mode]}"
64
65                 chart=$[RANDOM * ${#charts[@]} / 32767]
66                 chart="${charts[$chart]}"
67
68                 format=$[RANDOM * ${#formats[@]} / 32767]
69                 format="${formats[$format]}"
70
71                 echo "--url \"$host/api/v1/data?chart=$chart&mode=$mode&format=$format&options=$options&after=$st&before=$et&points=$points\" \\"
72         done >>$file
73         bash $file >/dev/null
74 done