Skip to content
Start here

Create Monitor

client.LoadBalancers.Monitors.New(ctx, params) (*Monitor, error)
POST/accounts/{account_id}/load_balancers/monitors

Create a configured monitor.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Load Balancing: Monitors and Pools Write
ParametersExpand Collapse
params MonitorNewParams
AccountID param.Field[string]

Path param: Identifier.

maxLength32
AllowInsecure param.Field[bool]optional

Body param: Do not validate the certificate when monitor use HTTPS. This parameter is currently only valid for HTTP and HTTPS monitors.

ConsecutiveDown param.Field[int64]optional

Body param: To be marked unhealthy the monitored origin must fail this healthcheck N consecutive times.

ConsecutiveUp param.Field[int64]optional

Body param: To be marked healthy the monitored origin must pass this healthcheck N consecutive times.

Description param.Field[string]optional

Body param: Object description.

ExpectedBody param.Field[string]optional

Body param: A case-insensitive sub-string to look for in the response body. If this string is not found, the origin will be marked as unhealthy. This parameter is only valid for HTTP and HTTPS monitors.

ExpectedCodes param.Field[string]optional

Body param: The expected HTTP response code or code range of the health check. This parameter is only valid for HTTP and HTTPS monitors.

FollowRedirects param.Field[bool]optional

Body param: Follow redirects if returned by the origin. This parameter is only valid for HTTP and HTTPS monitors.

Header param.Field[map[string, []string]]optional

Body param: The HTTP request headers to send in the health check. It is recommended you set a Host header by default. The User-Agent header cannot be overridden. This parameter is only valid for HTTP and HTTPS monitors.

Interval param.Field[int64]optional

Body param: The interval between each health check. Shorter intervals may improve failover time, but will increase load on the origins as we check from multiple locations.

Method param.Field[string]optional

Body param: The method to use for the health check. This defaults to 'GET' for HTTP/HTTPS based checks and 'connection_established' for TCP based health checks.

Path param.Field[string]optional

Body param: The endpoint path you want to conduct a health check against. This parameter is only valid for HTTP and HTTPS monitors.

Port param.Field[int64]optional

Body param: The port number to connect to for the health check. Required for TCP, UDP, and SMTP checks. HTTP and HTTPS checks should only define the port when using a non-standard port (HTTP: default 80, HTTPS: default 443).

ProbeZone param.Field[string]optional

Body param: Assign this monitor to emulate the specified zone while probing. This parameter is only valid for HTTP and HTTPS monitors.

Retries param.Field[int64]optional

Body param: The number of retries to attempt in case of a timeout before marking the origin as unhealthy. Retries are attempted immediately.

Timeout param.Field[int64]optional

Body param: The timeout (in seconds) before marking the health check as failed.

Type param.Field[MonitorNewParamsType]optional

Body param: The protocol to use for the health check. Currently supported protocols are 'HTTP','HTTPS', 'TCP', 'ICMP-PING', 'UDP-ICMP', and 'SMTP'.

const MonitorNewParamsTypeHTTP MonitorNewParamsType = "http"
const MonitorNewParamsTypeHTTPS MonitorNewParamsType = "https"
const MonitorNewParamsTypeTCP MonitorNewParamsType = "tcp"
const MonitorNewParamsTypeUdpIcmp MonitorNewParamsType = "udp_icmp"
const MonitorNewParamsTypeIcmpPing MonitorNewParamsType = "icmp_ping"
const MonitorNewParamsTypeSmtp MonitorNewParamsType = "smtp"
ReturnsExpand Collapse
type Monitor struct{…}
ID stringoptional
AllowInsecure booloptional

Do not validate the certificate when monitor use HTTPS. This parameter is currently only valid for HTTP and HTTPS monitors.

ConsecutiveDown int64optional

To be marked unhealthy the monitored origin must fail this healthcheck N consecutive times.

ConsecutiveUp int64optional

To be marked healthy the monitored origin must pass this healthcheck N consecutive times.

CreatedOn stringoptional
Description stringoptional

Object description.

ExpectedBody stringoptional

A case-insensitive sub-string to look for in the response body. If this string is not found, the origin will be marked as unhealthy. This parameter is only valid for HTTP and HTTPS monitors.

ExpectedCodes stringoptional

The expected HTTP response code or code range of the health check. This parameter is only valid for HTTP and HTTPS monitors.

FollowRedirects booloptional

Follow redirects if returned by the origin. This parameter is only valid for HTTP and HTTPS monitors.

Header map[string, []string]optional

The HTTP request headers to send in the health check. It is recommended you set a Host header by default. The User-Agent header cannot be overridden. This parameter is only valid for HTTP and HTTPS monitors.

Interval int64optional

The interval between each health check. Shorter intervals may improve failover time, but will increase load on the origins as we check from multiple locations.

Method stringoptional

The method to use for the health check. This defaults to 'GET' for HTTP/HTTPS based checks and 'connection_established' for TCP based health checks.

ModifiedOn stringoptional
Path stringoptional

The endpoint path you want to conduct a health check against. This parameter is only valid for HTTP and HTTPS monitors.

Port int64optional

The port number to connect to for the health check. Required for TCP, UDP, and SMTP checks. HTTP and HTTPS checks should only define the port when using a non-standard port (HTTP: default 80, HTTPS: default 443).

ProbeZone stringoptional

Assign this monitor to emulate the specified zone while probing. This parameter is only valid for HTTP and HTTPS monitors.

Retries int64optional

The number of retries to attempt in case of a timeout before marking the origin as unhealthy. Retries are attempted immediately.

Timeout int64optional

The timeout (in seconds) before marking the health check as failed.

Type MonitorTypeoptional

The protocol to use for the health check. Currently supported protocols are 'HTTP','HTTPS', 'TCP', 'ICMP-PING', 'UDP-ICMP', and 'SMTP'.

One of the following:
const MonitorTypeHTTP MonitorType = "http"
const MonitorTypeHTTPS MonitorType = "https"
const MonitorTypeTCP MonitorType = "tcp"
const MonitorTypeUdpIcmp MonitorType = "udp_icmp"
const MonitorTypeIcmpPing MonitorType = "icmp_ping"
const MonitorTypeSmtp MonitorType = "smtp"

Create Monitor

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/load_balancers"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  monitor, err := client.LoadBalancers.Monitors.New(context.TODO(), load_balancers.MonitorNewParams{
    AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", monitor.ID)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "f1aba936b94213e5b8dca0c0dbf1f9cc",
    "allow_insecure": true,
    "consecutive_down": 0,
    "consecutive_up": 0,
    "created_on": "2014-01-01T05:20:00.12345Z",
    "description": "Login page monitor",
    "expected_body": "alive",
    "expected_codes": "2xx",
    "follow_redirects": true,
    "header": {
      "Host": [
        "example.com"
      ],
      "X-App-ID": [
        "abc123"
      ]
    },
    "interval": 0,
    "method": "GET",
    "modified_on": "2014-01-01T05:20:00.12345Z",
    "path": "/health",
    "port": 0,
    "probe_zone": "example.com",
    "retries": 0,
    "timeout": 0,
    "type": "https"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "f1aba936b94213e5b8dca0c0dbf1f9cc",
    "allow_insecure": true,
    "consecutive_down": 0,
    "consecutive_up": 0,
    "created_on": "2014-01-01T05:20:00.12345Z",
    "description": "Login page monitor",
    "expected_body": "alive",
    "expected_codes": "2xx",
    "follow_redirects": true,
    "header": {
      "Host": [
        "example.com"
      ],
      "X-App-ID": [
        "abc123"
      ]
    },
    "interval": 0,
    "method": "GET",
    "modified_on": "2014-01-01T05:20:00.12345Z",
    "path": "/health",
    "port": 0,
    "probe_zone": "example.com",
    "retries": 0,
    "timeout": 0,
    "type": "https"
  },
  "success": true
}