Datadog Checks Base

37.35.0 · active · verified Thu Apr 16

datadog-checks-base provides the foundational Python classes and utilities for developing custom Datadog Agent integrations, also known as Checks. It functions both within the Datadog Agent's embedded Python interpreter and in local development environments for testing and validation. The library is currently at version 37.35.0 and maintains an active release cadence, frequently updated to align with new Datadog Agent and integration functionalities.

Common errors

Warnings

Install

Imports

Quickstart

To create a custom Datadog Agent check, define a Python class that inherits from `AgentCheck` and implements a `check(self, instance)` method. The `check` method is invoked by the Agent to collect and submit data. Metrics are submitted using methods like `self.gauge()`, `self.count()`, `self.service_check()`, etc. Ensure your check file includes a `__version__` variable. For the Agent to discover and run the check, place the Python file in the Agent's `checks.d` directory and a corresponding YAML configuration file in `conf.d`.

import os
from datadog_checks.base.checks import AgentCheck

__version__ = "1.0.0"

class MyCustomCheck(AgentCheck):
    def check(self, instance):
        # The 'instance' dictionary contains configuration for this check instance from its YAML file.
        # E.g., if your my_custom_check.yaml has 'instances: [{ 'foo': 'bar' }]'
        # then 'instance' here would be { 'foo': 'bar' }.
        
        # Submit a simple gauge metric
        self.gauge('my_app.metric.hello_world', 1, tags=['env:dev', 'region:us-east-1'])
        self.log.info("Submitted my_app.metric.hello_world")

        # Example of getting configuration from instance
        custom_value = instance.get('custom_config_key', 'default_value')
        self.log.debug(f"Custom config value: {custom_value}")

        # To run this, place in checks.d/my_custom_check.py and create conf.d/my_custom_check.yaml:
        # init_config:
        # instances:
        #   - custom_config_key: 'my_special_value'

view raw JSON →