Skip to content

Fix cumulative metrics being incorrectly sent as counters#28

Open
MakonnenMak wants to merge 2 commits intoDataDog:masterfrom
MakonnenMak:master
Open

Fix cumulative metrics being incorrectly sent as counters#28
MakonnenMak wants to merge 2 commits intoDataDog:masterfrom
MakonnenMak:master

Conversation

@MakonnenMak
Copy link

Summary

Fixes #18

DogStatsD counters sum all values received during a flush period, which causes cumulative metrics like worker.respawns to be reported incorrectly.

For example, if worker.respawns=3 is pushed 5 times per flush period, DogStatsD would report 15 instead of 3.

Changes

This PR modifies the plugin to send all uwsgi metrics as DogStatsD gauges (|g) instead of counters (|c). Gauges report the last received value, which correctly represents:

  • Cumulative metrics: requests, respawns, bytes transmitted
  • Snapshot metrics: memory usage, worker count

Why This Works

DogStatsD Counter Behavior:

  • Sums all values during flush period
  • metric:5|c sent 3 times = reports 15

DogStatsD Gauge Behavior:

  • Uses last value received
  • metric:5|g sent 3 times = reports 5

Since uwsgi pushes the same metric value repeatedly until it changes, gauges are the correct type for all uwsgi metrics.

Testing

Updated test suite to verify metrics are sent with the correct type (|g).

🤖 Generated with Claude Code

MakonnenMak and others added 2 commits October 28, 2025 17:40
DogStatsD counters sum all values received during a flush period,
which causes cumulative metrics like worker.respawns to be reported
incorrectly. For example, if worker.respawns=3 is pushed 5 times
per flush period, DogStatsD would report 15 instead of 3.

This change sends all uwsgi metrics as DogStatsD gauges instead,
which report the last received value. This correctly represents
both cumulative metrics (requests, respawns, bytes transmitted)
and snapshot metrics (memory usage, worker count).

Fixes DataDog#18

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The test now verifies that every metric received is sent with
type 'g' (gauge), not just a hardcoded list. This ensures the
fix applies universally to all uwsgi metrics.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@MakonnenMak
Copy link
Author

@remeh Was wondering what you think here and if I could get a review

@remeh
Copy link
Contributor

remeh commented Nov 5, 2025

Hey @MakonnenMak, thanks for the PR.

I don't understand why this change is necessary given that the dogstatsd-all-gauges configuration field already exists. When set to true, it does exactly what you're describing. Am I missing something? I wouldn't be surprised if this field was implemented specifically for your use case.

Additionally, I'm concerned that your change might affect behavior for other users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metric <app>.worker.respawns aggregrated incorrectly

2 participants