Node.js Datadog StatsD Client

0.0.7 · abandoned · verified Sun Apr 19

node-dogstatsd is an unmaintained Node.js client specifically designed for Datadog's extended StatsD server, differentiating itself from generic StatsD clients by supporting Datadog-specific features like histograms and tags. The package's current stable version is 0.0.7, indicating a very old codebase. It was initially an extension of Steve Ivy's `node-statsd`, adding Datadog's proprietary features. Given its version number and engine requirements (Node.js >=0.1.97), it is largely incompatible with modern Node.js environments and ecosystems. There is no active release cadence, and the project appears to be abandoned, making it unsuitable for new development. Its core utility lies in providing an API to send metrics, timings, and custom events with tags and histograms to a Datadog agent.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `node-dogstatsd` client and send various metric types including increments, timings, histograms, and tagged metrics to a Datadog agent, along with basic socket error handling.

const StatsD = require('node-dogstatsd').StatsD;

// Initialize the client with your Datadog agent host and port
// Replace '127.0.0.1' with your Datadog agent's IP or hostname
// Standard StatsD port is 8125
const c = new StatsD('127.0.0.1', 8125);

// Basic increment and decrement operations
c.increment('node_test.requests_total');
c.incrementBy('node_test.requests_total', 5);
c.decrement('node_test.active_users');

// Record a timing metric (e.g., latency in milliseconds)
c.timing('node_test.api_response_time', 250); // 250 ms

// Record a histogram metric (Datadog-specific)
// Useful for percentile aggregation
c.histogram('node_test.data_processing_size', 1024); // Size in bytes

// Increment a metric with a specific tag (Datadog-specific)
c.increment('node_test.event_count', 1, ['environment:production', 'feature:login']);

// Listen for socket errors (recommended for robustness)
c.socket.on('error', function (exception) {
   console.error("Error event in socket.send(): " + exception.message);
   // Implement proper error handling here, e.g., logging to a file or an error tracking service
});

console.log("Datadog metrics sent successfully (check your Datadog agent logs for verification).");
// In a real application, metrics would typically be sent throughout the application's lifecycle.

view raw JSON →