statsd
pg-statsd · C client functions for sending counters, gauges, and timings to StatsD over UDP.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100123 | statsd | pg-statsd | 0.2.0 | STAT | BSD-3-Clause | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
statsd version 0.2.0 sends counters, gauges, and timing metrics directly from a PostgreSQL backend to a StatsD endpoint over UDP. It is an archived 2014 client with fire-and-forget network behavior; use it only where losing metrics is acceptable and database roles cannot abuse outbound access.
Core Workflow
Install the extension and emit metrics to a reachable StatsD listener:
All functions return void. The host and port are supplied on every call rather than through extension configuration.
Function Forms
statsd.add_timing(host, port, metric, milliseconds)sends anmsmetric.statsd.increment_counter(host, port, metric)increments by one.statsd.increment_counter(host, port, metric, value)sends an explicit counter delta.statsd.increment_counter(host, port, metric, value, sample)adds a sample rate.statsd.set_gauge(host, port, metric, value)has integer and double-precision overloads.
Operational Caveats
Each call performs DNS resolution, opens a UDP socket, and sends one datagram from the querying backend. UDP provides no delivery acknowledgement, and the implementation reports resolution or send failures as server warnings while still returning void, so SQL success does not prove metric delivery. The SQL incorrectly declares these network-side-effecting functions IMMUTABLE; never use them in indexes, generated columns, constraints, or expressions the planner may fold. Revoke broad EXECUTE privileges to prevent arbitrary DNS lookups, network egress, or metric injection. Metric names are not sanitized. Prefer a maintained asynchronous exporter or log/telemetry pipeline for production workloads.