python-dogstatsd-workshop
How applications send custom metrics to Datadog using the DogStatsD protocol — from first principles.
🎯Purpose
This workshop teaches you how any application can send custom metrics to Datadog without a full SDK — using the lightweight DogStatsD UDP protocol baked into every Datadog Agent.
The core problem: Applications generate continuous streams of data — temperatures, request counts, queue depths. That data is worthless unless something collects it, stores it, and makes it queryable. DogStatsD is the bridge between your application code and Datadog's time-series database.
🏗️How It Works — Architecture
weather simulator
UDP listener
cloud backend
metrics
The Python weather simulator emits gauge metrics every 10 seconds over UDP to port 8125. The DogStatsD server (embedded in the Datadog Agent) buffers those datagrams and forwards them upstream to Datadog over HTTPS. The Agent also scrapes container metrics from the Docker socket simultaneously.
💡Key Concepts
- Gauge: A value at a point in time — e.g.
weather.temperature = 22.5. Replaces the previous value each flush. - Counter: A cumulative count — e.g.
requests_total++. Aggregated as a rate per second. - DogStatsD: A UDP listener on port 8125 embedded inside the Datadog Agent. UDP means fire-and-forget — your app never blocks waiting for an ack.
- DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true: Required when the app and Agent are in separate Docker containers so the Agent listens on all interfaces, not just localhost.
- Tags: Key-value pairs appended to every metric (e.g.
city:tokyo) that let you slice and filter in Datadog.
🚀Quick Start
- Copy the example env file:
cp .env.example .env
- Set your Datadog API key in
.env:DD_API_KEY=your_key_here
- Start all services:
docker compose up -d
- Watch logs to confirm metrics are flowing:
docker compose logs -f app
📊What You'll See in Datadog
Navigate to Metrics Explorer and search for:
weather.temperature weather.humidity weather.wind_speedEach metric will appear with city tags, updated every 10 seconds. You can also check Infrastructure → Containers to see the Agent-collected container metrics.
python-dogstatsd-workshop
DogStatsDプロトコルを使ってアプリケーションがDatadogにカスタムメトリクスを送る仕組みを、基礎から学びます。
🎯目的
このワークショップでは、フルSDKなしで任意のアプリケーションがDatadogにカスタムメトリクスを送れる仕組みを学びます。DatadogエージェントにはDogStatsD UDPプロトコルが組み込まれており、これがアプリとDatadogを繋ぐ橋渡しになります。
解決する問題: アプリケーションは気温・リクエスト数・キュー深度などのデータを常に生成します。それを収集・保存・クエリできる仕組みがなければ、データは無意味です。DogStatsDはそのブリッジです。
🏗️仕組み — アーキテクチャ
weather simulator
UDP listener
cloud backend
metrics
Pythonの気象シミュレーターは10秒ごとにUDP経由でポート8125にゲージメトリクスを送ります。DogStatsDサーバー(Datadogエージェントに組み込み)がそれをバッファリングし、HTTPSでDatadogに転送します。エージェントはDockerソケットからコンテナメトリクスも同時に収集します。
💡重要な概念
- ゲージ (Gauge): ある時点の値(例:
weather.temperature = 22.5)。フラッシュごとに上書きされます。 - カウンター (Counter): 累積カウント(例:
requests_total++)。毎秒のレートとして集計されます。 - DogStatsD: Datadogエージェント内のUDPリスナー(ポート8125)。UDPはfire-and-forgetなのでアプリがブロックされません。
- DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true: アプリとエージェントが別コンテナにある場合に必要。エージェントがlocalhost以外のインターフェースもリッスンするようになります。
- タグ: すべてのメトリクスに付加するキーと値のペア(例:
city:tokyo)。Datadog上でスライス・フィルタリングに使います。
🚀クイックスタート
- envファイルをコピー:
cp .env.example .env
.envにAPIキーを設定:DD_API_KEY=your_key_here
- 全サービスを起動:
docker compose up -d
- ログを確認:
docker compose logs -f app
📊Datadogで確認できること
メトリクスエクスプローラーで以下を検索してください:
weather.temperature weather.humidity weather.wind_speedcityタグ付きで10秒ごとに更新されます。インフラ → コンテナでエージェントが収集したコンテナメトリクスも確認できます。
python-dogstatsd-workshop
從第一原理學習應用程式如何使用 DogStatsD 協定將自訂指標傳送至 Datadog。
🎯目的
本工作坊教您任何應用程式如何在不需要完整 SDK 的情況下,透過內建於每個 Datadog Agent 的輕量 DogStatsD UDP 協定將自訂指標傳送至 Datadog。
核心問題:應用程式持續產生資料(溫度、請求數量、佇列深度),但除非有工具收集、儲存並使其可查詢,否則這些資料毫無意義。DogStatsD 就是應用程式與 Datadog 時間序列資料庫之間的橋樑。
🏗️運作方式 — 架構
weather simulator
UDP listener
cloud backend
metrics
Python 天氣模擬器每 10 秒透過 UDP 向 8125 端口發送 gauge 指標。DogStatsD 伺服器(嵌入在 Datadog Agent 中)緩衝這些資料報後透過 HTTPS 轉發至 Datadog。Agent 同時也透過 Docker socket 抓取容器指標。
💡核心概念
- Gauge:某個時間點的數值,例如
weather.temperature = 22.5,每次刷新時覆蓋前一個值。 - Counter:累積計數,例如
requests_total++,聚合為每秒速率。 - DogStatsD:嵌入 Datadog Agent 的 UDP 監聽器(端口 8125)。UDP 是即發即忘,應用程式不會阻塞等待確認。
- DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true:當應用程式和 Agent 在不同 Docker 容器時必須設定,使 Agent 監聽所有介面而不只是 localhost。
- Tags:附加到每個指標的鍵值對(例如
city:tokyo),讓您在 Datadog 中切片和篩選。
🚀快速開始
- 複製範例環境檔案:
cp .env.example .env
- 在
.env中設定 API 金鑰:DD_API_KEY=your_key_here
- 啟動所有服務:
docker compose up -d
- 查看日誌確認指標正在傳送:
docker compose logs -f app
📊在 Datadog 中會看到什麼
前往 Metrics Explorer 搜尋:
weather.temperature weather.humidity weather.wind_speed每個指標都會附帶城市標籤,每 10 秒更新一次。也可至 Infrastructure → Containers 查看 Agent 收集的容器指標。