0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenWrt + Prometheus + Grafana でルーター監視 (Lua版 Node Exporter)

Last updated at Posted at 2025-04-08

確実に忘れるのでメモ

0. 動機

  • ネットワークが遅い
  • Grafanaを使用したかった

1. 構成

サーバ OS アドレス 役割
ルータ OpenWrt 192.168.8.1 監視対象
監視サーバ Ubuntu 22.04.5 LTS 192.168.8.20 メトリクス配置
クライアント Windows 11 192.168.8.10 ブラウザ

2. 流れ

  • OpenWrt に prometheus-node-exporter-lua をインストール
  • Prometheus と Grafana を用いてルーターの監視ダッシュボードを作成

3. prometheus-node-exporter-lua のインストール

ルータで実施する。

OpenWrt に Lua版 Node Exporter をインストール

prometheus-node-exporter-lua は、OpenWrt のような組み込みシステム向けの軽量な Prometheus エクスポーター。

sudo opkg update
sudo opkg install prometheus-node-exporter-lua

ローカルホストのバインド解除

prometheus-node-exporter-lua はデフォルトで127.0.0.1にバインドして動作するため、外部(192.168.8.20)からアクセスできない。

そのため、バインドアドレスをuciを使用して変更する(lanインターフェース: 192.168.8.1)。

sudo uci set prometheus-node-exporter-lua.main.liten_interface='lan'

# 設定を保存
sudo uci commit prometheus-node-exporter-lua

# 再起動
sudo /etc/init.d/prometheus-node-exporter-lua restart

監視サーバからアクセスして確認。

curl http://192.168.8.1:9100/metrics

4. Prometheus のインストール

監視サーバで実施する。

Ubuntu serevr に Prometheus をインストールする

sudo apt update
sudo apt install prometheus

設定ファイル作成

/etc/prometheus/prometheus.ymlを編集する。

job_name は Grafana ダッシュボードでjobを指定するときの名前になる。
targets に監視対象のprometheus-node-exporter-luaのアドレスとポートを記載。

scrape_configs:
  - job_name: 'router1'
    static_configs:
      - targets: ['192.168.8.1:9100']

サービス等再起動

sudo systemctl daemon-reload

sudo systemctl restart prometheus

# 確認
sudo systemctl status prometheus

5. Grafana のインストール

監視サーバで実施する。

Grafana のインストール

# gpgキー取得
wget -q -O /usr/share/keyrings/grafana.gpg https://packages.grafana.com/gpg.key

# リポジトリ登録
echo "deb [signed-by=/usr/share/keyrings/grafana.gpg] https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list

# パッケージを更新してインストール
sudo apt update
sudo apt install grafana

# サービス起動
sudo systemctl daemon-reload
sudo enable grafana-server
sudo systemctl start grafana-server

6. Grafana ダッシュボード作成

クライアントで実施する。

ダッシュボード作成

192.168.8.20:3000にアクセスし、以下の情報でログインすると任意のパスワードでパスワード変更を求められるので実施。

  • user: admin
  • password: admin

データソース設定

サイドバーのConnections/Data sourcesから Prometheus を選択し、localhost:9090を入力。

Grafana ダッシュボードのインポート

以下のダッシュボードをインポートする。

  • Node Exporter Full(Grafana ダッシュボードID: 1860)

Jobをprometheusで設定した名前に変更して、以下のような画面が出れば成功

補足

繋がらない場合はファイヤーウォール等でアクセスできていないこと考える。

0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?