| tags:raspberry pi openwrt categories:computing

Prometheus on OpenWRT

Pi OpenWRT Prometheus

監視アプリのPrometheusをOpenWRTにインストールします。 GoLangで書かれシングルバイナリーで配布されています。なかなか素敵です。

OpenWRTではパッケージで提供されています。

Install

様々なNodeエクスポーターがありますが、いくつかに絞りました。

root@OpenWrt:~$ opkg install prometheus 
root@OpenWrt:~$ opkg install prometheus-node-exporter-lua-netstat prometheus-node-exporter-lua-openwrt prometheus-node-exporter-lua-wifi prometheus-node-exporter-lua-wifi_stations

そしてストレージの設定、データー領域を確保します。

root@OpenWrt:~$ mkdir -p /srv/prometheus/data
root@OpenWrt:~$ chown -R prometheus:prometheus /srv/prometheus/data

prometheusの設定

以下の設定ファイルを編集する必要があります。

  • /etc/config/prometheus
  • /etc/prometheus.yml
  • /etc/config/prometheus-node-exporter-lua

/etc/config/prometheus

OpenWRTの設定ファイル、ストレージのパスを上で設定した ‘/data’ -> ‘/srv/prometheus/data’ に変更。

他の端末のGrafanaよりアクセスを行うので、 web_listen_addressを 0.0.0.0:9090 に変更します。

root@OpenWrt:~$ vi /etc/config/prometheus

config prometheus 'prometheus'
        option config_file '/etc/prometheus.yml'
        option storage_tsdb_path '/srv/prometheus/data'
        option web_listen_address '0.0.0.0:9090'

/etc/prometheus.yml

プロメテウスの設定ファイル、新しいjobを追加します。 とりあえずローカルのみの監視になるので、以下のノード設定を追記します。

  - job_name: 'localnetwork'
    static_configs:
    - targets: ['localhost:9100']

で、以下のようになります。

root@OpenWrt:~$ vi /etc/prometheus.yml

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'localnetwork'
    static_configs:
    - targets: ['localhost:9100']

Exporterの設定:/etc/config/prometheus-node-exporter-lua

エクスポーターの設定ファイル、 listen_interface部分のIPを変更する必要があるとみて 127.0.0.1 に変更したら接続エラーが出ました。 結局いじる必要なくそのままでよいようです。

$ cat /etc/config/prometheus-node-exporter-lua 

config prometheus-node-exporter-lua 'main'
        option listen_interface 'loopback'
        option listen_ipv6 '0'
        option listen_port '9100'

サービスの起動

プロメテウスとエクスポーターのサービスをスタートします。

root@OpenWrt:~$ service prometheus start
root@OpenWrt:~$ /etc/init.d/prometheus-node-exporter-lua restart

端末よりプロメテウスにアクセスします。

http://«SERVER_IP»:9090

ここで、管理画面に到着できれば良いです。 以下のように接続されていれば問題なし。

Pi OpenWRT Prometheus

参考: https://stuarthowlette.me.uk/posts/prometheus-monitoring-other-os/ https://wiki.archlinux.jp/index.php/Prometheus


Grafanaにて表示する

Prometeusでグラフを表示することも可能なのですが、 外部の端末にて、Grafanaでデーターをアクセスして表示することにする。

メイン端末のHackintoshにGrafanaをインストール。brewで一発です。

ダッシュボードは人様のをお借りします。

https://grafana.com/grafana/dashboards/11147

データーベースの設定をして、表示されます!

Pi OpenWRT Prometheus

当分はちょっと細かくデータ更新します。 ちょっと動向を眺めて落ち着いたらデーターが大きくなるのもなんなので、 15秒の設定を長く変えます。

Zeroだと両方共にカツカツになってしまうので、この辺のバランスをとった SBCを発売してくれないからん。。

DualCore + 2GB.RAM、11ac対応&USB3で省電力の物があれば、 ストレージに少し高速なMMCだあればサーバー用途で最高なんだけどね、。。


おまけ:

ついでにゼロでもちょっとインストールしてみましたがちょっと表示部分で問題が、、 データー自体は引っこ抜いてこれているようなので、また気が向いたらかな。

監視するまでもないので、後回し。

pi@raspberrypi:~ $ sudo apt install prometheus-node-exporter

See Also

🏝 tipping

🌷 sat ⚡️ goozenlab@getalby.com
🌻 bitcoin : bc1qnjhnsxgqah050995dkdveav4y3t3d7uxyme4ud

If you do send a tip, Please email me so that I can say thank you.