Optional GenServer that monitors the ROS 2 graph and emits :telemetry
events when nodes, topics, services, or actions join or leave.
Telemetry events
All measurements are %{count: 1}.
| Event | Metadata keys |
|---|---|
[:rclex, :graph, :node_joined] | node_name, node_namespace |
[:rclex, :graph, :node_left] | node_name, node_namespace |
[:rclex, :graph, :topic_joined] | topic_name, topic_types |
[:rclex, :graph, :topic_left] | topic_name, topic_types |
[:rclex, :graph, :service_joined] | service_name, service_types |
[:rclex, :graph, :service_left] | service_name, service_types |
[:rclex, :graph, :action_joined] | action_name, action_types |
[:rclex, :graph, :action_left] | action_name, action_types |
Enabling
Pass graph_monitor: true when starting a node:
Rclex.start_node("my_node", graph_monitor: true)Requires the :telemetry library to be listed as a dependency in your project.
on_entity/4
Registers a callback that fires when a ROS entity is visible in the graph.
The callback receives the matching entity_spec as its only argument. If
the entity is already present when on_entity/4 is called, the callback
fires before the function returns. Otherwise it fires once the first time
the entity joins. Each firing runs in its own Task, so a slow or crashing
callback cannot block or crash the GraphMonitor.
Rclex.GraphMonitor.on_entity("my_node", {:node, "camera_node", "/sensors"}, fn entity_spec ->
IO.inspect(entity_spec, label: "joined")
end)
Summary
Types
Identifies a ROS graph entity to watch.
Functions
Returns a specification to start this module under a supervisor.
Return the current graph snapshot maintained by the monitor.
Registers callback to be called with entity_spec when it is present in
the ROS graph. If the entity is already visible, callback is invoked
before this function returns. Otherwise it fires once the first time the
entity appears. Each firing runs in its own Task.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Return the current graph snapshot maintained by the monitor.
The snapshot is a map with keys :nodes, :topics, :services, and
:actions, each being a MapSet of the currently known graph entities.
opts
:namespace— namespace of the monitor node. Defaults to"/".
@spec on_entity( monitor_node_name :: String.t(), entity_spec :: entity_spec(), callback :: (entity_spec() -> any()), opts :: [{:namespace, String.t()}] ) :: :ok
Registers callback to be called with entity_spec when it is present in
the ROS graph. If the entity is already visible, callback is invoked
before this function returns. Otherwise it fires once the first time the
entity appears. Each firing runs in its own Task.
entity_spec can be:
{:node, node_name, node_namespace}— a ROS node{:topic, topic_name}— a topic (any publisher or subscriber){:service, service_name}— a service server{:action, action_name}— an action server
opts
:namespace— namespace of the monitor node. Defaults to"/".