Refactor stats generation code

Signed-off-by: John Else <john.else@citrix.com>
CA-137766: Add GC stats reporting

rrdd was erronously reporting its own GC stats as xapi's - this code is
adapted from the code removed from rrdd.

Signed-off-by: John Else <john.else@citrix.com>
Merge pull request #1997 from johnelse/ca-137766

CA-137766: Add GC stats reporting