i'm no pro, so take this with a grain of salt :-)

using lua code you can get the amount of mana left, and the total amount, so you can calculate a % from there.
to get the amount of mana left you use
Code:
UnitPower("player", 0);
more info here: http://www.wowwiki.com/API_UnitPower

I would know how to do it in an addon, but not sure how to do it in a macro.
not sure you can do conditionals (if then else) in a macro.