Deprecated: Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog.reyfox.com/htdocs/wp/wp-includes/Requests/Cookie/Jar.php on line 63

Deprecated: Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog.reyfox.com/htdocs/wp/wp-includes/Requests/Cookie/Jar.php on line 73

Deprecated: Return type of Requests_Cookie_Jar::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog.reyfox.com/htdocs/wp/wp-includes/Requests/Cookie/Jar.php on line 89

Deprecated: Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog.reyfox.com/htdocs/wp/wp-includes/Requests/Cookie/Jar.php on line 102

Deprecated: Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog.reyfox.com/htdocs/wp/wp-includes/Requests/Cookie/Jar.php on line 111

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog.reyfox.com/htdocs/wp/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 40

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog.reyfox.com/htdocs/wp/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 51

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog.reyfox.com/htdocs/wp/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 68

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog.reyfox.com/htdocs/wp/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 82

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog.reyfox.com/htdocs/wp/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 91

Deprecated: Return type of AIOSEO\Plugin\Common\Models\Model::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog.reyfox.com/htdocs/wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Models/Model.php on line 409

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/blog.reyfox.com/htdocs/wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Utils/Database.php on line 535

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/blog.reyfox.com/htdocs/wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Utils/Database.php on line 535

Deprecated: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in /var/www/blog.reyfox.com/htdocs/wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Models/Model.php on line 174

Deprecated: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in /var/www/blog.reyfox.com/htdocs/wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Models/Model.php on line 174

Deprecated: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in /var/www/blog.reyfox.com/htdocs/wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Models/Model.php on line 174
grafana+prometheusでサーバ監視をしグラフィカルなダッシュボードを作る | reyfox blog

reyfox blog

reyfox tech info

CentOS grafana influxdb Linux prometheus

grafana+prometheusでサーバ監視をしグラフィカルなダッシュボードを作る

投稿日:

少し前までは、fluentd+elasticsearch+kibanaというダッシュボードが流行っていた気がしますが、elasticsearchはJavaで動いているため非常に多くのメモリを消費するという欠点(?)がありました。

今回導入するのは比較的軽いgrafana+prometheusとなります。
grafanaがビジュアライズダッシュボードの役割をし、
prometheusがデータの収集を行います。
grafanaと相性の良いinfluxDBも導入します。

grafanaのインストール

まずはgrafanaからインストールします。


yum install https://dl.grafana.com/oss/release/grafana-5.4.3-1.x86_64.rpm
systemctl start grafana-server
systemctl enable grafana-server

ついでに、grafana-serverの起動と自動起動も設定します。

起動すると、http://localhost(またはサーバIP):3000/login でログインできるようになります。
管理ユーザは admin
パスワードはデフォルトでは admin となっていますが、初回ログイン時にパスワードの変更を促されます。(Skipも可)

influxDBのインストール

後々いろいろと便利なinfluxDBもインストールします。


wget https://dl.influxdata.com/influxdb/releases/influxdb-1.7.3.x86_64.rpm
sudo yum localinstall influxdb-1.7.3.x86_64.rpm
systemctl start influxdb
systemctl enable influxdb

こちらも同様にインストール後、起動及び自動起動の設定を行います。

prometheusのインストール

データを収集するprometheusをインストールします。
といってもprometheusはバイナリで配布されているので設置するだけで動作します。

インストールとテスト起動


mkdir /usr/local/src/prometheus
cd /usr/local/src/prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.6.1/prometheus-2.6.1.linux-amd64.tar.gz
tar zxvf prometheus-2.6.1.linux-amd64.tar.gz
cd prometheus-2.6.1.linux-amd64/
./prometheus
[Ctrl-Cで終了]

必要な場所にファイルを移動します。


mkdir /opt/prometheus
cp -av ./* /opt/prometheus
chmod 755 /opt/prometheus/
chown -R root:root /opt/prometheus/

mkdir /etc/prometheus
ln -s /opt/prometheus/console_libraries /etc/prometheus/console_libraries
ln -s /opt/prometheus/consoles /etc/prometheus/consoles
ln -s /opt/prometheus/prometheus.yml /etc/prometheus/prometheus.yml

設定

/etc/prometheus/prometheus.yml を編集します。


OPTIONS="--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --web.console.libraries=/etc/prometheus/console_libraries --web.console.templates=/etc/prometheus/consoles"

prometheusを自動起動させるためにsystemdに登録

/etc/systemd/system/prometheus.service を作成して編集します。


[Unit]
Description=Prometheus Service
After=network.target

[Service]
Type=simple
EnvironmentFile=-/etc/default/prometheus
ExecStart=/opt/prometheus/prometheus $OPTIONS
PrivateTmp=true
Restart=always

[Install]
WantedBy=multi-user.target

systemd を reload し、自動起動を設定


systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus

systemctl status -l prometheus を実行すると正常に動作しているかをチェックすることが出来ます。

prometheus で使用する node_exporter を導入する

node_exporterはprometheusで取れないシステム情報を取得するのに便利です。


mkdir /opt/node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz
tar zxvf node_exporter-0.170.linux-amd64.tar.gz
mv node_exporter-0.17.0.linux-amd64/node_exporter /opt/node_exporter

node_exporterの起動と自動起動

/etc/systemd/system/node_exporter.service をsystemdで使用できるようにするため新規で作成します。


[Unit]
Description=Node exporter for prometheus
After=network.target

[Service]
Type=simple
EnvironmentFile=-/etc/default/node_exporter
ExecStart=/opt/node_exporter/node_exporter $OPTIONS
PrivateTmp=true

[Install]
WantedBy=multi-user.target

node_exporterをprometheusに設定

/etc/prometheus/prometheus.yml を編集します。
targets: の部分に node_exporter を設定します。


    - targets: ['localhost:9090','localhost:9100']

localhost:9090がprometheus、localhost:9100は node_exporter を意味します。

これで一通りgrafana+prometheusでの設定ができました。

-CentOS, grafana, influxdb, Linux, prometheus

執筆者:

関連記事

CentOS7の初期設定

CentOS7 を Intel NUC にインストールしましたが今の所家庭内ネットワークからのみの想定で、外部からのアクセスはすべてルータでフィルタリングしているため、利便性のため下記の設定を行います …

CentOS7上でUSB温度計で温度を記録してgrafanaでグラフ化する

AmazonでUSBで温度(室温)が図れるデバイスが売っていたのでこれをCentOS7で動いているNUCにつなげて温度をグラフ化してみたいと思います。 やりたいこと USBで温度を計測、その値をinf …

CentOS7にMySQLサーバ(mariaDB)をインストールする

CentOS7からMySQLにかわりmariaDBが採用されていますが、使い方はほぼ MySQLと同じでいけます。 インストール いつもの通り、yumで。 yum install mariadb-se …

CentOS7にSambaサーバを立ててWindows/Macとファイルを共有する

Linux上にsambaサーバを立てて、Windows及びMacとファイル共有をします。 ストレージは以前増設した3TBのHDDを用いて3TBすべてを共有してNASのように使用します。 Intel N …

PHPMyAdminの設置

PHPをインストールしましたが、DBを操作するのに便利なのがPHPMyAdminです。もちろんコマンドラインからも行えますがユーザの追加やユーザ専用のDBを作るとき何度もパスワードを入力したりするのが …


Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/blog.reyfox.com/htdocs/wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Utils/Database.php on line 535

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/blog.reyfox.com/htdocs/wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Utils/Database.php on line 535

Deprecated: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in /var/www/blog.reyfox.com/htdocs/wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Models/Model.php on line 174

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/blog.reyfox.com/htdocs/wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Utils/Database.php on line 535

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/blog.reyfox.com/htdocs/wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Utils/Database.php on line 535

Deprecated: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in /var/www/blog.reyfox.com/htdocs/wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Models/Model.php on line 174