Skip to content

Open-source status page, incident response and uptime monitoring

5.2 KB
Raw Blame
---
category: Guides
title: How to Deploy a Private Probe on Cloudflare Containers
description: A step-by-step guide to deploying an openstatus private monitoring probe on Cloudflare Containers.
sidebar:
  label: Deploy private probes on Cloudflare Containers
---


## Problem

You need to monitor internal services that are not accessible from the public internet, or you want to run checks from your own infrastructure for compliance or performance reasons. You need a lightweight, serverless way to run these monitoring probes without managing virtual machines.

## Solution

Deploy the openstatus private location probe as a serverless container using Cloudflare Containers. This allows you to run monitoring checks from within your own network infrastructure, managed by Cloudflare. This guide will walk you through the entire process, from creating the private location in openstatus to deploying the container.

The code for the Cloudflare Worker template is available on [GitHub](https://github.com/openstatusHQ/private-location-cloudflare-container).

## Prerequisites
- A Cloudflare account
- An [openstatus account](https://www.openstatus.dev)
- `pnpm` and `docker` installed on your local machine

## Step-by-step guide

### 1. Create a private location in openstatus

First, you need to create a private location in your openstatus workspace to get an access key.

1. Go to the openstatus dashboard.
2. Navigate to **Settings** > **Private Locations**.
3. Click **Create Private Location**.
4. Give it a human-readable name (e.g., "Cloudflare-EU").
5. Copy the generated token and save it somewhere secure.
6. Click **Submit** to save the new private location.

### 2. Set up the Cloudflare project

Next, create a new Cloudflare project using the containers template.

```bash
pnpm create cloudflare@latest --template=cloudflare/templates/containers-template
```

### 3. Pull and tag the probe Docker image

Pull the official openstatus private location image from the GitHub Container Registry (`ghcr.io`). You must specify the `linux/amd64` platform, as this is what Cloudflare Containers supports.

```bash
# Pull the image
docker pull --platform linux/amd64 ghcr.io/openstatushq/private-location:latest

# Tag the image for Cloudflare (you cannot use the 'latest' tag)
docker tag ghcr.io/openstatushq/private-location:latest openstatus-private-location:v1
```

### 4. Push the image to Cloudflare Container Registry

Push the tagged image to your Cloudflare account's container registry.

```bash
pnpm wrangler containers push openstatus-private-location:v1
```

### 5. Configure `wrangler.toml`

Now, configure your Cloudflare project to use the container and run it on a schedule.

1. Open the `wrangler.toml` file.
2. Add a `[containers]` section to link the image you pushed. Replace `GENERATED_ID` with the actual ID from the previous step's output.
    ```toml
    [containers]
    image = "registry.cloudflare.com/GENERATED_ID/openstatus-private-location:v1"
    ```
3. Add a `triggers` section to run the worker on a cron schedule. This keeps the container alive, as Cloudflare Containers automatically scales to zero.
    ```toml
    triggers = { cron = ["*/2 * * * *"] } # Runs every 2 minutes
    ```

### 6. Configure the worker

Update the worker script (`index.ts`) to start the container with the correct environment variables.

1. Set the `sleepAfter` value to control how long the container runs after being invoked.
    ```typescript
    sleepAfter = "150s";
    ```
2. Update the `scheduled` function to pass your openstatus key to the container.
    ```typescript
    async scheduled(_controller: any, env: Env) {
      try {
        const container = getContainer(env.MY_CONTAINER);
        await container.start({
          envVars: {
            OPENSTATUS_KEY: env.OPENSTATUS_KEY,
          },
        });
      } catch (e) {
        console.error("Error in scheduled task:", e);
      }
    
      return new Response("ok");
    },
    ```

### 7. Add your openstatus key as a secret

Securely provide your private location token to the Cloudflare worker.

```bash
# Paste the token you saved in Step 1 when prompted
pnpm wrangler secret put OPENSTATUS_KEY
```

### 8. Deploy the application

Finally, deploy the worker and container to Cloudflare.

```bash
pnpm wrangler deploy
```

Your private location probe is now running on Cloudflare Containers and will start picking up monitoring jobs from your openstatus workspace.

## Verify the deployment

You can check the logs of your Cloudflare Worker to see the probe in action. In your openstatus dashboard, the private location's status flips to **active** once the agent reports, and checks from it start appearing in your monitors' response logs.

<Image
    src="/docs/guides/how-to-deploy-probes-cf-containters/cloudflare-log.png"
    alt="Cloudflare Workers Logs showing openstatus Private Location running"
    caption="Cloudflare Workers logs showing the private probe running."
  />

<Image
    src="/docs/guides/how-to-deploy-probes-cf-containters/private-location.jpg"
    alt="openstatus monitor response logs showing checks from a private location"
    caption="Response logs for a monitor, showing checks arriving from the private probe (Cloud Provider: private)."
  />