graphite-project/carbon — pull request #75 by bitprophet (2013-02-20 05:37:50+00:00)
Title: Fix misreporting cache size/queues metrics

When running Carbon 0.9.x, I noticed my carbon-cache always reporting at least 8.0 for its internal cache size metric. It correctly reports higher numbers when caching actually occurs, but never goes below 8 when inactive.

I found it was because `instrumentation.py` uses the cache data structure (`carbon.cache.MetricCache`) to store its own metrics, and the cache size calculation is performed after 8 other internal metrics are added to the cache. QED.

This pull request moves the calculation (& storage) of these two metrics above the other `record()` calls. It looks good on my system now, though I haven't tested it under load yet.

The code involved looks identical to me in master so this can probably get cherry-picked to both branches.