LinuCエヴァンジェリストの鯨井貴博@opensourcetechです。
今回は、Grafanaの始め方の紹介です。
Grafanaは、PrometheusやInfluxDB・Elasticsearch・PostgreSQLなどのダッシュボードを構築するツールです。
予め用意したUbbuntu 20.04 LTS ServerにGrafanaを使える環境を作ります。
まず、Grafanaの入手から。
ここから、該当するプラットフォームのインストーラを取得します。
takahiro@ubuntu2004server:/var/tmp$ wget https://dl.grafana.com/oss/release/grafana_7.0.3_amd64.deb --2020-06-11 18:58:02-- https://dl.grafana.com/oss/release/grafana_7.0.3_amd64.deb Resolving dl.grafana.com (dl.grafana.com)... 2a04:4e42:2e::729, 151.101.198.217 Connecting to dl.grafana.com (dl.grafana.com)|2a04:4e42:2e::729|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 49387092 (47M) [application/x-debian-package] Saving to: ‘grafana_7.0.3_amd64.deb’ grafana_7.0.3_amd64 100%[===================>] 47.10M 9.56MB/s in 5.7s 2020-06-11 18:58:09 (8.26 MB/s) - ‘grafana_7.0.3_amd64.deb’ saved [49387092/49387092] takahiro@ubuntu2004server:/var/tmp$ ls grafana_7.0.3_amd64.deb prometheus-2.19.0.linux-amd64 prometheus-2.19.0.linux-amd64.tar.gz
続いて、依存関係にあるパッケージのインストールです。
takahiro@ubuntu2004server:~$ sudo apt install adduser libfontconfig1 [sudo] password for takahiro: Reading package lists... Done Building dependency tree Reading state information... Done adduser is already the newest version (3.118ubuntu2). adduser set to manually installed. The following packages were automatically installed and are no longer required: linux-headers-5.4.0-31 linux-headers-5.4.0-31-generic linux-image-5.4.0-31-generic linux-modules-5.4.0-31-generic linux-modules-extra-5.4.0-31-generic Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: fontconfig-config fonts-dejavu-core The following NEW packages will be installed: fontconfig-config fonts-dejavu-core libfontconfig1 0 upgraded, 3 newly installed, 0 to remove and 31 not upgraded. Need to get 1,184 kB of archives. After this operation, 3,525 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 fonts-dejavu-core all 2.37-1 [1,041 kB] Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 fontconfig-config all 2.13.1-2ubuntu3 [28.8 kB] Get:3 http://archive.ubuntu.com/ubuntu focal/main amd64 libfontconfig1 amd64 2.13.1-2ubuntu3 [114 kB] Fetched 1,184 kB in 2s (504 kB/s) Selecting previously unselected package fonts-dejavu-core. (Reading database ... 179881 files and directories currently installed.) Preparing to unpack .../fonts-dejavu-core_2.37-1_all.deb ... Unpacking fonts-dejavu-core (2.37-1) ... Selecting previously unselected package fontconfig-config. Preparing to unpack .../fontconfig-config_2.13.1-2ubuntu3_all.deb ... Unpacking fontconfig-config (2.13.1-2ubuntu3) ... Selecting previously unselected package libfontconfig1:amd64. Preparing to unpack .../libfontconfig1_2.13.1-2ubuntu3_amd64.deb ... Unpacking libfontconfig1:amd64 (2.13.1-2ubuntu3) ... Setting up fonts-dejavu-core (2.37-1) ... Setting up fontconfig-config (2.13.1-2ubuntu3) ... Setting up libfontconfig1:amd64 (2.13.1-2ubuntu3) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for libc-bin (2.31-0ubuntu9) ...
そして、Grafanaのインストール。
takahiro@ubuntu2004server:/var/tmp$ sudo dpkg -i grafana_7.0.3_amd64.deb Selecting previously unselected package grafana. (Reading database ... 179993 files and directories currently installed.) Preparing to unpack grafana_7.0.3_amd64.deb ... Unpacking grafana (7.0.3) ... Setting up grafana (7.0.3) ... Adding system user `grafana' (UID 112) ... Adding new user `grafana' (UID 112) with group `grafana' ... Not creating home directory `/usr/share/grafana'. ### NOT starting on installation, please execute the following statements to configure grafana to start automatically using systemd sudo /bin/systemctl daemon-reload sudo /bin/systemctl enable grafana-server ### You can start grafana-server by executing sudo /bin/systemctl start grafana-server Processing triggers for systemd (245.4-4ubuntu3) ...
インストール完了後、Grafanaの起動をします。
起動すると、TCP3000番ポートが公開され、ブラウザからアクセスして利用します。
takahiro@ubuntu2004server:/var/tmp$ sudo systemctl status grafana-server
● grafana-server.service - Grafana instance
Loaded: loaded (/lib/systemd/system/grafana-server.service; disabled; vend>
Active: inactive (dead)
Docs: http://docs.grafana.org
takahiro@ubuntu2004server:/var/tmp$ sudo systemctl start grafana-server
takahiro@ubuntu2004server:/var/tmp$ sudo systemctl status grafana-server
● grafana-server.service - Grafana instance
Loaded: loaded (/lib/systemd/system/grafana-server.service; disabled; vend>
Active: active (running) since Thu 2020-06-11 19:00:35 UTC; 2s ago
Docs: http://docs.grafana.org
Main PID: 2701054 (grafana-server)
Tasks: 9 (limit: 16559)
Memory: 8.9M
CGroup: /system.slice/grafana-server.service
mq2701054 /usr/sbin/grafana-server --config=/etc/grafana/grafana.i>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:38 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:38>
...skipping...
● grafana-server.service - Grafana instance
Loaded: loaded (/lib/systemd/system/grafana-server.service; disabled; vend>
Active: active (running) since Thu 2020-06-11 19:00:35 UTC; 2s ago
Docs: http://docs.grafana.org
Main PID: 2701054 (grafana-server)
Tasks: 9 (limit: 16559)
Memory: 8.9M
CGroup: /system.slice/grafana-server.service
mq2701054 /usr/sbin/grafana-server --config=/etc/grafana/grafana.i>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:37 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:37>
Jun 11 19:00:38 ubuntu2004server grafana-server[2701054]: t=2020-06-11T03:00:38>
ブラウザからhttp://Grafanaが動作するホストのIPアドレス:3000とすると、ログイン画面が表示されます。
アカウントは、デフォルトでadmin/adminでログインできます。
ログインすると、初期画面に移行します。
いいデザインですね♪
続いて、ダッシュボードに表示するデータの登録です。
ここでは、以下の記事で構築したPrometheusをデータソースとして追加します。
Prometheusの始め方 - Opensourcetechブログ
まず、左側のメニューからConfiguration > Data Sourcesと辿ります。
Add Data sourceとし、追加したいデータソースを選択します。
Prometheusを選択し、selectをクリック。
今回は、URLの欄のみ入力しました。
save & testをクリックし、以下のようになればOKです。
[
-
どこかミスなどがあった場合は、以下のようにエラーとなるので項目を見直しましょう。
そして、いよいよダッシュボードの作成です。
create > Dashboardと辿ります。
Add new panelとすれば、表示する情報を登録できます。
今回は、以下の項目のみ編集し、Applyとしました。
- 左下にある赤いベルのようなマークのところで、表示するホスト(仮想マシンやコンテナなど)を選択
- Metricで取得したい項目を選択
- 右にあるパネルの名前を入力
さらに項目を足したい場合、右上にあるアイコンAdd panelからパネルを追加します。
あとは、ダッシュボードを保存すれば完了となります。
右上にあるSave dashboardをクリックし、Saveとすれば監視用のダッシュボードの出来上がり!
作成したダッシュボードは、ログイン後の画面で左下の部分にリストされるので、クリックして開きます。
以上、簡単ですが Grafanaの始め方でした!
おまけ
自動起動設定。
takahiro@ubuntu2004server:/var/tmp$ sudo systemctl is-enabled grafana-server [sudo] password for takahiro: disabled takahiro@ubuntu2004server:/var/tmp$ sudo systemctl enable grafana-server Synchronizing state of grafana-server.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable grafana-server Created symlink /etc/systemd/system/multi-user.target.wants/grafana-server.service → /lib/systemd/system/grafana-server.service. takahiro@ubuntu2004server:/var/tmp$ sudo systemctl is-enabled grafana-server enabled