> ## 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.

# 使用 qrb_ros_system_monitor 发布系统状态

`qrb_ros_system_monitor` 示例应用程序具有各种 ROS 节点,用于发布系统状态信息,例如 CPU 负载、内存使用情况和磁盘空间。

## `qrb_ros_system_monitor` 的管道

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

<img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-staging/zh/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/sys-monitor-pipeline.svg" style={{ width: "100%", display: "block", margin: "0 auto" }} />

<p style={{ textAlign: 'center', fontWeight: 'bold'}}>
  图: 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`

<Accordion title="试一试">
  <Steps>
    <Step title="在设备上设置 QIR SDK 和 ROS2 环境">
      启动两个终端,并在每个终端中运行以下命令。

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

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

    <Step title="运行系统监控 ROS 节点">
      在终端 1 中,运行系统监控 ROS 节点。

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

      输出结果如下所示:

      ```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="查看系统信息">
      在终端 2 中,使用 `ros2 topic list` 查看 ROS 主题。

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

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

      使用 `ros2 topic echo /cpu` 查看 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>

## 构建并运行 `qrb_ros_system_monitor`

<Accordion title="试一试">
  <Steps>
    <Step title="在主机计算机上构建 qrb_ros_system_monitor">
      在主机计算机上构建 QIR SDK 提供的 `qrb_ros_system_monitor`,请参考:[开发 ROS2 示例应用程序](./develop-a-sample-ros-2-application.mdx)。以 `IQ-9075` 为例:

      ```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="将 qrb_ros_system_monitor 推送到设备">
      <Note>
        **注意**

        确保设备上已安装 QIR SDK。
      </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="在设备上设置 QIR SDK 和 ROS2 环境">
      启动两个终端,并在每个终端中运行以下命令。

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

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

    <Step title="运行系统监控 ROS 节点">
      在终端 1 中,运行系统监控 ROS 节点。

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

    <Step title="获取系统信息">
      在终端 2 中,获取系统信息。

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

## 限制

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