Pulumi Any Terraform

Monitor

Create and manage uptime monitors for websites, APIs, and services

The Monitor resource allows you to create and manage uptime monitoring checks in Better Uptime.

Example Usage

Basic HTTP Monitor

import * as betteruptime from "@pulumi-contrib/better-uptime";

const monitor = new betteruptime.Monitor("website-monitor", {
    url: "https://www.example.com",
    monitorType: "status",
    checkFrequency: 180,
});

API Endpoint Monitor

const apiMonitor = new betteruptime.Monitor("api-health-check", {
    url: "https://api.example.com/health",
    monitorType: "status",
    checkFrequency: 60,
    requestTimeout: 30,
    confirmationPeriod: 60,
    call: true,
    sms: true,
    email: true,
    push: true,
});

Monitor with Expected Status

const statusMonitor = new betteruptime.Monitor("service-status", {
    url: "https://service.example.com/status",
    monitorType: "expected_status_code",
    expectedStatusCodes: [200, 201],
    checkFrequency: 120,
    requestTimeout: 20,
});

Monitor with Keyword Check

const keywordMonitor = new betteruptime.Monitor("content-check", {
    url: "https://www.example.com",
    monitorType: "keyword",
    requiredKeyword: "Online",
    checkFrequency: 300,
});

Monitor with Custom Headers

const authMonitor = new betteruptime.Monitor("authenticated-endpoint", {
    url: "https://api.example.com/private",
    monitorType: "status",
    checkFrequency: 60,
    requestHeaders: [
        { name: "Authorization", value: "Bearer token123" },
        { name: "X-API-Key", value: "key456" },
    ],
});

SSL Certificate Monitor

const sslMonitor = new betteruptime.Monitor("ssl-check", {
    url: "https://www.example.com",
    monitorType: "ssl",
    checkFrequency: 86400, // Once per day
    rememberCookies: false,
});

Monitor with Policy

import * as betteruptime from "@pulumi-contrib/better-uptime";

const policy = new betteruptime.Policy("oncall-policy", {
    name: "24/7 On-Call",
});

const monitor = new betteruptime.Monitor("critical-service", {
    url: "https://critical.example.com",
    monitorType: "status",
    checkFrequency: 30,
    policyId: policy.id,
    call: true,
    sms: true,
});

Ping Monitor

const pingMonitor = new betteruptime.Monitor("server-ping", {
    url: "192.168.1.100",
    monitorType: "ping",
    checkFrequency: 60,
});

Port Monitor

const portMonitor = new betteruptime.Monitor("database-port", {
    url: "db.example.com",
    port: 5432,
    monitorType: "tcp",
    checkFrequency: 120,
});

Monitor with Maintenance Windows

const monitor = new betteruptime.Monitor("maintenance-aware", {
    url: "https://api.example.com",
    monitorType: "status",
    checkFrequency: 60,
    maintenanceFrom: "2024-01-15T00:00:00Z",
    maintenanceTo: "2024-01-15T04:00:00Z",
    maintenanceTimezone: "America/New_York",
});

Argument Reference

Required Arguments

  • url (String) - The URL, IP address, or host to monitor
  • monitorType (String) - Type of monitor. Options: status, expected_status_code, keyword, keyword_absence, ping, tcp, udp, smtp, pop, imap, ssl

Optional Arguments

  • checkFrequency (Number) - Check frequency in seconds. Options: 30, 60, 120, 180, 300, 600, 1800, 3600, 86400. Default: 180
  • requestTimeout (Number) - Request timeout in seconds (1-60). Default: 15
  • confirmationPeriod (Number) - Confirmation period in seconds before marking as down. Default: 0
  • monitorGroupId (Number) - Monitor group ID
  • pronounceableName (String) - Pronounceable name for phone calls
  • paused (Boolean) - Whether the monitor is paused. Default: false
  • port (Number) - Port number (for TCP/UDP monitors)
  • regions (List) - Regions to check from (e.g., ["us", "eu", "as"])
  • expectedStatusCodes (List) - Expected HTTP status codes (for expected_status_code type)
  • requiredKeyword (String) - Required keyword in response (for keyword type)
  • call (Boolean) - Enable phone call notifications. Default: false
  • sms (Boolean) - Enable SMS notifications. Default: false
  • email (Boolean) - Enable email notifications. Default: true
  • push (Boolean) - Enable push notifications. Default: true
  • policyId (Number) - Escalation policy ID
  • requestHeaders (List) - Custom HTTP headers
  • requestBody (String) - HTTP request body (for POST requests)
  • followRedirects (Boolean) - Follow HTTP redirects. Default: false
  • rememberCookies (Boolean) - Remember cookies between checks. Default: false
  • verifySSL (Boolean) - Verify SSL certificates. Default: true
  • maintenanceFrom (String) - Maintenance window start time (ISO 8601)
  • maintenanceTo (String) - Maintenance window end time (ISO 8601)
  • maintenanceTimezone (String) - Maintenance window timezone

Attribute Reference

  • id (String) - The monitor ID
  • status (String) - Current monitor status (up, down, paused, maintenance)
  • createdAt (String) - Creation timestamp
  • updatedAt (String) - Last update timestamp

Monitor Types

HTTP Monitors

status - Checks if URL returns 2xx status code

{ monitorType: "status", url: "https://example.com" }

expected_status_code - Checks for specific status codes

{
    monitorType: "expected_status_code",
    expectedStatusCodes: [200, 201, 204]
}

keyword - Checks if response contains keyword

{
    monitorType: "keyword",
    requiredKeyword: "success"
}

keyword_absence - Checks if response doesn't contain keyword

{
    monitorType: "keyword_absence",
    requiredKeyword: "error"
}

Network Monitors

ping - ICMP ping check

{ monitorType: "ping", url: "192.168.1.1" }

tcp - TCP port check

{ monitorType: "tcp", url: "example.com", port: 443 }

udp - UDP port check

{ monitorType: "udp", url: "example.com", port: 53 }

Email Monitors

smtp - SMTP server check

{ monitorType: "smtp", url: "mail.example.com", port: 587 }

pop - POP3 server check

{ monitorType: "pop", url: "mail.example.com", port: 110 }

imap - IMAP server check

{ monitorType: "imap", url: "mail.example.com", port: 993 }

SSL Monitor

ssl - SSL certificate expiration check

{ monitorType: "ssl", url: "https://example.com" }

Best Practices

Check Frequency Guidelines

Service TypeRecommended FrequencyReason
Critical API30-60 secondsImmediate detection
Public Website60-180 secondsBalance cost/detection
Internal Service180-300 secondsReduced load
SSL Certificates86400 seconds (daily)Infrequent changes

Timeout Configuration

// Fast APIs
const fastApi = new betteruptime.Monitor("fast-api", {
    url: "https://fast-api.example.com",
    requestTimeout: 5,
    checkFrequency: 60,
});

// Slow Services
const slowService = new betteruptime.Monitor("slow-service", {
    url: "https://slow.example.com",
    requestTimeout: 30,
    checkFrequency: 180,
});

Confirmation Period

// Avoid false alerts with confirmation period
const reliableMonitor = new betteruptime.Monitor("reliable-check", {
    url: "https://api.example.com",
    checkFrequency: 60,
    confirmationPeriod: 60, // Wait 60s before alerting
});

Regional Monitoring

// Multi-region monitoring for global services
const globalMonitor = new betteruptime.Monitor("global-service", {
    url: "https://global.example.com",
    monitorType: "status",
    regions: ["us", "eu", "as"],
    checkFrequency: 60,
});

Import

Monitors can be imported using their ID:

pulumi import better-uptime:index/monitor:Monitor example 123456

Troubleshooting

Monitor Shows Down but Service is Up

Causes:

  • Firewall blocking Better Uptime IPs
  • Geographic restrictions
  • Rate limiting

Solution:

  • Whitelist Better Uptime IP ranges
  • Adjust geographic restrictions
  • Increase rate limits

False Positives

Causes:

  • Network instability
  • Service intermittent issues
  • Too short timeout

Solution:

const stableMonitor = new betteruptime.Monitor("stable", {
    url: "https://api.example.com",
    requestTimeout: 30,
    confirmationPeriod: 120, // 2 minute confirmation
    checkFrequency: 180,
});

SSL Verification Failures

Cause: Self-signed certificates or certificate issues

Solution:

const devMonitor = new betteruptime.Monitor("dev-env", {
    url: "https://dev.example.com",
    monitorType: "status",
    verifySSL: false, // Only for development
});