stress.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  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. # shellcheck disable=SC2207 disable=SC1117
  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. update_every="$(curl "$host/netdata.conf" 2>/dev/null | grep "update every = " | head -n 1 | cut -d '=' -f 2)"
  19. [ $(( update_every + 1 - 1)) -eq 0 ] && update_every=1
  20. entries="$(curl "$host/netdata.conf" 2>/dev/null | grep "history = " | head -n 1 | cut -d '=' -f 2)"
  21. [ $(( entries + 1 - 1)) -eq 0 ] && entries=3600
  22. # to compare equal things, set the entries to 3600 max
  23. [ $entries -gt 3600 ] && entries=3600
  24. if [ $entries -ne 3600 ]
  25. then
  26. echo >&2 "You are running a test for a history of $entries entries."
  27. fi
  28. modes=("average" "max")
  29. formats=("jsonp" "json" "ssv" "csv" "datatable" "datasource" "tsv" "ssvcomma" "html" "array")
  30. options="flip|jsonwrap"
  31. now=$(date +%s)
  32. first=$((now - (entries * update_every)))
  33. duration=$((now - first))
  34. file="$(mktemp /tmp/netdata-stress-XXXXXXXX)"
  35. cleanup() {
  36. echo "cleanup"
  37. [ -f "$file" ] && rm "$file"
  38. }
  39. trap cleanup EXIT
  40. while true
  41. do
  42. echo "curl --compressed --keepalive-time 120 --header \"Connection: keep-alive\" \\" >"$file"
  43. # shellcheck disable=SC2034
  44. for x in {1..100}
  45. do
  46. dt=$((RANDOM * duration / 32767))
  47. st=$((RANDOM * duration / 32767))
  48. et=$(( st + dt ))
  49. [ $et -gt "$now" ] && st=$(( now - dt ))
  50. points=$((RANDOM * 2000 / 32767 + 2))
  51. st=$((first + st))
  52. et=$((first + et))
  53. mode=$((RANDOM * ${#modes[@]} / 32767))
  54. mode="${modes[$mode]}"
  55. chart=$((RANDOM * ${#charts[@]} / 32767))
  56. chart="${charts[$chart]}"
  57. format=$((RANDOM * ${#formats[@]} / 32767))
  58. format="${formats[$format]}"
  59. echo "--url \"$host/api/v1/data?chart=$chart&mode=$mode&format=$format&options=$options&after=$st&before=$et&points=$points\" \\"
  60. done >>"$file"
  61. bash "$file" >/dev/null
  62. done