# Host Metrics on Raspberry Pi

> Monitor Raspberry Pi host metrics including CPU, memory, disk, network, system load, and temperature using OpenTelemetry Collector with Last9

Source: https://last9.io/docs/integrations/observability/host-metrics-on-raspberry-pi/

Use OpenTelemetry to monitor Raspberry Pi host metrics including CPU, memory, disk, network, system load, and **CPU/GPU temperature**.

## Prerequisites

Before setting up Raspberry Pi host metrics monitoring, ensure you have:

- Raspberry Pi (any model) running Raspberry Pi OS
- SSH access to your Pi
- Last9 account with integration credentials

1.  **Determine Your Pi's Architecture**

    Run this command to check your Pi's architecture:

    ```bash
    uname -m
    ```

    - `armv7l` → 32-bit (use `linux_armv7` package)
    - `aarch64` → 64-bit (use `linux_arm64` package)

2.  **Install OpenTelemetry Collector**

    > Note: systemd is required for automatic service configuration.

**64-bit (arm64)**

    For Raspberry Pi 4/5 with 64-bit OS:

    ```bash
    sudo apt-get update
    sudo apt-get -y install wget
    wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.144.0/otelcol-contrib_0.144.0_linux_arm64.deb
    sudo dpkg -i otelcol-contrib_0.144.0_linux_arm64.deb
    ```

**32-bit (armv7)**

    For Raspberry Pi 3 and older, or 32-bit OS:

    ```bash
    sudo apt-get update
    sudo apt-get -y install wget
    wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.144.0/otelcol-contrib_0.144.0_linux_armv7.deb
    sudo dpkg -i otelcol-contrib_0.144.0_linux_armv7.deb
    ```

    More installation options can be found [here](https://opentelemetry.io/docs/collector/installation/#linux).

3.  **Configure OpenTelemetry Collector**

    Create the configuration file:

    ```bash
    sudo nano /etc/otelcol-contrib/config.yaml
    ```

    Use the following configuration optimized for Raspberry Pi:

    ```yaml
    receivers:
      hostmetrics:
        collection_interval: 30s
        scrapers:
          cpu:
            metrics:
              system.cpu.utilization:
                enabled: true
              system.cpu.logical.count:
                enabled: true
          memory:
            metrics:
              system.memory.utilization:
                enabled: true
              system.memory.limit:
                enabled: true
          load:
          disk:
          filesystem:
            metrics:
              system.filesystem.utilization:
                enabled: true
          network:
          processes:
          process:
            mute_process_user_error: true
            mute_process_io_error: true
            mute_process_exe_error: true
            metrics:
              process.cpu.utilization:
                enabled: true
              process.memory.utilization:
                enabled: true

      # Raspberry Pi temperature (requires pi-temp-exporter)
      prometheus/pi_temp:
        config:
          scrape_configs:
            - job_name: "pi-temperature"
              scrape_interval: 30s
              static_configs:
                - targets: ["localhost:9101"]

    processors:
      # Memory limiter to prevent OOM on resource-constrained Pi
      memory_limiter:
        check_interval: 5s
        limit_mib: 100
        spike_limit_mib: 25

      batch:
        timeout: 10s
        send_batch_size: 1000
        send_batch_max_size: 2000

      resourcedetection/system:
        detectors: ["system"]
        system:
          hostname_sources: ["os"]

      resource/pi:
        attributes:
          - key: device.type
            value: raspberry-pi
            action: upsert

      transform/hostmetrics:
        metric_statements:
          - context: datapoint
            statements:
              - set(attributes["host.name"], resource.attributes["host.name"])
              - set(attributes["os.type"], resource.attributes["os.type"])

    exporters:
      otlp/last9:
        endpoint: "{{ .Metrics.WriteURL }}"
        headers:
          "Authorization": "{{ .Metrics.AuthValue }}"

    service:
      pipelines:
        metrics:
          receivers: [hostmetrics, prometheus/pi_temp]
          processors:
            [
              memory_limiter,
              batch,
              resourcedetection/system,
              resource/pi,
              transform/hostmetrics,
            ]
          exporters: [otlp/last9]
    ```

4.  **Install Temperature Exporter (Optional)**

    To collect CPU/GPU temperature and throttle state:

    ```bash
    # Download the exporter
    sudo curl -o /usr/local/bin/pi-temp-exporter.py \
      https://raw.githubusercontent.com/last9/opentelemetry-examples/main/otel-collector/raspberry-pi/pi-temp-exporter.py
    sudo chmod +x /usr/local/bin/pi-temp-exporter.py

    # Create and start service
    sudo tee /etc/systemd/system/pi-temp-exporter.service > /dev/null <<EOF
    [Unit]
    Description=Raspberry Pi Temperature Exporter
    After=network.target

    [Service]
    Type=simple
    ExecStart=/usr/bin/python3 /usr/local/bin/pi-temp-exporter.py
    Restart=always
    User=root

    [Install]
    WantedBy=multi-user.target
    EOF

    sudo systemctl daemon-reload
    sudo systemctl enable pi-temp-exporter
    sudo systemctl start pi-temp-exporter
    ```

5.  **Start the OpenTelemetry Collector Service**

    Reload systemd to apply changes and start the service:

    ```bash
    sudo systemctl daemon-reload
    sudo systemctl enable otelcol-contrib
    sudo systemctl start otelcol-contrib
    ```

## Verification

Check the service status:

```bash
sudo systemctl status otelcol-contrib
```

Monitor logs in real-time:

```bash
sudo journalctl -u otelcol-contrib -f
```

Log into your Last9 account to confirm host metrics are being received.

## Collected Metrics

| Category    | Metrics                                                    |
| ----------- | ---------------------------------------------------------- |
| CPU         | Usage per core, utilization, load averages                 |
| Memory      | Used, free, cached, buffers, utilization                   |
| Disk        | Usage, I/O operations, read/write bytes                    |
| Filesystem  | Usage per mount point                                      |
| Network     | Bytes sent/received, packets, errors                       |
| Load        | 1m, 5m, 15m averages                                       |
| Process     | Count, CPU/memory per process                              |
| Temperature | CPU temp, GPU temp, throttle state (with pi-temp-exporter) |

## Resource Optimization

For Raspberry Pi Zero or older models with limited resources, increase the collection interval and reduce batch sizes:

```yaml
receivers:
  hostmetrics:
    collection_interval: 60s # Instead of 30s

processors:
  batch:
    send_batch_size: 500
    send_batch_max_size: 1000
```

## Need Help?

If you encounter any issues or have questions:

- Join our [Discord community](https://discord.com/channels/652153247672729619/652153247672729621) for real-time support
- Contact our support team at [support@last9.io](mailto:support@last9.io)
