x86系OpenWRTのNetdataをCloud対応に
Celeron J4125ミニPCのVMware ESXi 8.0ハイパーバイザ上で仮想マシンとして動く、OpenWRTルータへインストール済のOpenWRTパッケージ版のNetdataは、クラウド機能を無効にするビルドオプション --disable-cloud が付与された仕様になっているので、動作はスタンドアロンのみに限定されます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
----------------------------------------------------- OpenWrt 22.03.3, r20028-43d71ad93e ----------------------------------------------------- # netdata -W buildinfo Version: netdata v1.33.1 Configure options: '--target=x86_64-openwrt-linux' '--host=x86_64-openwrt-linux' '--build=x86_64-pc-linux-gnu' '--program-prefix=' '--program-suffix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--libexecdir=/usr/lib' '--sysconfdir=/etc' '--datadir=/usr/share' '--localstatedir=/var' '--mandir=/usr/man' '--infodir=/usr/info' '--disable-nls' '--with-zlib' '--with-math' '--disable-x86-sse' '--enable-lto' '--disable-ebpf' '--without-libcap' '--disable-https' '--disable-dbengine' '--disable-compression' '--disable-plugin-nfacct' '--disable-plugin-freeipmi' '--disable-plugin-cups' '--disable-plugin-xenstat' '--disable-backend-prometheus-remote-write' '--disable-unit-tests' '--disable-ml' '--disable-cloud' 'netdata' 'build_alias=x86_64-pc-linux-gnu' 'host_alias=x86_64-openwrt-linux' 'target_alias=x86_64-openwrt-linux' 'CC=x86_64-openwrt-linux-musl-gcc' 'CFLAGS=-pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-x86_64_musl/netdata-v1.33.1=netdata-v1.33.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -ffunction-sections -fdata-sections -O3 ' 'LDFLAGS=-L/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/usr/lib -L/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/lib -znow -zrelro -Wl,--gc-sections' 'CPPFLAGS=-I/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/usr/include -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/include/fortify -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/include ' 'CXX=x86_64-openwrt-linux-musl-g++' 'CXXFLAGS=-pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-x86_64_musl/netdata-v1.33.1=netdata-v1.33.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -ffunction-sections -fdata-sections -O3 ' 'PKG_CONFIG=/builder/shared-workdir/build/sdk/staging_dir/host/bin/pkg-config' 'PKG_CONFIG_PATH=/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/usr/lib/pkgconfig:/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/usr/share/pkgconfig' 'PKG_CONFIG_LIBDIR=/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/usr/lib/pkgconfig:/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/usr/share/pkgconfig' Install type: custom Features: dbengine: NO Native HTTPS: NO Netdata Cloud: NO (by user request) ACLK Next Generation: NO ACLK-NG New Cloud Protocol: NO ACLK Legacy: NO TLS Host Verification: NO Machine Learning: NO Stream Compression: NO Libraries: protobuf: NO jemalloc: NO JSON-C: YES libcap: NO libcrypto: NO libm: YES tcalloc: NO zlib: YES Plugins: apps: YES cgroup Network Tracking: YES CUPS: NO EBPF: NO IPMI: NO NFACCT: NO perf: YES slabinfo: YES Xen: NO Xen VBD Error Tracking: NO Exporters: AWS Kinesis: NO GCP PubSub: NO MongoDB: NO Prometheus Remote Write: NO |
そこで、Netdataで用意されているスタティックビルド版へ入れ替えようと思うので、
今入っているパッケージ版Netdataをアンインストールし、関連ファイルを全て削除しておきます。
まず始めに、サービスを止めてパッケージの削除から。
1 2 3 4 5 6 7 8 9 10 |
# ps | grep netdata 5027 root 37568 SN /usr/sbin/netdata -D -c /etc/netdata/netdata.conf 5058 root 11696 SN /usr/sbin/netdata --special-spawn-server 21243 root 1120 R grep netdata # /etc/init.d/netdata stop # ps | grep netdata 21322 root 1120 S grep netdata # opkg remove netdata Removing package netdata from root... Command failed: Not found |
これで削除されたのはバイナリ /usr/sbin/netdata ぐらいなので、混在を防ぐためにも以下の要領で関連ファイルを全て一旦削除します。
1 2 3 |
# rm -rf /etc/netdata : confやプラグインなど # rm -rf /var/lib/netdata : DBなど # rm -rf /usr/lib/netdata : プラグインひな型 |
続いて kickstart.sh を使ったインストールの前に、必要なパッケージを準備します( bash も必要なので未インストールであればここでインストールが必要)。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# opkg install curl Installing curl (7.86.0-2) to root... Downloading https://downloads.openwrt.org/releases/22.03.3/packages/x86_64/packages/curl_7.86.0-2_x86_64.ipk Installing libmbedtls12 (2.28.2-1) to root... Downloading https://downloads.openwrt.org/releases/22.03.3/packages/x86_64/base/libmbedtls12_2.28.2-1_x86_64.ipk Installing libnghttp2-14 (1.44.0-1) to root... Downloading https://downloads.openwrt.org/releases/22.03.3/packages/x86_64/packages/libnghttp2-14_1.44.0-1_x86_64.ipk Installing libcurl4 (7.86.0-2) to root... Downloading https://downloads.openwrt.org/releases/22.03.3/packages/x86_64/packages/libcurl4_7.86.0-2_x86_64.ipk Configuring libmbedtls12. Configuring libnghttp2-14. Configuring libcurl4. Configuring curl. |
kickstart.sh を一旦ローカルにダウンロードしてから、 --static-only オプション付きで実行します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# wget https://my-netdata.io/kickstart.sh Downloading 'https://my-netdata.io/kickstart.sh' Connecting to 172.67.156.192:443 Writing to 'kickstart.sh' Download completed (82038 bytes) # chmod +x ./kickstart.sh # bash ./kickstart.sh --static-only --- Using /tmp/netdata-kickstart-XXXXbMJiGH as a temporary directory. --- --- Checking for existing installations of Netdata... --- --- No existing installations of netdata found, assuming this is a fresh install. --- [/tmp/netdata-kickstart-XXXXbMJiGH]# sh -c curl https://github.com/netdata/netdata-nightlies/releases/latest -s -L -I -o /dev/null -w '%{url_effective}' | grep -o '[^/]*$' OK --- Attempting to install using static build... --- [/tmp/netdata-kickstart-XXXXbMJiGH]# curl --fail -q -sSL --connect-timeout 10 --retry 3 --output /tmp/netdata-kickstart-XXXXbMJiGH/netdata-x86_64-latest.gz.run https://github.com/netdata/netdata-nightlies/releases/download/v1.38.0-73-nightly/netdata-x86_64-latest.gz.run OK [/tmp/netdata-kickstart-XXXXbMJiGH]# curl --fail -q -sSL --connect-timeout 10 --retry 3 --output /tmp/netdata-kickstart-XXXXbMJiGH/sha256sum.txt https://github.com/netdata/netdata-nightlies/releases/download/v1.38.0-73-nightly/sha256sums.txt OK --- Installing netdata --- [/tmp/netdata-kickstart-XXXXbMJiGH]# sh /tmp/netdata-kickstart-XXXXbMJiGH/netdata-x86_64-latest.gz.run -- ^ |.-. .-. .-. .-. . netdata | '-' '-' '-' '-' real-time performance monitoring, done right! +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+---> (C) Copyright 2017, Costa Tsaousis All rights reserved Released under GPL v3+ You are about to install netdata to this system. netdata will be installed at: /opt/netdata The following changes will be made to your system: # USERS / GROUPS User 'netdata' and group 'netdata' will be added, if not present. # LOGROTATE This file will be installed if logrotate is present. - /etc/logrotate.d/netdata # SYSTEM INIT This file will be installed if this system runs with systemd: - /lib/systemd/system/netdata.service or, for older CentOS, Debian/Ubuntu or OpenRC Gentoo: - /etc/init.d/netdata will be created This package can also update a netdata installation that has been created with another version of it. Your netdata configuration will be retained. After installation, netdata will be (re-)started. netdata re-distributes a lot of open source software components. Check its full license at: https://github.com/netdata/netdata/blob/master/LICENSE Please type y to accept, n otherwise: y -略- WARNING Failed to enable auto updates. Netdata will still work, but you will need to update manually. Successfully installed the Netdata Agent. The following non-fatal warnings or errors were encountered: - Command "chown netdata:netdata /tmp/netdata-kickstart-XXXXbMJiGH/install-type" failed with exit code 1. - Command "/opt/netdata/usr/libexec/netdata/netdata-updater.sh --enable-auto-updates " failed with exit code 1. - Failed to enable auto updates. Netdata will still work, but you will need to update manually. Official documentation can be found online at https://learn.netdata.cloud/docs/. Looking to monitor all of your infrastructure with Netdata? Check out Netdata Cloud at https://app.netdata.cloud. Join our community and connect with us on: - GitHub: https://github.com/netdata/netdata/discussions - Discord: https://discord.gg/5ygS846fR6 - Our community forums: https://community.netdata.cloud/ [/root]# rm -rf /tmp/netdata-kickstart-XXXXbMJiGH OK |
インストールの終わりに指摘されていた netdata ユーザが存在しない件は、パッケージ版でも同じ仕様だったので問題なしと判断します。
プロセスはもう動いていますが、以降もシステム起動時に自動開始するよう、これもパッケージ版を参考に起動スクリプトを作成します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#!/bin/sh /etc/rc.common START=99 USE_PROCD=1 APPBINARY=/opt/netdata/usr/sbin/netdata CONFIGFILE=/opt/netdata/etc/netdata/netdata.conf start_service() { # mkdir -m 0755 -p /var/cache/netdata # chown nobody /var/cache/netdata # mkdir -m 0755 -p /var/lib/netdata # chown nobody /var/lib/netdata # mkdir -m 0755 -p /var/log/netdata # chown nobody /var/log/netdata procd_open_instance procd_set_param command $APPBINARY -D -c $CONFIGFILE procd_set_param file $CONFIGFILE procd_set_param respawn procd_close_instance } |
1 2 3 |
# vi /etc/init.d/netdata # chmod +x /etc/init.d/netdata # /etc/init.d/netdata enable |
既存のプロセスを killall した後、起動スクリプトから開始します。
1 2 3 4 5 6 7 8 9 10 |
# /etc/init.d/netdata start # /etc/init.d/netdata status running # ps | grep netdata 28854 root 208m SN /opt/netdata/bin/srv/netdata -D -c /opt/netdata/etc/netdata/netdata.conf 28868 root 19232 SN /opt/netdata/bin/srv/netdata --special-spawn-server 29054 root 755m SN /opt/netdata/usr/libexec/netdata/plugins.d/go.d.plugin 1 29114 root 6528 SN /opt/netdata/usr/libexec/netdata/plugins.d/apps.plugin 1 29122 root 10548 SN /opt/netdata/usr/libexec/netdata/plugins.d/ebpf.plugin 1 29191 root 1120 R grep netdata |
なおインストールされたバイナリへのパスは通っていないので、個別に呼び出す必要がある場合はフルパスで。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
root@vWrt:~# /opt/netdata/usr/sbin/netdata -W buildinfo Version: netdata v1.38.0-73-g5bfc81f85 Configure options: '--prefix=/opt/netdata/usr' '--sysconfdir=/opt/netdata/etc' '--localstatedir=/opt/netdata/var' '--libexecdir=/opt/netdata/usr/libexec' '--libdir=/opt/netdata/usr/lib' '--with-zlib' '--with-math' '--with-user=netdata' '--enable-cloud' '--without-bundled-protobuf' '--disable-dependency-tracking' 'CFLAGS=-static -O2 -I/openssl-static/include -pipe' 'LDFLAGS=-static -L/openssl-static/lib' 'PKG_CONFIG_PATH=/openssl-static/lib/pkgconfig' Install type: kickstart-static Binary architecture: x86_64 Features: dbengine: YES Native HTTPS: YES Netdata Cloud: YES ACLK: YES TLS Host Verification: YES Machine Learning: YES Stream Compression: YES Libraries: protobuf: YES (system) jemalloc: NO JSON-C: YES libcap: NO libcrypto: YES libm: YES tcalloc: NO zlib: YES Plugins: apps: YES cgroup Network Tracking: YES CUPS: NO EBPF: YES IPMI: NO NFACCT: NO perf: YES slabinfo: YES Xen: NO Xen VBD Error Tracking: NO Exporters: AWS Kinesis: NO GCP PubSub: NO MongoDB: NO Prometheus Remote Write: YES Debug/Developer Features: Trace Allocations: NO |
クラウドへの登録に、ローカルにいるスクリプト netdata-claim.sh を使用してみます(実行には openssl-util パッケージが必要)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# opkg install openssl-util Installing openssl-util (1.1.1s-1) to root... Downloading https://downloads.openwrt.org/releases/22.03.3/packages/x86_64/base/openssl-util_1.1.1s-1_x86_64.ipk Configuring openssl-util. # bash /opt/netdata/bin/netdata-claim.sh -token=############################################################### Token: **************** Base URL: https://api.netdata.cloud Id: ################################### Rooms: Hostname: vWrt Proxy: Netdata user: netdata Generating private/public key for the first time. Generating RSA private key, 2048 bit long modulus (2 primes) ..........................+++++ ..+++++ e is 65537 (0x010001) Extracting public key from private key. writing RSA key Connection attempt 1 successful chown: unknown user/group netdata:netdata Claiming failed Node was successfully claimed. |
これでNetdata CloudにOpenWRTが追加されました。
ARMv8系OpenWRTもNetdata Cloud対応に
もう1台のOpenWRTルータ、FriendlyElec NanoPi R2Sには、SoCにARMv8のRK3328が使われており、こちらにもOpenWRTパッケージ版のクラウド非対応のNetdataが入っています(インストール記事はこちら)。
1 2 3 4 5 6 7 |
----------------------------------------------------- OpenWrt 21.02.2, r16495-bf0c965af0 ----------------------------------------------------- # uname -a Linux R2S 5.4.179 #0 SMP PREEMPT Wed Feb 16 20:29:10 2022 aarch64 GNU/Linux # netdata -W buildinfo Version: netdata v1.30.1 |
これもx86版と全く同じ要領でスタティックビルド版へ入れ替え、Netdata Cloud対応させることができました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# /opt/netdata/usr/sbin/netdata -W buildinfo Version: netdata v1.38.0-90-gd6b071100 Configure options: '--prefix=/opt/netdata/usr' '--sysconfdir=/opt/netdata/etc' '--localstatedir=/opt/netdata/var' '--libexecdir=/opt/netdata/usr/libexec' '--libdir=/opt/netdata/usr/lib' '--with-zlib' '--with-math' '--with-user=netdata' '--enable-cloud' '--without-bundled-protobuf' '--disable-dependency-tracking' 'CFLAGS=-static -O2 -I/openssl-static/include -pipe' 'LDFLAGS=-static -L/openssl-static/lib' 'PKG_CONFIG_PATH=/openssl-static/lib/pkgconfig' Install type: kickstart-static Binary architecture: aarch64 Features: dbengine: YES Native HTTPS: YES Netdata Cloud: YES ACLK: YES TLS Host Verification: YES Machine Learning: YES Stream Compression: YES Libraries: protobuf: YES (system) jemalloc: NO JSON-C: YES libcap: NO libcrypto: YES libm: YES tcalloc: NO zlib: YES Plugins: apps: YES cgroup Network Tracking: YES CUPS: NO EBPF: NO IPMI: NO NFACCT: NO perf: YES slabinfo: YES Xen: NO Xen VBD Error Tracking: NO Exporters: AWS Kinesis: NO GCP PubSub: NO MongoDB: NO Prometheus Remote Write: YES Debug/Developer Features: Trace Allocations: NO |
Netdata Cloud Dashboardで一元監視
こうして登録したNodeたちを拠点毎のWar Roomに振り分け、Node一覧に表示されるMetricsをカスタマイズしてみました。
本来ならDashboard機能を使ってみたかったのですが、ここではSystem Overviewにあるようなゲージがサポートされていないとのことなので、ページをスクロールすることなく全体像を監視するには、Node一覧が今のところの最適解です。
取得可能なMetricsをよく見てみると、NIC毎の情報やWirelessの情報が取得できていなかったので、別途調べてみる必要がありそうです。