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

# 使用 qrb_ros_system_monitor 发布系统状态

`qrb_ros_system_monitor` 示例应用程序包含多个 ROS 节点，用于发布系统状态信息，例如 CPU 负载、内存使用率和磁盘空间。

## `qrb_ros_system_monitor` 的管道

下图展示了该管道，它通过 `sysfs` 节点和一些系统标准命令工具收集系统信息，然后通过 ROS 消息发布这些数据。

<p style={{ textAlign: 'center', fontWeight: 'bold'}}>
  <img src="https://mintcdn.com/qualcomm-prod/BUW_rqJcTn92gBMR/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/sys-monitor-pipeline.svg?fit=max&auto=format&n=BUW_rqJcTn92gBMR&q=85&s=b025d5240f6764404aa5c0fa61f419af" width="1243" height="434" data-path="SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/sys-monitor-pipeline.svg" />

  图：qrb\_ros\_system\_monitor 管道
</p>

## `qrb_ros_system_monitor `管道中使用的 ROS 节点

| ROS 节点             | 描述                  |
| :----------------- | :------------------ |
| CpuMonitor         | 发布 CPU 负载信息。        |
| MemoryMonitor      | 发布内存使用信息。           |
| DiskMonitor        | 发布磁盘空间信息。           |
| SwapMonitor        | 发布交换空间信息。           |
| TemperatureMonitor | 发布 CPU 温度。          |
| BatteryMonitor     | 发布电池信息。             |
| SystemInfoServer   | 发布静态系统信息，例如 CPU 数量。 |

## `qrb_ros_system_monitor ` 管道中使用的 ROS 话题

<table>
  <thead>
    <tr>
      <th style={{ width: '20%' }}>ROS 话题</th>
      <th style={{ width: '25%' }}>消息类型</th>
      <th style={{ width: '20%' }}>发布/订阅方</th>
      <th style={{ width: '35%' }}>描述</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`/cpu`</td>
      <td>`qrb_ros_system_monitor::CpuMonitor`</td>
      <td>由 `CpuMonitor` 发布</td>
      <td>发布 CPU 负载信息。</td>
    </tr>

    <tr>
      <td>`/memory`</td>
      <td>`qrb_ros_system_monitor::MemoryMonitor`</td>
      <td>由 `MemoryMonitor` 发布</td>
      <td>发布内存使用信息。</td>
    </tr>

    <tr>
      <td>`/disk`</td>
      <td>`qrb_ros_system_monitor::DiskMonitor`</td>
      <td>由 `DiskMonitor` 发布</td>
      <td>发布磁盘空间信息。</td>
    </tr>

    <tr>
      <td>`/swap`</td>
      <td>`qrb_ros_system_monitor::SwapMonitor`</td>
      <td>由 `SwapMonitor` 发布</td>
      <td>发布交换空间信息。</td>
    </tr>

    <tr>
      <td>`/temperature`</td>
      <td>`qrb_ros_system_monitor::TemperatureMonitor`</td>
      <td>由 `TemperatureMonitor` 发布</td>
      <td>发布 CPU 温度。</td>
    </tr>

    <tr>
      <td>`/battery`</td>
      <td>`qrb_ros_system_monitor::BatteryMonitor`</td>
      <td>由 `BatteryMonitor` 发布</td>
      <td>发布电池信息。</td>
    </tr>
  </tbody>
</table>

## `qrb_ros_system_monitor ` 管道中使用的 ROS 服务

<table>
  <thead>
    <tr>
      <th style={{ width: '28%' }}>ROS 话题</th>
      <th style={{ width: '20%' }}>消息类型</th>
      <th style={{ width: '22%' }}>服务方</th>
      <th style={{ width: '30%' }}>描述</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`/system_info_server`</td>
      <td>`qrb_ros_system_monitor::SystemInfoServer`</td>
      <td>`SystemInfoServer`</td>
      <td>发布静态系统信息，例如 CPU 数量。 </td>
    </tr>
  </tbody>
</table>

## 前提条件

您已按照[设置运行示例应用程序的环境](./set-up-env-for-sample-app)完成了**设置设备**。

## 运行开箱即用的 `qrb_ros_system_monitor`

1. 启动两个终端，并在每个终端中运行以下命令，在设备上设置 QIR SDK 和 ROS2 环境。
   ```shell theme={null}
   ssh root@[ip-addr]
   (ssh) source /usr/share/qirp-setup.sh
   ```
2. 在终端 1 中，运行系统监控 ROS 节点。
   ```shell theme={null}
   (ssh) ros2 run qrb_ros_system_monitor qrb_ros_system_monitor
   ```
3. 在终端 2 中，通过 ROS 话题查看系统信息。
   ```shell theme={null}
   (ssh) ros2 topic echo /cpu
   ```

## 构建并运行 `qrb_ros_system_monitor`

1. 在主机上构建 QIR SDK 提供的 `qrb_ros_system_monitor`。
   ```shell theme={null}
   cd <qirp_decompressed_workspace>
   source setup.sh
   cd qirp-samples/platform/qrb_ros_system_monitor
   colcon build --merge-install --cmake-args ${CMAKE_ARGS}
   ```
2. 将 `qrb_ros_system_monitor` 推送到设备。

   <Note>
     **注意**

     确保设备上已安装 QIR SDK。
   </Note>

   ```shell theme={null}
   cd <qirp_decompressed_workspace>
   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]
   (ssh) tar --no-overwrite-dir --no-same-owner -zxf /opt/qrb_ros_system_monitor.tar.gz -C /usr/ros/jazzy/
   ```
3. 启动两个终端，并在每个终端中运行以下命令，在设备上设置 QIR SDK 和 ROS2 环境。
   ```shell theme={null}
   ssh root@[ip-addr]
   (ssh) source /usr/share/qirp-setup.sh
   ```
4. 在终端 1 中，运行系统监控 ROS 节点。
   ```shell theme={null}
   (ssh) ros2 run qrb_ros_system_monitor qrb_ros_system_monitor
   ```
5. 在终端 2 中，获取系统信息。
   ```shell theme={null}
   (ssh) ros2 topic echo /cpu
   (ssh) ros2 topic echo /memory
   ```

## **限制**

系统信息值由 `sysfs` 节点和 Linux 标准命令行工具收集。因此，如果 `sysfs` 路径发生变化或命令行工具的输出格式发生变化，这些 ROS 节点可能无法按预期工作。
