0
1

PrometheusとGrafanaを使ってみた。

Last updated at Posted at 2023-12-04

はじめに

自宅にNASサーバを導入し、そのNASサーバがDocker hubが使えたり色々できそうな雰囲気があったのでPrometheusとgrafanaを導入し自身とPCを監視させてみることにした。

Prometheusとexporterのインストール

下記ページへアクセスし、自身の環境に合わせたファイルをダウンロードおよび解凍する。
Prometheusはexporterへリクエストを送り、exporterは監視対象からデータを収集しPrometheusへ返す。
PULL型のためexpoterは監視対象のサーバへインストールする。(SNMP_exporterを除く)

https://github.com/prometheus/prometheus/releases/
https://github.com/prometheus/node_exporter/releases
https://github.com/prometheus/snmp_exporter/releases
https://github.com/prometheus-community/windows_exporter/releases

node_exporterとsnmp_exporterをNASにインストールし、windows_exporterをPCへインストールする。自分が使用しているNASはLinux(arm系)なので以下を使用。

https://github.com/prometheus/prometheus/releases/download/v2.48.0/prometheus-2.48.0.linux-arm64.tar.gz
https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-arm64.tar.gz
https://github.com/prometheus/snmp_exporter/releases/download/v0.24.1/snmp_exporter-0.24.1.freebsd-arm64.tar.gz

起動

インストールした各種exporterを起動する。
例としてnode_exporterは9100番ポートを使用するのでhttp://[IPアドレス]:9100へアクセスし、起動しているか確認する。起動していると以下のようなページが表示される。(表示されない場合はACL等設定がされていないか確認する。)
尚、Metricsを押下するとメトリクスの一覧が表示される。

image.png

同様にほかのexporterについても起動しているか確認する。

起動していることが確認出来たらPrometheus.ymlを編集し、監視対象を定義する。

image.png
編集したらPrometheusも起動する。

起動後、http://[IPアドレス]:9090からPrometheusへアクセスし、Status→Targetsから監視対象のステータスを確認する。

image.png

上記全て確認出来たらPrometheus側の設定は完了。

grafanaダッシュボードの設定

Prometheusのグラフはダサい見づらいのでgrafanaを使用し見やすくかつスタイリッシュなダッシュボードを作成する。自分はDockerイメージを使用したが公式からダウンロードする場合は以下ページから行う。
https://grafana.com/grafana/download

grafanaを起動したらHome→connections→Data Sourceから監視サーバのアドレスを入力。

image.png

設定後、ダッシュボードの設定を行う。ダッシュボードはプリセットを使用できるほか、自分で設定もできる。
grafanaの公式ページからダッシュボードプリセットのJSONファイルをダウンロードすることもできる。
https://grafana.com/grafana/dashboards/

ダッシュボードの設定をすることで各パラメータが表示される。かっこいい。テンション上がる。
image.png

0
1
0

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