Issue 3014 rp api kpi

@kparlante, @seanmonstar - wanna review this?

I broke it into two commits. The first is code cleanup. The second fixes the bug.

fixes #3014