Getting Started - fleXRPL/datadog-monitor-deployer GitHub Wiki

Getting Started with DataDog Monitor Deployer

This guide will help you get started with the DataDog Monitor Deployer tool, covering basic concepts and initial setup.

Basic Concepts

What is Monitor as Code?

Monitor as Code is an approach where monitoring configurations are defined in version-controlled files rather than through a UI. Benefits include:

  • Version control
  • Reproducibility
  • Automation
  • Consistency
  • Code review process
  • Disaster recovery

Monitor Types

DataDog Monitor Deployer supports all monitor types:

  • Metric monitors
  • Log monitors
  • APM monitors
  • Process monitors
  • Network monitors
  • Event monitors
  • Custom monitors

Initial Setup

1. Install the Package

pip install datadog-monitor-deployer

2. Configure Credentials

Set up your DataDog credentials:

export DD_API_KEY='your-api-key'
export DD_APP_KEY='your-app-key'

3. Create Project Structure

mkdir my-monitors
cd my-monitors

Recommended project structure:

my-monitors/
├── monitors/
│   ├── infrastructure/
│   │   ├── cpu.yaml
│   │   └── memory.yaml
│   ├── application/
│   │   ├── errors.yaml
│   │   └── latency.yaml
│   └── business/
│       └── transactions.yaml
├── templates/
│   └── common.yaml
└── README.md

Basic Usage

Command Line Interface

The dd-monitor command provides several operations:

# List all monitors
dd-monitor list

# Deploy monitors
dd-monitor deploy monitors/infrastructure/cpu.yaml

# Validate configuration
dd-monitor validate monitors/infrastructure/cpu.yaml

# Delete a monitor
dd-monitor delete <monitor-id>

Configuration Format

Basic monitor configuration:

monitors:
  - name: "Service CPU Usage"
    type: "metric alert"
    query: "avg(last_5m):avg:system.cpu.user{service:myapp} > 80"
    message: |
      Service is experiencing high CPU usage.

      {{#is_alert}}
      Current value: {{value}}
      {{/is_alert}}
    tags:
      - "team:platform"
      - "env:production"

Working with Templates

Using Template Variables

monitors:
  - name: "{{ service }} CPU Usage"
    type: "metric alert"
    query: "avg(last_5m):avg:system.cpu.user{service:{{ service }}} > {{ threshold }}"
    variables:
      service: "myapp"
      threshold: 80

Template Inheritance

# templates/base.yaml
template:
  defaults:
    tags:
      - "team:platform"
      - "env:production"
    options:
      notify_no_data: true
      evaluation_delay: 900

# monitors/cpu.yaml
monitors:
  - template: base
    name: "CPU Alert"
    type: "metric alert"
    query: "avg(last_5m):avg:system.cpu.user{*} > 80"

Best Practices

  1. Organization

    • Use consistent naming conventions
    • Group related monitors
    • Use templates for common patterns
  2. Version Control

    • Commit monitor configurations to Git
    • Use branches for changes
    • Review changes through PRs
  3. Automation

    • Integrate with CI/CD pipelines
    • Automate validation
    • Use automated testing
  4. Documentation

    • Document monitor purpose
    • Include runbooks
    • Maintain change history

Common Workflows

Creating a New Monitor

  1. Create configuration file
  2. Validate configuration
  3. Test in development
  4. Deploy to production
  5. Verify in DataDog UI

Updating Existing Monitors

  1. Modify configuration
  2. Validate changes
  3. Review differences
  4. Deploy updates
  5. Verify changes

Next Steps

Additional Resources

⚠️ **GitHub.com Fallback** ⚠️