Nouvelles annonces sur les technologies sans serveur et réseau ainsi que sur le RUM (Real-User Monitoring) dévoilées à la conférence Dash ! Nouvelles annonces dévoilées à la conférence Dash !

Events with DogStatsD

Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Submission

After installing DogStatsD, you can emit events to your Datadog event stream with the following function:

event(<TITLE>, <TEXT>, <TIMESTAMP>, <HOSTNAME>, <AGGREGATION_KEY>, <PRIORITY>, <SOURCE_TYPE_NAME>, <ALERT_TYPE>, <TAGS>)

Definitions:

ParameterTypeRequiredDescription
<TITLE>StringYesThe title of the event
<TEXT>StringYesThe text body of the event
<TIMESTAMP>IntegerYesThe epoch timestamp for the event (defaults to the current time from the DogStatsD server)
<HOSTNAME>StringNoThe name of the host
<AGGREGATION_KEY>StringNoA key to use for aggregating events
<PRIORITY>StringNoSpecifies the priority of the event (normal or low).
<SOURCE_TYPE_NAME>StringNoThe source type name
<ALERT_TYPE>StringNoerror, warning, success, or info (defaults to info)
<TAGS>List of stringsNoA list of tags associated with this event.

Examples

View errors and exceptions in Datadog with a DogStatsD event:

event.py

from datadog import initialize, statsd

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

initialize(**options)

statsd.event('An error occurred', 'Error message', alert_type='error', tags=['env:dev'])

event.rb

require 'datadog/statsd'

statsd = Datadog::Statsd.new('localhost', 8125)

statsd.event('An error occurred', "Error message", alert_type: 'error', tags: ['env:dev'])

event.go

package main

import (
    "log"
    "time"

    "github.com/DataDog/datadog-go/statsd"
)

func main() {

    dogstatsdClient, err := statsd.New("127.0.0.1:8125")

    if err != nil {
        log.Fatal(err)
    }
    for {
        dogstatsdClient.SimpleEvent("An error occurred", "Error message")
        time.Sleep(10 * time.Second)
    }
}

event.java

import com.timgroup.statsd.Event;
import com.timgroup.statsd.NonBlockingStatsDClient;
import com.timgroup.statsd.StatsDClient;

public class DogStatsdClient {

    public static void main(String[] args) throws Exception {

        StatsDClient Statsd = new NonBlockingStatsDClient("statsd", "localhost", 8125);

        Event event = Event.builder()
          .withTitle("An error occurred")
          .withText("Error message")
          .withAlertType(Event.AlertType.ERROR)
          .build();

        Statsd.event(event)
    }
}

event.cs

using StatsdClient;

public class DogStatsdClient
{
    public static void Main()
    {
        var dogstatsdConfig = new StatsdConfig
        {
            StatsdServerName = "127.0.0.1",
            StatsdPort = 8125,
        };

        StatsdClient.DogStatsd.Configure(dogstatsdConfig);

        DogStatsd.Event("An error occurred", "Error message", alertType: "error", tags: new[] { "env:dev" });
    }
}

event.php

<?php

require __DIR__ . '/vendor/autoload.php';

use DataDog\DogStatsd;

$statsd = new DogStatsd(
    array('host' => '127.0.0.1',
          'port' => 8125,
     )
  );

$statsd->event('An error occurred.',
    array( 'text' => 'Error message',
           'alert_type' => 'error'
    )
  );

With the DogStatsD-PHP library you can submit events via TCP directly to the Datadog API. It’s slower but more reliable than using the Agent DogStatsD instance since events are forwarded from your application to the Agent using UDP. To use this, you must configure the library with your Datadog API and application keys instead of the local DogStatS instance:

event_through_api.php

<?php

require __DIR__ . '/vendor/autoload.php';

use DataDog\DogStatsd;

$statsd = new DogStatsd(
    array('api_key' => '<DATADOG_API_KEY>',
          'app_key' => '<DATADOG_APPLICATION_KEY>',
     )
  );

$statsd->event('An error occurred.',
    array( 'text' => 'Error message',
           'alert_type' => 'error'
    )
  );

Note:

  • Sending events with this method uses cURL for API requests.
  • You should use a try/catch code block to avoid warnings or errors on communication issues with the Datadog API.

Further reading