A simple way is perhaps implement a text-to-metrics system where metrics could be defined as SQL functions.