You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.5 KiB

  1. # Pinging Reliability Tips
  2. Sending monitoring signals over the public internet is inherently unreliable.
  3. HTTP requests can sometimes take excessively long or fail completely
  4. for a variety of reasons. Here are some general tips to make your monitoring
  5. code more robust.
  6. ## Specify HTTP Request Timeout
  7. Put a time limit on how long each ping is allowed to take. This is especially
  8. important when sending a "start" signal at the start of a job: you don't want
  9. a stuck ping to prevent the actual job from running. Another case is a continuously
  10. running worker process that pings SITE_NAME after each completed item. A stuck
  11. request could block the whole process. An explicit per-request time limit mitigates
  12. this problem.
  13. Specifying the timeout depends on the tool you use. curl, for example, has the
  14. `--max-time` (shorthand: `-m`) parameter:
  15. ```bash
  16. # Send an HTTP request, 10 second timeout:
  17. curl -m 10 PING_URL
  18. ```
  19. ## Use Retries
  20. To minimize the amount of false alerts you get from SITE_NAME, instruct your HTTP
  21. client to retry failed requests several times.
  22. Specifying the retry policy depends on the tool you use. curl, for example, has the
  23. `--retry` parameter:
  24. ```bash
  25. # Retry up to 5 times, uses an increasing delay between each retry (1s, 2s, 4s, 8s, ...)
  26. curl --retry 5 PING_URL
  27. ```
  28. ## Handle Exceptions
  29. Make sure you know how your HTTP client handles failed requests. For example,
  30. if you use an HTTP library that raises exceptions, decide if you want to
  31. catch the exceptions or let them bubble up.