mutao.net

いわゆる雑記。

Grafana Prometheusな環境構築

grafanaをラズパイにinstall

環境

Rasberry Pi4 ModelB

CentOS 8

構築

https://grafana.com/grafana/download?platform=arm

$ wget https://dl.grafana.com/oss/release/grafana-8.0.5-1.aarch64.rpm
$ sudo yum install grafana-8.0.5-1.aarch64.rpm
$ systemctl enable grafana-server
Synchronizing state of grafana-server.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable grafana-server
Created symlink /etc/systemd/system/multi-user.target.wants/grafana-server.service → /usr/lib/systemd/system/grafana-server.service.
$ firewall-cmd --zone=public --add-port=3000/tcp --permanent
$ systemctl restart firewalld.service
$ systemctl start grafana-server

デフォルトのログインは root : root でログインできる。

f:id:mutaonet:20210714201109p:plain

node_expoter

https://prometheus.io/download/#node_exporter

 ## documentにあるものだとエラーがでたのでgithubから直接wget
 $ wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-arm64.tar.gz
 $ tar -xvzf node_exporter-1.1.2.linux-amd64.tar.gz
 
 ## ブラウザ経由でみたい場合firewallを設定する
 $ firewall-cmd --zone=public --add-port=9100/tcp --permanent
 
 $ systemctl restart firewalld.service
 $ ./node_exporter-1.1.2.linux-arm64/node_exporter
level=info ts=2021-07-11T09:35:59.700Z caller=node_exporter.go:178 msg="Starting node_exporter" version="(version=1.1.2, branch=HEAD, revision=b597c1244d7bef49e6f3359c87a56dd7707f6719)"
level=info ts=2021-07-11T09:35:59.700Z caller=node_exporter.go:179 msg="Build context" build_context="(go=go1.15.8, user=root@f07de8ca602a, date=20210305-09:32:30)"
level=warn ts=2021-07-11T09:35:59.700Z caller=node_exporter.go:181 msg="Node Exporter is running as root user. This exporter is designed to run as unpriviledged user, root is not required."
level=info ts=2021-07-11T09:35:59.701Z caller=filesystem_common.go:74 collector=filesystem msg="Parsed flag --collector.filesystem.ignored-mount-points" flag=^/(dev|proc|sys|var/lib/docker/.+)($|/)
level=info ts=2021-07-11T09:35:59.701Z caller=filesystem_common.go:76 collector=filesystem msg="Parsed flag --collector.filesystem.ignored-fs-types" flag=^(autofs|binfmt_misc|bpf|cgroup2?|configfs|debugfs|devpts|devtmpfs|fusectl|hugetlbfs|iso9660|mqueue|nsfs|overlay|proc|procfs|pstore|rpc_pipefs|securityfs|selinuxfs|squashfs|sysfs|tracefs)$
 $ curl http://localhost:9100/metrics
 $ mv node_exporter-1.1.2.linux-amd64/node_exporter /usr/local/bin
 
 ## servideファイルを作成する。
 $ vi /etc/systemd/system/node_exporter.service
 [Unit]
Description=Prometheus Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
#User=node_exporter ## お好みのuserを指定
#Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target

Prometheus

https://github.com/prometheus/prometheus/releases/tag/v2.28.1

$ wget https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-arm64.tar.gz
$ tar xvzf prometheus-2.28.1.linux-arm64.tar.gz
$ cd prometheus-2.28.1.linux-arm64
$ ./prometheus --config.file=prometheus.yml
## node_exporterを監視設定に含める
$ vi prometheus.yml
## 追記
  - job_name: 'node_exporter'
    static_configs:
    - targets: ['localhost:9100']
## 配置
$ mv prometheus-2.28.1.linux-arm64/prometheus /usr/local/bin;
$ mv prometheus-2.28.1.linux-arm64/promtool /usr/local/bin;

$ mv prometheus-2.28.1.linux-arm64/prometheus.yml /etc/prometheus/;

$ mv prometheus-2.28.1.linux-arm64/consoles /etc/prometheus/;
$ mv prometheus-2.28.1.linux-arm64/console_libraries /etc/prometheus/;

## Service化
$ vi /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
#User=prometheus ## お好みで設定。ここで指定したユーザに/etc/prometheusあたりの権限を付与する。
#Group=prometheus
Type=simple
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/prometheus \
    --config.file=/etc/prometheus/prometheus.yml \
    --storage.tsdb.path=/var/lib/prometheus/ \
    --web.console.templates=/etc/prometheus/consoles \
    --web.console.libraries=/etc/prometheus/console_libraries \
    --web.listen-address=0.0.0.0:9090

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target

f:id:mutaonet:20210714201251p:plain

node_exporterのmetricsをGrafanaで可視化

Prometheusを選択。

f:id:mutaonet:20210714201345p:plain

左メニューからDashboardを作成。

Metrix browserから可視化したいものを選択するだけ。

f:id:mutaonet:20210714201502p:plain