Monitors

API monitors

An API monitor sends the request your API expects and checks the answer: the status code, values in the JSON, headers and how long it took. When a check fails, the alert says which one.

On this page

Create an API monitor

  1. On Monitors, press New monitor. Under What to check, choose API.
  2. Fill in the Name and the Address of the API, such as https://api.example.com/v1/health.
  3. Choose the Check interval and the Timeout.
  4. Choose the Request method: GET, POST, PUT, PATCH, DELETE, HEAD or OPTIONS. At first it is GET.
  5. Keep or change the Expected status code. At first it is 2xx: any answer from 200 to 299.
  6. Add Request headers, a Request body and Response checks if you need them. The sections below explain each one.
  7. Press Create monitor.

The address follows the same rules as for a website monitor: it starts with http:// or https://, its port is 80, 443, or 1024 and higher, it is not in a private network, and it has no user name or password in it. See Website and keyword monitors.

Expected status code takes one class, such as 2xx or 4xx, or one exact code, such as 201. It does not take a list or a range.

Send headers, such as an API key

  1. Under Request headers, press Add header.
  2. Type the Header name, such as Authorization or X-Api-Key.
  3. Type its Value, such as Bearer <token>.
  • You can send up to 10 headers. A value is one line of up to 2,000 characters. The same name twice is refused.
  • Your headers replace the ones the check sends itself: User-Agent, Accept and Content-Type.
  • These headers cannot be set, because they change how the request is sent: Host, Content-Length, Transfer-Encoding, Connection, Upgrade, TE, Trailer, Expect, Keep-Alive, and every header that starts with Proxy- or Sec-.
  • For basic authentication, send an Authorization header with Basic and the encoded user and password. A user name and password in the address are refused.

Header values are stored encrypted and never shown again: the dashboard and the API show only the names. When you edit the monitor, a saved header shows Saved. Type to replace. Leave it empty to keep the value, or type a new one. On the monitor's page, the Request and checks card lists the names and says Header values are hidden.

Send a body

A body goes only with POST, PUT, PATCH and DELETE. With another method, the field is hidden, and changing to such a method removes the body.

  1. Choose one of these methods under Request method.
  2. Type the Request body, up to 16 KB.
  3. Choose the Body type. At first it is JSON.
Body typeContent-Type sent
JSONapplication/json. The body must be valid JSON.
Form (URL-encoded)application/x-www-form-urlencoded, such as a=1&b=2
XMLapplication/xml
Texttext/plain; charset=utf-8

A Content-Type header in your list replaces the one of the body type. Only a JSON body is checked when you save; the other types are sent as you typed them.

Check the answer

Without checks, the right status code is enough. You can add up to 10 checks. They run in order after the status code, and the first one that fails makes the check fail.

  1. Under Response checks, press Add check.
  2. Under Look at, choose JSON value or Response header.
  3. Type the Path of the value, or the header's name.
  4. Choose the Comparison and type the Value. exists and does not exist need no value.

For example, your API answers this:

JSON
{
  "status": "ok",
  "database": { "connected": true, "latency_ms": 12 },
  "queues": [ { "name": "email", "waiting": 3 } ]
}
Look atPath or nameComparisonValue
JSON valuestatusequalsok
JSON valuedatabase.connectedequalstrue
JSON valuedatabase.latency_msis less than100
JSON valuequeues[0].waitingis less than50
Response headerContent-Typecontainsapplication/json

How to write a path

  • Keys are separated by dots: data.status is the key status inside data.
  • A place in a list is a number in brackets, starting at 0: items[0].id is the id of the first item.
  • A path may start with $., as in $.data.status. $ alone is the whole answer, and [0].name reads the first item of an answer that is a list.
  • A path has at most 200 characters.

How values are compared

  • Text is compared exactly, and upper and lower case matter, also for contains.
  • A JSON number equals a number however it is written: 1.0 equals 1. A number in quotes in the JSON, such as "1.0", is text.
  • is less than and is greater than need a number as the value. They also work on numbers in quotes and on headers such as Content-Length.
  • true, false and null are compared as those words. An object or a list is compared as compact JSON, such as [1,2].
  • A value that is not there passes only does not exist. A value that is null is there.
  • A header's name may be written in any case. A header that comes several times is read as all its values, joined with a comma and a space.
  • The whole answer must be one JSON value, whatever its Content-Type says. Otherwise the check fails with The response is not valid JSON.
  • Only the first 1 MB of the answer is read. A larger JSON answer is cut, and a JSON check on it fails.
  • A HEAD request gets no body, so it cannot have JSON checks. Header checks work.

Limit the response time

In Slowest allowed response (ms), type the longest time you accept, in milliseconds. A slower answer fails with The response came too slowly. Leave the field empty for no limit.

  • The limit must be shorter than the Timeout, up to 30,000 ms. Otherwise a slow answer would end as No answer in time.
  • The time runs from sending the request until the answer has been read, redirects included.
  • The time is judged last. A wrong status code or a failed check is what the alert names, even when the answer was also slow.

When an API monitor counts as down

A check fails for one of these reasons, and the dashboard shows which one:

Reason in the dashboardWhat happened
No answer in timeThe whole answer did not arrive within the timeout.
Address not found (DNS)The name could not be looked up.
Connection refused or droppedThe server refused or dropped the connection.
Certificate or secure connection problemA problem with the certificate or the secure connection. There is no option to ignore it.
Unexpected status codeThe status code is not the expected one.
Too many redirectsMore than 5 redirects.
Address leads to a private networkThe name leads to an address in a private network.
Request failedAnother problem with the request.
The response is not valid JSONA JSON check needs the answer, and the answer is not JSON.
A response check failedOne of your checks did not pass. The alert gives its number.
The response came too slowlyThe answer was slower than your limit.

A redirect is followed only on the same host, and never from https to http, so your headers never travel to another server. A redirect to another host is not followed: the redirect itself is judged, so with 2xx it fails with Unexpected status code.

After a failed check, the monitor is checked again 30 seconds later, or sooner when the interval is shorter. Only a second failure in a row makes it Down and sends the alert. When other places are online, they check at the same moment, and the status changes only when most of them agree. On the monitor's page, the Request and checks card marks the check that failed with Failed in the last check.

More guides

All guides