Allow any function to be used for metric collection

This commit adds, documents and tests support for using any
module/function for metric collection.