The OpenTelemetry Collector, when configured with a StatsD receiver, provides an integration with Gunicorn to receive StatsD metrics. The Collector uses the StatsD Receiver to receive metrics from the configured endpoint in the Gunicorn configuration file. From there, the metrics are processed and exported to Cloud Observability.
To complete the integration, you will:
You need to configure Gunicorn to use the StatsD exporter.
Run your Gunicorn server with
--statsd-host argument like the following example:
1 gunicorn --bind 0.0.0.0:5000 main:app --statsd-host otel-collector:8125
Gunicorn emits metrics through custom StatsD format. Emitted metrics are broadcasted from StatsD using UDP on the StatsD default port
In the Collector configuration file, configure the StatsD receiver to host StatsD endpoint to receive metrics.
1 2 3 4 5 6 7 8 9 10 receivers: statsd: endpoint: "otel-collector:8125" aggregation_interval: 70s enable_metric_type: true is_monotonic_counter: false timer_histogram_mapping: - statsd_type: "histogram" observer_type: "summary" - statsd_type: "timing"
The OpenTelemetry repo provides additional details about StatsD receiver configuration.
More details about the StatsD configuration can be found here.
Once the Gunicorn receiver is configured, enable it by adding it to one or more pipelines as described in the Collector configuration documentation.
You can validate that metrics are reporting to Cloud Observability on the Metrics details page in Project settings.
In Cloud Observability, click Project settings > Metric details.
Search for Gunicorn metric names.
If needed, click on the metric to edit the description and how the units are displayed in Cloud Observability.
Use the Cloud Observability Terraform Provider to create a dashboard for the metrics.
For a more complete example that’s ready to run, see the Gunicorn integration in Cloud Observability OpenTelemetry Examples.
Updated Dec 20, 2022