internal/charmstore: copy stats logic from _old

Please note that almost all the code and tests in this PR are already reviewed
and battle-tested.