WIP: Add monitoring to API

Not ready for merge. Adds monitoring. Bit of refactoring.