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.

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