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.

40 lines
3.5 KiB

  1. <h1>Measuring Script Run Time</h1>
  2. <p>Append <code>/start</code> to a ping URL and use it to signal when a job starts.
  3. After receiving a start signal, Healthchecks.io will show the check as "Started".
  4. It will store the "start" events and display the job execution times. The job
  5. execution times are calculated as the time gaps between adjacent "start" and
  6. "complete" events.</p>
  7. <p>Signalling a start kicks off a separate timer: the job now <strong>must</strong> signal a
  8. success within its configured "Grace Time", or it will get marked as "down".</p>
  9. <p>Below is a code example in Python:</p>
  10. <div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">requests</span>
  11. <span class="n">URL</span> <span class="o">=</span> <span class="s2">&quot;PING_URL&quot;</span>
  12. <span class="c1"># &quot;/start&quot; kicks off a timer: if the job takes longer than</span>
  13. <span class="c1"># the configured grace time, the check will be marked as &quot;down&quot;</span>
  14. <span class="k">try</span><span class="p">:</span>
  15. <span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">URL</span> <span class="o">+</span> <span class="s2">&quot;/start&quot;</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
  16. <span class="k">except</span> <span class="n">requests</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">RequestException</span><span class="p">:</span>
  17. <span class="c1"># If the network request fails for any reason, we don&#39;t want</span>
  18. <span class="c1"># it to prevent the main job from running</span>
  19. <span class="k">pass</span>
  20. <span class="c1"># TODO: run the job here</span>
  21. <span class="n">fib</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="k">if</span> <span class="n">n</span> <span class="o">&lt;</span> <span class="mi">2</span> <span class="k">else</span> <span class="n">fib</span><span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">fib</span><span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span>
  22. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;F(42) = </span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">fib</span><span class="p">(</span><span class="mi">42</span><span class="p">))</span>
  23. <span class="c1"># Signal success:</span>
  24. <span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">URL</span><span class="p">)</span>
  25. </code></pre></div>
  26. <h2>Viewing Measured Run Times</h2>
  27. <p>When SITE_NAME receives a "start" signal followed by a regular ping or a "fail"
  28. signal, and the two events are less than 24 hours apart,
  29. you will see the time delta displayed in the list of checks. If the two events are
  30. more than 24 hours apart, they are assumed to be unrelated, and the time delta is
  31. not displayed.</p>
  32. <p><img alt="List of checks with durations" src="IMG_URL/checks_durations.png" /></p>
  33. <p>You can also see durations of the previous runs when viewing an individual check:</p>
  34. <p><img alt="Log of received pings with durations" src="IMG_URL/details_durations.png" /></p>