> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs-staging.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Publish system status with qrb_ros_system_monitor

The `qrb_ros_system_monitor` sample application has various ROS nodes that publish system status information, such as CPU loading, memory usage, and disk space.

## Pipeline for `qrb_ros_system_monitor`

The figure shows the pipeline, which collects system information with the `sysfs` node and some system standard command tools, and then publishes this data with ROS messages.

<img src="https://mintcdn.com/qualcomm-staging/blZpKs_b9On5nj-y/archives/2.1/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/sys-monitor-pipeline.svg?fit=max&auto=format&n=blZpKs_b9On5nj-y&q=85&s=c997685abd6986331e00fc688f823c85" style={{ width: "100%", display: "block", margin: "0 auto" }} width="1243" height="434" data-path="archives/2.1/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/sys-monitor-pipeline.svg" />

<p style={{ textAlign: 'center', fontWeight: 'bold'}}>
  Figure: qrb\_ros\_system\_monitor pipeline
</p>

## ROS nodes used in the `qrb_ros_system_monitor` pipeline

| ROS node | Description |
| :- | :- |
| CpuMonitor | Publishes the CPU loading information. |
| MemoryMonitor | Publishes the memory usage information. |
| DiskMonitor | Publishes the disk space information. |
| SwapMonitor | Publishes the swap space information. |
| TemperatureMonitor | Publishes the CPU temperature. |
| BatteryMonitor | Publishes the battery information. |
| SystemInfoServer | Publishes static system information, such as CPU count. |

## ROS topics used in the `qrb_ros_system_monitor` pipeline

<table>
  <thead>
    <tr>
      <th style={{ width: '20%' }}>ROS topic</th>
      <th style={{ width: '25%' }}>Message type</th>
      <th style={{ width: '20%' }}>Published/Subscribed by</th>
      <th style={{ width: '35%' }}>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`/cpu`</td>
      <td>`qrb_ros_system_monitor::CpuMonitor`</td>
      <td>Published by `CpuMonitor`</td>
      <td>Publishes the CPU loading information.</td>
    </tr>

    <tr>
      <td>`/memory`</td>
      <td>`qrb_ros_system_monitor::MemoryMonitor`</td>
      <td>Published by `MemoryMonitor`</td>
      <td>Publishes the memory usage information.</td>
    </tr>

    <tr>
      <td>`/disk`</td>
      <td>`qrb_ros_system_monitor::DiskMonitor`</td>
      <td>Published by `DiskMonitor`</td>
      <td>Publishes the disk space information.</td>
    </tr>

    <tr>
      <td>`/swap`</td>
      <td>`qrb_ros_system_monitor::SwapMonitor`</td>
      <td>Published by `SwapMonitor`</td>
      <td>Publishes the swap space information.</td>
    </tr>

    <tr>
      <td>`/temperature`</td>
      <td>`qrb_ros_system_monitor::TemperatureMonitor`</td>
      <td>Published by `TemperatureMonitor`</td>
      <td>Publishes the CPU temperature.</td>
    </tr>

    <tr>
      <td>`/battery`</td>
      <td>`qrb_ros_system_monitor::BatteryMonitor`</td>
      <td>Published by `BatteryMonitor`</td>
      <td>Publishes the battery information.</td>
    </tr>
  </tbody>
</table>

## ROS services used in the `qrb_ros_system_monitor` pipeline

<table>
  <thead>
    <tr>
      <th style={{ width: '28%' }}>ROS service</th>
      <th style={{ width: '20%' }}>Message type</th>
      <th style={{ width: '22%' }}>Served by</th>
      <th style={{ width: '30%' }}>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`/system_info_server`</td>
      <td>`qrb_ros_system_monitor::SystemInfoServer`</td>
      <td>`SystemInfoServer`</td>
      <td>Publishes static system information, such as CPU count. </td>
    </tr>
  </tbody>
</table>

## Prerequisites

You have **Set up the device** according to [Set up the environment for running sample applications](./set-up-env-for-sample-app).

## Run out-of-the-box `qrb_ros_system_monitor`

<Accordion title="Try me">
  <Steps>
    <Step title="Set up QIR SDK and ROS2 environment on the device">
      Start two terminals, and run the following commands in each terminal.

      ```shell theme={null}
      ssh root@[ip-addr]
      ```

      ```bash title="SSH Session" theme={null}
      source /usr/share/qirp-setup.sh
      ```
    </Step>

    <Step title="Run the system monitor ROS node">
      In terminal 1, run the system monitor ROS node.

      ```bash title="SSH Session" theme={null}
      ros2 run qrb_ros_system_monitor qrb_ros_system_monitor
      ```

      The output looks like this:

      ```log theme={null}
      [INFO] [1754041095.755470762] [cpu_monitor]: CPU Monitor start
      [INFO] [1754041095.775654235] [memory_monitor]: Memory Monitor start
      [INFO] [1754041095.783700187] [temperature_monitor]: Temperature Monitor start
      [INFO] [1754041095.791240297] [disk_monitor]: DISK Monitor start
      [INFO] [1754041095.798755668] [swap_monitor]: Swap Monitor start
      [INFO] [1754041095.804467314] [battery_monitor]: Battery Monitor start
      [INFO] [1754041095.809501190] [system_info_server]: System info server start
      ```
    </Step>

    <Step title="Check the system information">
      In terminal 2, check the ROS topics with `ros2 topic list`.

      ```bash title="SSH Session" theme={null}
      ros2 topic list
      ```

      ```shell title="Output" theme={null}
      /battery
      /cpu
      /disk
      /memory
      /parameter_events
      /rosout
      /swap
      /temperature
      ```

      Check the CPU information with `ros2 topic echo /cpu`:

      ```bash title="SSH Session" theme={null}
      ros2 topic echo /cpu
      ```

      ```shell title="Output" theme={null}
      usage: 8.870357513427734
      user: 2263131
      nice: 17852
      system: 12022972
      idle: 3165299899
      iowait: 235972
      irq: 11140524
      softirq: 4153651
      steal: 294225
      guest: 0
      guest_nice: 0
      ---
      ```
    </Step>
  </Steps>
</Accordion>

## Build and run `qrb_ros_system_monitor`

<Accordion title="Try me">
  <Steps>
    <Step title="Build qrb_ros_system_monitor on the host computer">
      Build `qrb_ros_system_monitor` provided by the QIR SDK on the host computer, reference: [Develop a sample ROS2 application](./develop-a-sample-ros-2-application.mdx). Take `IQ-9075` as an example:

      ```shell theme={null}
      cd <decompressed_workspace>/images/iq-9075-evk/qirpsdk_artifacts/iq-9075-evk/qirp-sdk
      source setup.sh
      cd qirp-samples/platform/qrb_ros_system_monitor
      colcon build --merge-install --cmake-args ${CMAKE_ARGS}
      ```
    </Step>

    <Step title="Push qrb_ros_system_monitor to the device">
      <Note>
        **Note**

        Ensure that the QIR SDK is installed on the device.
      </Note>

      ```shell theme={null}
      cd <decompressed_workspace>/images/iq-9075-evk/qirpsdk_artifacts/iq-9075-evk/qirp-sdk
      cd qirp-samples/platform/qrb_ros_system_monitor/install
      tar czvf qrb_ros_system_monitor.tar.gz lib share
      scp qrb_ros_system_monitor.tar.gz root@[ip-addr]:/opt/
      ssh root@[ip-addr]
      ```

      ```bash title="SSH Session" theme={null}
      tar --no-overwrite-dir --no-same-owner -zxf /opt/qrb_ros_system_monitor.tar.gz -C /usr/ros/jazzy/
      ```
    </Step>

    <Step title="Set up QIR SDK and ROS2 environment on the device">
      Start two terminals, and run the following commands in each terminal.

      ```shell theme={null}
      ssh root@[ip-addr]
      ```

      ```bash title="SSH Session" theme={null}
      source /usr/share/qirp-setup.sh
      ```
    </Step>

    <Step title="Run the system monitor ROS node">
      In terminal 1, run the system monitor ROS node.

      ```bash title="SSH Session" theme={null}
      ros2 run qrb_ros_system_monitor qrb_ros_system_monitor
      ```
    </Step>

    <Step title="Get the system information">
      In terminal 2, get the system information.

      ```bash title="SSH Session" theme={null}
      ros2 topic echo /cpu
      ros2 topic echo /memory
      ```
    </Step>
  </Steps>
</Accordion>

## Limitation

The `sysfs` node and Linux standard command-line tools collect the system information values. Therefore, if the `sysfs` path changes or the output format of command-line tools changes, those ROS nodes may not work as expected.
