Skip to content

DevOps Operations / Service monitoring · Step 3 of 7

Lesson: Availability and ErrorsSwitch
← DevOps Operations

Delivery and containers

Availability and Errors

Measure whether a service answers successfully and how often it fails.

A service is available when it can do what users ask of it. A running process is not enough. You need to measure successful answers.

Success ratio

A common measure is:

text
availability = successful requests / valid requests

If 9,990 of 10,000 requests succeed, availability is 99.9 percent. The error rate is the rest, 0.1 percent. Decide in advance what counts as success.

For HTTP, status codes help. 2xx means success and 3xx redirection. 4xx means the request had a problem, such as 404 Not Found. 5xx means the server failed, such as 500 or 503 Service Unavailable. Many teams count 5xx as service errors and watch 4xx separately, because a sudden rise in 401 or 404 can still point to a broken release.

Check from outside

A health check sends a request and judges the answer:

bash
$ curl -sS -f -o /dev/null --max-time 5 https://example.com/ && echo OK || echo FAIL
OK

-f makes curl exit with an error for HTTP status 400 and above in most cases (some authentication responses can slip through), and --max-time stops a hung request from waiting forever. A check run on the server itself cannot see problems with DNS or the network path, so test from another machine too.

Count errors from a log

In the common "combined" access log format, the status code is the ninth space-separated field:

bash
$ sudo awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c
    942 200
     31 404
      7 500

If your log format is customised, the field number will differ.

Nines and downtime

Targets are often written as "nines". Over 30 days, 99 percent allows about 7.2 hours of failure, and 99.9 percent allows about 43 minutes. The amount you may fail is sometimes called an error budget. Pick a target you can actually measure and that users care about.

Averages over a month can hide a bad ten minutes, so also look at short windows. When traffic is very low, a single failure swings the percentage widely.

Try it

Run the health check against a test web server, then stop the server and run it again. Then count status codes in its access log. More practice is in the networking and SSH lab.

Check your understanding

Availability and Errors

All 3 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.