Moved metrics code to a plugin