run_tests_prom.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. # Detect cmake build and adjust path
  3. BINDIR="../bin"
  4. if [ ! -f $BINDIR/turnserver ]; then
  5. BINDIR="../build/bin"
  6. fi
  7. function assert_prom_no_response() {
  8. wget --quiet --output-document=/dev/null --tries=1 "$1"
  9. status="$?"
  10. if [ "$status" -eq 0 ]; then
  11. echo FAIL
  12. exit 1
  13. else
  14. echo OK
  15. fi
  16. }
  17. function assert_prom_response() {
  18. # Match something that looks like the expected body
  19. wget --quiet --output-document=- --tries=1 "$1" | grep 'TYPE\|HELP\|counter\|gauge' >/dev/null
  20. status="$?"
  21. if [ "$status" -eq 0 ]; then
  22. echo OK
  23. else
  24. echo FAIL
  25. exit "$status"
  26. fi
  27. }
  28. echo "Running without prometheus"
  29. $BINDIR/turnserver /dev/null &
  30. turnserver_pid="$!"
  31. sleep 2
  32. assert_prom_no_response "http://localhost:9641/metrics"
  33. kill "$turnserver_pid"
  34. echo "Running turnserver with prometheus, using defaults"
  35. $BINDIR/turnserver --prometheus > /dev/null &
  36. turnserver_pid="$!"
  37. sleep 2
  38. assert_prom_response "http://localhost:9641/metrics"
  39. kill "$turnserver_pid"
  40. echo "Running turnserver with prometheus, using custom address"
  41. $BINDIR/turnserver --prometheus --prometheus-address="127.0.0.1" > /dev/null &
  42. turnserver_pid="$!"
  43. sleep 2
  44. assert_prom_response "http://127.0.0.1:9641/metrics"
  45. kill "$turnserver_pid"
  46. echo "Running turnserver with prometheus, using custom port"
  47. $BINDIR/turnserver --prometheus --prometheus-port="8080" > /dev/null &
  48. turnserver_pid="$!"
  49. sleep 2
  50. assert_prom_response "http://localhost:8080/metrics"
  51. kill "$turnserver_pid"
  52. echo "Running turnserver with prometheus, using custom address and port"
  53. $BINDIR/turnserver --prometheus --prometheus-address="127.0.0.1" --prometheus-port="8080" > /dev/null &
  54. turnserver_pid="$!"
  55. sleep 2
  56. assert_prom_response "http://127.0.0.1:8080/metrics"
  57. kill "$turnserver_pid"
  58. echo "Running turnserver with prometheus, using custom path"
  59. $BINDIR/turnserver --prometheus --prometheus-path="/coturn/metrics" > /dev/null &
  60. turnserver_pid="$!"
  61. sleep 2
  62. assert_prom_response "http://localhost:9641/coturn/metrics"
  63. kill "$turnserver_pid"