statsd_server

The `statsd_server` directive sets the hostname or IP address of the StatsD server that NGINX will send statistics to.

Syntaxstatsd_server address;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The statsd_server directive is utilized to specify the address of the StatsD server to which NGINX should send its statistics. This directive is part of the NGINX module designed for metrics collection, allowing users to monitor various performance metrics of their web servers. Within the module, this directive can be configured in three contexts: http, server, or location, providing flexibility in defining where the statistics are collected and sent.

When configuring this directive, users must provide a single argument, which is the address of the StatsD server. If the StatsD server is provided in the http context, it applies globally to all servers and locations defined within that http block. If overridden in a specific server or location block, the defined StatsD server will replace the global setting for that particular context.

To effectively manage traffic and avoid overloading the StatsD server, the statsd_sample_rate directive can also be used in conjunction with statsd_server. By setting a sample rate, users can control what percentage of statistics are sent to the server, ensuring that only a manageable amount of data is transmitted, which can be particularly useful in high-traffic environments.

Config Example

http {
    statsd_server your.statsd.server.com;
    statsd_sample_rate 10; 

    server {
        listen 80;
        server_name www.example.com;

        statsd_count "example.requests" 1;

        location / {
            statsd_count "example.pages.index_requests" 1;
            proxy_pass http://backend;
        }
    }
}

Ensure that the StatsD server is reachable from the NGINX server; otherwise, no metrics will be sent.

Misconfiguring the address (e.g., typo in the hostname) will cause failures in sending statistics, so double-check the server address.

← Back to all directives