Service Checks Submission: DogStatsD

While StatsD accepts only metrics, DogStatsD accepts all three of the major Datadog data types: metrics, events, and service checks. This section shows typical use cases for service checks with code examples.

Function

After installing DogStatsD, you can send service checks to Datadog with the following function:

service_check(<SERVICE_CHECK_NAME>, <STATUS>, <TAGS>, <HOSTNAME>, <MESSAGE>)

Service check function parameters:

ParameterTypeRequiredDefault ValueDescription
<SERVICE_CHECK_NAME>StringYes-The name of the service check.
<STATUS>IntYes-A constant describing the service status: 0 for OK, 1 for WARN, 2 for CRITICAL, and 3 for UNKNOWN.
<TAGS>List of key:value pairsNo-A list of tags to associate with the service check.
<HOSTNAME>StringNoCurrent hostThe hostname to associate with the service check.
<MESSAGE>StringNo-Additional information or a description of why the status occurred.

Code examples

Run the following code to submit a service check through DogStatsD to Datadog. Remember to flush/close the client when it is no longer needed.

from datadog import initialize, statsd

options = {"statsd_host": "127.0.0.1", "statsd_port": 8125}

initialize(**options)

statsd.service_check(
    check_name="application.service_check",
    status="0",
    message="Application is OK",
)

After a service check is reported, use it to trigger a service check monitor.

Further reading

PREVIEWING: gorkavicente/appsec-serverless-library-compatibility