QNAPでnode_exporterを動かす

Prometheusサーバを立ち上げたので、同じネットワーク内にあるQNAPの情報を収集するためにNode exporterを動かす

前提

  • 管理者アカウント名はadmin

準備

  • QNAPに管理アカウントでSSHクライアントでログインする

インストール

ホームディレクトリだと、再起動やファームウェアのアップデートで消えるため、/share/homes/admin以下に設置することにする

パス 用途
/share/homes/admin/opt プログラム本体
/share/homes/admin/bin 起動プログラム
  1. 設置場所作成

    mkdir /share/homes/admin/opt
    mkdir /share/homes/admin/bin
    cd /share/homes/admin/opt
    
  2. ReleasesからCPUにあったファイルをダウンロード

    curl -LO https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz
    
  3. 展開

    tar -xvzf node_exporter-1.2.2.linux-amd64.tar.gz -C /share/homes/admin/opt
    mv node_exporter-1.2.2.linux-amd64 node_exporter
    
  4. 実行確認

    /share/homes/admin/node_exporter/node_exporter  --version
    
  5. 起動スクリプト作成

    /share/homes/admin/binにnode_exporter.shを作成する

    #!/bin/bash
    
    DAEMON_MGR="/sbin/daemon_mgr"
    NAME=node_exporter
    PROG=/share/homes/admin/opt/node_exporter/node_exporter
    OPT=""
    
    case "$1" in
        start)
            mypid=`/bin/pidof $NAME`
            if [ ! -z $mypid ]; then
                    exit 1
            else
                echo -n "Starting $NAME: "
                $DAEMON_MGR $NAME start "$PROG $OPT &"
                exit 0
            fi
            ;;
        stop)
            echo -n "Stopping $NAME: "
            $DAEMON_MGR $NAME stop "$PROG"
            echo
            ;;
        *)
            echo "Usage: $1 start|stop"
            exit 1
            ;;
    esac
    
    exit 0
    
  6. 起動スクリプトに実行権限付与

    chmod +x /share/homes/admin/bin/node_exporter.sh
    
  7. 起動確認

    # 起動
    /share/homes/admin/bin/node_exporter.sh start
    
    # プロセスがあるか確認
    ps | grep node_exporter
    28556 admin      5140 S   /share/homes/admin/opt/node_exporter/node_exporter
    
    # 停止
    /share/homes/admin/bin/node_exporter.sh stop
    
  8. ブラウザから確認 ブラウザで http://QNAPのIP:9100/metrics を開いて、メトリクスが出力されているか確認 ブラウザ

古いQNAPだと、メトリクスが取得できないものがあります。その場合は--no-collector.オプションで取得しないようにします

選択できるオプションはhelpコマンドで見られます

例)TS-120

panic: runtime error: index out of range [0] with length 0

goroutine 60 [running]:
github.com/prometheus/procfs.evalStatusLine(0x2d2e1dd, 0x25, 0x2d2e203, 0x3, 0x0, 0x2df9a40, 0x0, 0x1, 0x1, 0x0, ...)
        /go/pkg/mod/github.com/prometheus/procfs@v0.7.2/mdstat.go:170 +0x5e4
github.com/prometheus/procfs.parseMDStat(0x2cdd800, 0x16f, 0x200, 0x16f, 0x200, 0x0, 0x0, 0x2)
        /go/pkg/mod/github.com/prometheus/procfs@v0.7.2/mdstat.go:105 +0x228
github.com/prometheus/procfs.FS.MDStat(0x6bc94c, 0x5, 0x6bc94c, 0x5, 0x0, 0x0, 0x0)
        /go/pkg/mod/github.com/prometheus/procfs@v0.7.2/mdstat.go:71 +0x110
github.com/prometheus/node_exporter/collector.(*mdadmCollector).Update(0x2d25110, 0x2d82ec0, 0x7e305645, 0x2)
        /app/collector/mdadm_linux.go:110 +0xc0
github.com/prometheus/node_exporter/collector.execute(0x6bd1ee, 0x5, 0x799ef0, 0x2d25110, 0x2d82ec0, 0x799b30, 0x2c5bdd0)
        /app/collector/collector.go:161 +0x40
github.com/prometheus/node_exporter/collector.NodeCollector.Collect.func1(0x2d82ec0, 0x2d10520, 0x799b30, 0x2c5bdd0, 0x2d7c8c0, 0x6bd1ee, 0x5, 0x799ef0, 0x2d25110)
        /app/collector/collector.go:152 +0x4c
created by github.com/prometheus/node_exporter/collector.NodeCollector.Collect
        /app/collector/collector.go:151 +0xcc

mdadm関係のエラーのため、--no-collector.mdadmオプションで無効にします

node_exporter --no-collector.mdadm

起動スクリプトのOPTに--no-collector.mdadmを追記

自動起動

自動起動するためには、以下の方法があるようです

参考

QNAPでnode_exporterを動かす” への1件のフィードバック

コメントは停止中です。