🪂

NASのメトリクスをGrafana Cloudで可視化

2025/01/30に公開

概要

自宅のNAS(LinkStation LS220D)のメトリクスをPrometheusのNode Exporterで取得します。
取得したメトリクスをOpenTelemetry CollectorでGrafana CloudのOpenTelemetry Endpointに送ります。
OpenTelemetry Endpointに送られたメトリクスはGrafana CloudのPrometheusにマッピングされ、Grafanaで可視化できます。

環境

  • LinkStation
# uname -a
Linux LS220D549 3.3.4 #1 Thu Jun 4 17:01:54 JST 2020 armv7l GNU/Linux

# cat /etc/os-release 
NAME=Buildroot
VERSION=2012.08-01784-g121b935
ID=buildroot
VERSION_ID=2012.08
PRETTY_NAME="Buildroot 2012.08"
  • Node Exporter
# node_exporter --version
node_exporter, version 1.8.2 (branch: HEAD, revision: f1e0e8360aa60b6cb5e5cc1560bed348fc2c1895)
  build user:       root@c129d06b03dd
  build date:       20240714-11:53:16
  go version:       go1.22.5
  platform:         linux/arm
  tags:             unknown
  • OpenTelemetry Collector
# otelcol-contrib --version
otelcol-contrib version 0.117.0

前提

  • ACP_CommanderでLinkStationにrootでsshログインできる状態

Node Exporterのインストール

Node Exporterのダウンロード&LinkStationへの転送

LinkStationでcurlコマンドが使えないので、ローカルPCでNode ExporterをダウンロードしてLinkStationに転送します。

ローカルPCでの作業
% curl -OL https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-armv7.tar.gz
% scp node_exporter-1.8.2.linux-armv7.tar.gz root@nas2:/tmp/

Node Exporterのインストール

LinkStationに転送したNode Exporterをインストールします。

LinkStationでの作業
# cd /usr/local/
# tar xzf /tmp/node_exporter-1.8.2.linux-armv7.tar.gz 
# ln -s /usr/local/node_exporter-1.8.2.linux-armv7/node_exporter /usr/local/bin/node_exporter
# node_exporter --version
node_exporter, version 1.8.2 (branch: HEAD, revision: f1e0e8360aa60b6cb5e5cc1560bed348fc2c1895)
  build user:       root@c129d06b03dd
  build date:       20240714-11:53:16
  go version:       go1.22.5
  platform:         linux/arm
  tags:             unknown

Node Exporterの起動

Node Exporterをバックグラウンドで起動します。
ログの出力先はちゃんと設計すべきですが、ひとまず/var/log/messagesに出力しています。

# nohup /usr/local/bin/node_exporter >> /var/log/messages 2>&1 &

OpenTelemetry Collectorのインストール

Node Exporterと同様にローカルにダウンロード後にLinkStationに転送してインストールします。

OpenTelemetry Collectorのダウンロード&LinkStationへの転送

ローカルPCでの作業
% curl -OL https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.117.0/otelcol-contrib_0.117.0_linux_armv7.tar.gz
% scp otelcol-contrib_0.117.0_linux_armv7.tar.gz root@nas2:/tmp/

OpenTelemetry Collectorのインストール

LinkStationでの作業
# mkdir /usr/local/otelcol
# cd /usr/local/otelcol/
# tar xvzf /tmp/otelcol-contrib_0.117.0_linux_armv7.tar.gz
# ln -s /usr/local/otelcol/otelcol-contrib /usr/local/bin/otelcol-contrib
# otelcol-contrib --version
otelcol-contrib version 0.117.0

接続情報の取得

OpenTelemetry Endpointに接続するための情報をGrafana Cloudから取得します。

Grafana Cloud Portal画面のLaunchをクリックします。

OpenTelemetryのConfigureをクリックします。

Password / API TokenのGenerate nowをクリックします。

Token nameを入力し、Create tokenをクリックします。

Your token has been successfully issued.のメッセージとトークンが表示されます。

環境変数の設定

接続情報の取得で表示したOTLP Endpointの画面に表示された値を使用して、以下の環境変数を設定します。

環境変数名 設定する値
GRAFANA_CLOUD_API_KEY 控えたトークン
GRAFANA_CLOUD_OTLP_ENDPOINT Endpoint for sending OTLP signalsに表示された値
GRAFANA_CLOUD_INSTANCE_ID Instance IDに表示された値
export GRAFANA_CLOUD_API_KEY="トークン"
export GRAFANA_CLOUD_OTLP_ENDPOINT="https://otlp-gateway-prod-ap-southeast-1.grafana.net/otlp"
export GRAFANA_CLOUD_INSTANCE_ID="Instance ID"

設定ファイルの作成

Node Exporterからメトリクスを取得し、Grafana CloudのOpenTelemetry Endpointに送信するための設定を/etc/otelcol/config.yamlに記載します。

/etc/otelcol/config.yaml
receivers:
  prometheus:
    config:
      scrape_configs:
        - job_name: 'node_exporter'
          scrape_interval: 10s
          static_configs:
            - targets: ['localhost:9100']
            
exporters:
  otlphttp/grafana_cloud:
    # https://github.com/open-telemetry/opentelemetry-collector/tree/main/exporter/otlphttpexporter
    endpoint: "${env:GRAFANA_CLOUD_OTLP_ENDPOINT}"
    auth:
      authenticator: basicauth/grafana_cloud
    tls:
      insecure_skip_verify: true

extensions:
  basicauth/grafana_cloud:
    # https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/extension/basicauthextension
    client_auth:
      username: "${env:GRAFANA_CLOUD_INSTANCE_ID}"
      password: "${env:GRAFANA_CLOUD_API_KEY}"

connectors:
  grafanacloud:
    # https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/connector/grafanacloudconnector
    host_identifiers: ["host.name"]


service:
  extensions:
    [
      basicauth/grafana_cloud,
    ]
  pipelines:
    metrics:
      receivers: [prometheus]
      exporters: [otlphttp/grafana_cloud]
tls: failed to verify certificate: x509: certificate signed by unknown authority

OpenTelemetry Collectorの起動

作成した設定ファイルを指定して、OpenTelemetry Collectorをバックグラウンドで起動します。

# nohup /usr/local/bin/otelcol-contrib --config=/etc/otelcol/config.yaml >> /var/log/messages 2>&1 &

Grafanaでの確認

Explore - Metricsを表示します。
Data sourceで末尾がpromのものを選択し、View byでnode_を選択します。
メトリクスが可視化されていることを確認できます。

参考

以下の情報を参考にさせていただきました。
https://prometheus.io/download/#node_exporter
https://github.com/prometheus/node_exporter
https://grafana.com/docs/grafana-cloud/send-data/otlp/
https://grafana.com/docs/grafana-cloud/monitor-applications/application-observability/collector/opentelemetry-collector/

Discussion