Fix potential heap overflow when generating StatsD metric