Memory monitoring

Is there a way to monitor ray memory consumption inside the actor?
I want to check how much memory the node that is hosting my actor has and how much memory my actor is consuming and stop some tasks based on a threshold.
I tried using ray.nodes() to gather the information but it doesn’t return memory usage.
I’m considering using the dashboard API to get this info:

  • http://ray_api_path/logical/actors/actor_id
  • http://ray_api_path/nodes/node_id

Is there a better way to do it?