Skip to content

Conditions — What "Up" Means

By the end of this chapter you can write the rules that decide health for a real service — and you will have seen the most important lesson in this guide happen live: a service answering 200, promptly and correctly, that still counts as down, because health means what your conditions say and nothing else.

The shape of a condition

A condition is one line of YAML text, a small comparison:

[PLACEHOLDER] <comparison> value

The bracketed word is a placeholder: before judging, Gatus replaces it with a fact from the visit it just made. [STATUS] becomes the reply's status code, [RESPONSE_TIME] the measured milliseconds, [BODY] the reply's body. The comparison is one of ==, !=, <, <=, >, >=. Every condition on an endpoint must pass for the visit to count as a success — they are ANDed, always; there is no OR except inside one condition, with any(...) below.

When a condition fails, Gatus shows its working: the API and dashboard display the condition with the resolved value in place, like [BODY].status (UP) == DOWN. When a check goes red, that line is the first thing to read — it names the fact that offended, not just the rule.

The placeholders

Placeholder The fact it becomes
[STATUS] The HTTP status code (0 when there was no reply)
[BODY] The reply body — text, or JSON you can dig into
[RESPONSE_TIME] How long the visit took, in milliseconds
[CONNECTED] true if a connection could be made at all
[IP] The address the name resolved to
[CERTIFICATE_EXPIRATION] Time until the TLS certificate expires, like 48h
[DNS_RCODE] The DNS reply's status, for DNS endpoints

The lab ran the first four for real. [CERTIFICATE_EXPIRATION] and [DNS_RCODE] belong to endpoint kinds the lab could not exercise (a public TLS site, and DNS over UDP, which the lab's sandbox blocks) — they are taught here from the project's documentation and labelled again in criteria.md.

The lab's three rule sets

A page that must say its line. The front page endpoint requires three things at once:

conditions:
  - "[STATUS] == 200"
  - "[BODY] == pat(*lab web page is up*)"
  - "[RESPONSE_TIME] < 500"

pat(...) turns its argument into a pattern, where * matches anything — so this reads "the body contains the words lab web page is up". All three passed on every visit in the lab (transcript t03-api-statuses.txt). Note what each rule guards: the status guards the reply's kind, the body guards its content, the response time guards its manners — a page that takes nine seconds is up in the first two senses and down in the third, and whether that counts is your decision, written here.

An API that must say it is well. The health endpoint from chapter 4:

conditions:
  - "[STATUS] == 200"
  - "[BODY].status == UP"

[BODY].status digs into a JSON body: it is the value of the status field — the same path style as $.status in other tools. Paths go deeper ([BODY].data[0].id), and two small functions help: len([BODY].data) < 5 counts a list, has([BODY].errors) == false asks whether a field exists at all.

A port that must answer at all. The lab's dead endpoint:

conditions:
  - "[CONNECTED] == true"
  - "[STATUS] == 200"

[CONNECTED] is the humblest placeholder and often the most useful: for tcp:// endpoints (a database port, a game server) it is the only meaningful one — the lab watched tcp://127.0.0.1:8734 with it alone and got success on every visit (transcript t10-tcp-and-icmp.txt).

The lesson: 200 is not a synonym for up

The lab added one more endpoint on purpose — same healthy /health page, one condition changed:

conditions:
  - "[STATUS] == 200"
  - "[BODY].status == DOWN"

The result, from the API:

overall success: False   http status: 200
  [STATUS] == 200              -> True
  [BODY].status (UP) == DOWN   -> False

(Transcript t11-200-but-down.txt.) Nothing was broken. The service was up; the definition said down, and the definition wins. This cuts both ways, and the useful direction is the reverse of the lab's trick: real services fail exactly like this in the wild — a database-backed page that renders "an error occurred" with a cheerful 200, a health endpoint that reports DEGRADED in the body while the status stays green. A status-only check calls those healthy. One body condition — the field your service itself uses to say how it is — calls them what they are. Write that condition first; add the others around it.

Choosing values that mean something

  • Status: == 200 for most things; any(200, 429) when a service legitimately answers "slow down" under load and you do not want paging for it; < 400 when redirects and client errors are equally acceptable to you — know that you are choosing that.
  • Response time: measure before you judge. The lab's local pages answered in 1–9 ms, so < 500 was generous. Against a real service, read a day of [RESPONSE_TIME] values off the API first, then set the line above normal and below pain.
  • Body: prefer your service's own health signal (a status field, a version string) over scraping words meant for humans — the words get edited; the field is a contract.

The check for this chapter is chapter 4's, read harder: fetch the API, and for every endpoint state in one sentence why the latest verdict is what it is, naming the deciding condition. When you can do that without guessing, your conditions say what you mean.