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.

264 lines
8.3 KiB

10 years ago
10 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. {% extends "front/base_docs.html" %}
  2. {% load compress staticfiles hc_extras %}
  3. {% block title %}Documentation - {% site_name %}{% endblock %}
  4. {% block docs_content %}
  5. <h2>Summary</h2>
  6. <p>
  7. Each check in <a href="{% url 'hc-index' %}">My Checks</a>
  8. page has an unique "ping" URL. Whenever you access this URL,
  9. the "Last Ping" value of corresponding check is updated.
  10. </p>
  11. <p>When a certain amount of time passes since last received ping, the
  12. check is considered "late", and {% site_name %} sends an email alert.
  13. It is a simple idea.</p>
  14. <h2>Executing a Ping</h2>
  15. <p>
  16. At the end of your batch job, add a bit of code to request
  17. your ping URL.
  18. </p>
  19. <ul>
  20. <li>HTTP and HTTPS protocols both are fine</li>
  21. <li>Request method can be GET, POST or HEAD</li>
  22. <li>Both IPv4 and IPv6 work</li>
  23. <li>It does not matter what request headers you send, or what you put in request body.</li>
  24. </ul>
  25. <p>The response will have status code "200 OK" and response body will be a
  26. short and simple string "OK".</p>
  27. <p>
  28. Here are examples of executing pings from different environments.
  29. </p>
  30. <a name="crontab"></a>
  31. <h3>Crontab</h3>
  32. <p>
  33. When using cron, probably the easiest is to append a curl
  34. or wget call after your command. The scheduled time comes,
  35. and your command runs. If it completes successfully (exit code 0),
  36. curl or wget runs a HTTP GET call to the ping URL.
  37. </p>
  38. {% include "front/snippets/crontab.html" %}
  39. <p>With this simple modification, you monitor several failure
  40. scenarios:</p>
  41. <ul>
  42. <li>The whole machine has stopped working (power outage, janitor stumbles on wires, VPS provider problems, etc.) </li>
  43. <li>cron daemon is not running, or has invalid configuration</li>
  44. <li>cron does start your task, but the task exits with non-zero exit code</li>
  45. </ul>
  46. <p>Either way, when your task doesn't finish successfully, you will soon
  47. know about it.</p>
  48. <p>The extra options to curl are meant to suppress any output, unless it hits
  49. an error. This is to prevent cron from sending an email every time the
  50. task runs. Feel free to adjust the curl options to your liking.
  51. </p>
  52. <table class="table curl-opts">
  53. <tr>
  54. <th>&amp;&amp;</th>
  55. <td>Run curl only if <code>/home/user/backup.sh</code> succeeds</td>
  56. </tr>
  57. <tr>
  58. <th>
  59. -f, --fail
  60. </th>
  61. <td>Makes curl treat non-200 responses as errors</td>
  62. </tr>
  63. <tr>
  64. <th>-s, --silent</th>
  65. <td>Silent or quiet mode. Don't show progress meter or error messages.</td>
  66. </tr>
  67. <tr>
  68. <th>-S, --show-error</th>
  69. <td>When used with -s it makes curl show error message if it fails.</td>
  70. </tr>
  71. <tr>
  72. <th>--retry &lt;num&gt;</th>
  73. <td>
  74. If a transient error is returned when curl tries to perform a
  75. transfer, it will retry this number of times before giving up.
  76. Setting the number to 0 makes curl do no retries
  77. (which is the default). Transient error means either: a timeout,
  78. an FTP 4xx response code or an HTTP 5xx response code.
  79. </td>
  80. </tr>
  81. <tr>
  82. <th>&gt; /dev/null</th>
  83. <td>
  84. Redirect curl's stdout to /dev/null (error messages go to stderr,)
  85. </td>
  86. </tr>
  87. </table>
  88. <a name="bash"></a>
  89. <h3>Bash or a shell script</h3>
  90. <p>Both <code>curl</code> and <code>wget</code> examples accomplish the same
  91. thing: they fire off a HTTP GET method.</p>
  92. <p>
  93. If using <code>curl</code>, make sure it is installed on your target system.
  94. Ubuntu, for example, does not have curl installed out of the box.
  95. </p>
  96. {% include "front/snippets/bash_curl.html" %}
  97. {% include "front/snippets/bash_wget.html" %}
  98. <a name="python"></a>
  99. <h3>Python</h3>
  100. {% include "front/snippets/python_urllib2.html" %}
  101. {% include "front/snippets/python_requests.html" %}
  102. <a name="node"></a>
  103. <h3>Node</h3>
  104. {% include "front/snippets/node.html" %}
  105. <a name="php"></a>
  106. <h3>PHP</h3>
  107. {% include "front/snippets/php.html" %}
  108. <a name="browser"></a>
  109. <h3>Browser</h3>
  110. <p>
  111. {% site_name %} includes <code>Access-Control-Allow-Origin:*</code>
  112. CORS header in its ping responses, so cross-domain AJAX requests
  113. should work.
  114. </p>
  115. {% include "front/snippets/browser.html" %}
  116. <a name="powershell"></a>
  117. <h3>PowerShell</h3>
  118. <p>
  119. You can use <a href="https://msdn.microsoft.com/en-us/powershell/mt173057.aspx">PowerShell</a>
  120. and Windows Task Scheduler to automate various tasks on a Windows system.
  121. From within a PowerShell script it is also easy to ping {% site_name %}.
  122. </p>
  123. <p>Here is a simple PowerShell script that pings {% site_name %}.
  124. When scheduled to run with Task Scheduler, it will essentially
  125. just send regular "I'm alive" messages. You can of course extend it to
  126. do more things.</p>
  127. {% include "front/snippets/powershell.html" %}
  128. <p>Save the above to e.g. <code>C:\Scripts\healthchecks.ps1</code>. Then use
  129. the following command in a Scheduled Task to run the script:
  130. </p>
  131. <div class="highlight">
  132. <pre>powershell.exe -ExecutionPolicy bypass -File C:\Scripts\healthchecks.ps1</pre>
  133. </div>
  134. <p>In simple cases, you can also pass the script to PowerShell directly,
  135. using the "-command" argument:</p>
  136. {% include "front/snippets/powershell_inline.html" %}
  137. <a name="email"></a>
  138. <h3>Email</h3>
  139. <p>
  140. As an alternative to HTTP/HTTPS requests,
  141. you can "ping" this check by sending an
  142. email message to <strong>{{ ping_email }}</strong>
  143. </p>
  144. <p>
  145. This is useful for end-to-end testing weekly email delivery.
  146. </p>
  147. <p>
  148. An example scenario: you have a cron job which runs weekly and
  149. sends weekly email reports to a list of e-mail addresses. You have already
  150. set up a check to get alerted when your cron job fails to run.
  151. But what you ultimately want to check is your emails <em>get sent and
  152. get delivered</em>.
  153. </p>
  154. <p>
  155. The solution: set up another check, and add its
  156. @hchk.io address to your list of recipient email addresses. Set its
  157. Period to 1 week. As long as your weekly email script runs correctly,
  158. the check will be regularly pinged and will stay up.
  159. </p>
  160. <h2>When Alerts Are Sent</h2>
  161. <p>
  162. Each check has a configurable <strong>Period</strong> parameter, with the default value of one day.
  163. For periodic tasks, this is the expected time gap between two runs.
  164. </p>
  165. <p>
  166. Additionally, each check has a <strong>Grace</strong> parameter, with default value of one hour.
  167. You can use this parameter to account for run time variance of tasks.
  168. For example, if a backup task completes in 50 seconds one day, and
  169. completes in 60 seconds the following day, you might not want to get
  170. alerted because the backups are 10 seconds late.
  171. </p>
  172. <p>Each check can be in one of the following states:</p>
  173. <table class="table">
  174. <tr>
  175. <td>
  176. <span class="status icon-up new"></span>
  177. </td>
  178. <td>
  179. <strong>New.</strong>
  180. A check that has been created, but has not received any pings yet.
  181. </td>
  182. </tr>
  183. <tr>
  184. <td>
  185. <span class="status icon-paused"></span>
  186. </td>
  187. <td>
  188. <strong>Monitoring Paused.</strong>
  189. You can resume monitoring of a paused check by pinging it.
  190. </td>
  191. </tr>
  192. <tr>
  193. <td>
  194. <span class="status icon-up"></span>
  195. </td>
  196. <td>
  197. <strong>Up.</strong>
  198. Time since last ping has not exceeded <strong>Period</strong>.
  199. </td>
  200. </tr>
  201. <tr>
  202. <td>
  203. <span class="status icon-grace"></span>
  204. </td>
  205. <td>
  206. <strong>Late.</strong>
  207. Time since last ping has exceeded <strong>Period</strong>,
  208. but has not yet exceeded <strong>Period</strong> + <strong>Grace</strong>.
  209. </td>
  210. </tr>
  211. <tr>
  212. <td>
  213. <span class="status icon-down"></span>
  214. </td>
  215. <td>
  216. <strong>Down.</strong>
  217. Time since last ping has exceeded <strong>Period</strong> + <strong>Grace</strong>.
  218. When check goes from "Late" to "Down", {% site_name %}
  219. sends you an alert.
  220. </td>
  221. </tr>
  222. </table>
  223. {% endblock %}
  224. {% block scripts %}
  225. {% compress js %}
  226. <script src="{% static 'js/jquery-2.1.4.min.js' %}"></script>
  227. <script src="{% static 'js/bootstrap.min.js' %}"></script>
  228. <script src="{% static 'js/clipboard.min.js' %}"></script>
  229. <script src="{% static 'js/snippet-copy.js' %}"></script>
  230. {% endcompress %}
  231. {% endblock %}