Cloudflare Docs
Learning Paths
Edit this page
Give us feedback
Set theme to dark (⇧+D)

Create monitor

  4 min read

Instead of starting on your production domain, you likely should create a load balancer on a test or staging domain. This may involve temporary changes to your monitors and pools, depending on your infrastructure setup.

Starting with a test domain allows you to verify everything is working correctly before routing production traffic.

Set up the monitor

You can create a monitor within the load balancer workflow or in the Monitors section of the dashboard:

  1. Go to Traffic > Load Balancing.

  2. Select Manage Monitors.

  3. Select Create.

  4. Add the following information:

    • Type: The protocol to use for health monitors
      • Non-enterprise customers: Choose HTTP, HTTPS, or TCP.
      • Enterprise customers: Choose HTTP, HTTPS, TCP, UDP ICMP, ICMP Ping, or SMTP.
    • Path: The endpoint path to run health monitor requests against
    • Port: The destination port for health monitors
  5. For additional settings, select Advanced health monitor settings:

    • Interval:
      • By increasing the default, you can improve failover time, but you may also increase load on your endpoints.
      • Minimum time in seconds is 60 (Pro), 15 (Business), and 10 (Enterprise).
    • Timeout and Retries:
      • The health monitor request will return unhealthy if it exceeds the duration specified in Timeout (and exceeds this duration more times than the specified number of Retries).
    • Expected Code(s): The expected HTTP response codes listed individually (200, 302) or as a range (for example, entering 2xx would cover all response codes in the 200 range).
    • Response Body:
      • Looks for a case-insensitive substring in the response body.
      • Make sure that the value is relatively static and within the first 100 MB of the HTML page.
    • Simulate Zone:
      • Pushes a request from Cloudflare health monitors through the Cloudflare stack as if it were a real visitor request to help analyze behavior or validate a configuration using the zone specified.
      • It is recommended to use the same zone in which the Load Balancer exists.
      • Ensures health monitor requests are compatible with features like authenticated origin pulls and Argo Smart Routing.
    • Follow Redirects:
      • Instead of reporting a 301 or 302 code as unhealthy, the health monitor request follows redirects to the final endpoint.
    • Configure Request Header(s):
      • Useful if your endpoints are expecting specific incoming headers.
    • Header:
      • The HTTP request headers to send in the health monitor. It is recommended that you set a Host header by default. The User-Agent header cannot be overridden. This parameter is only valid for HTTP and HTTPS monitors.
  6. Select Save.

Prepare your servers

Make sure that your firewall or web server does not block or rate limit your configured health monitors or requests associated with Cloudflare IP addresses.

Each health monitor has the HTTP user-agent of "Mozilla/5.0 (compatible; Cloudflare-Traffic-Manager/1.0; +https://www.cloudflare.com/traffic-manager/; pool-id: $poolid)", where the $poolid is the first 16 characters of the associated pool.

Set up the monitor

For a full list of monitor properties, refer to Create Monitor. If you need help with API authentication, refer to Cloudflare API documentation.

Request
curl -X POST \
-H "X-Auth-Email: user@cloudflare.com" \
-H "X-Auth-Key: REDACTED" \
"https://api.cloudflare.com/client/v4/accounts/:account_id/load_balancers/monitors" \
-H "Content-Type: application/json" \
-d '{
"type":"https",
"description":"Login page monitor",
"method":"GET",
"path":"/health",
"header": {
"Host":["example.com"],
"X-App-ID":["abc123"]
},
"port":8080,
"timeout":3,
"retries":0,
"interval":90,
"expected_body":"alive",
"expected_codes":"2xx",
"follow_redirects":true,
"allow_insecure":true,
"consecutive_up":3,
"consecutive_down":2,
"probe_zone":"example.com"
}'

The response contains the complete definition of the new monitor.

Response
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": ":monitor-id",
"created_on": "2021-01-01T05:20:00.12345Z",
"modified_on": "2021-01-01T05:20:00.12345Z",
"type": "https",
"description": "Login page monitor",
"method": "GET",
"path": "/health",
"header": {
"Host": [
"example.com"
],
"X-App-ID": [
"abc123"
]
},
"port": 8080,
"timeout": 3,
"retries": 0,
"interval": 90,
"expected_body": "alive",
"expected_codes": "2xx",
"follow_redirects": true,
"allow_insecure": true,
"consecutive_up": 3,
"consecutive_down": 2,
"probe_zone": "example.com"
}
}

Prepare your servers

Make sure that your firewall or web server does not block or rate limit your configured health monitors or requests associated with Cloudflare IP addresses.

Each health monitor has the HTTP user-agent of "Mozilla/5.0 (compatible; Cloudflare-Traffic-Manager/1.0; +https://www.cloudflare.com/traffic-manager/; pool-id: $poolid)", where the $poolid is the first 16 characters of the associated pool.

Example monitor configuration
FieldValue
TypeHTTP
Path/
Port80
Interval60
MethodGET
Timeout5 seconds
Retries2
Expected Code(s)200