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にCPU使用率及びメモリ使用率グラフを追加 | reyfox blog

reyfox blog

reyfox tech info

CentOS grafana Linux prometheus

grafanaにCPU使用率及びメモリ使用率グラフを追加

投稿日:

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

上記記事でgrafana+prometheusでダッシュボードを作成しました。
今回はここにCPU使用率とメモリ使用率を追加してみたいと思います。

なお、使用するバージョンは下記のものとなります。
prometheus Version 2.6.1
node_exporter Version 0.17.0

前回の記事でprometheusを起動している場合、すでに node_exporter も裏で動いていて情報が収集されています。

CPU使用率グラフの追加

まず、grafanaにログインしダッシュボードを開き、上の方の Add panel を選択します。
grafana のアドレスは、http://[サーバアドレス]:3000/ となります。

続いて、Graph を選択します。

今回は、Userが使っているCPUとSystemで使っているCPUを分けてグラフ化してみます。
Data Source を「prometheus」を選択し、Aに以下の文言を入力します。

rate(node_cpu_seconds_total{job="prometheus",mode="user"}[5m]) * 100

上記は、User が使っているCPUとなります。

次にBに以下の文言を入力します。

rate(node_cpu_seconds_total{job="prometheus",mode="system"}[5m]) * 100

General タブを押して、「CPU Usage」などと入力し、ダッシュボードに戻り、ダッシュボードを保存します。

以上でコア別のCPU使用率がグラフ化されました。

メモリ使用率のグラフを追加

CPUのときと同じように Add panel から Graph を選択します。

Data Sourceから「Prometheus」を選びAに以下の文言を入力します。

node_memory_MemTotal_bytes{instance="localhost:9100",job="prometheus"}

続いてBに以下の文言を入力します。

node_memory_MemTotal_bytes{instance="localhost:9100",job="prometheus"} - node_memory_MemAvailable_bytes{instance="localhost:9100",job="prometheus"}

Aはメモリトータルを表示、Bはメモリトータルから空きを引いたものを表示=使用率、となります。

以上で、上記のようなメモリ使用率のグラフが出来ました。
同じようにダッシュボードに戻りダッシュボードを保存します。

ディスクの空き容量をゲージ化する

ディスクの空き容量も同じようにグラフ化は出来ますが、ひと目でわかりやすいようにゲージを使ってみます。

Add panel から Singlestat を選びます。

Data Sourceから「Prometheus」を選び、Aに以下の文言を入力します。

node_filesystem_free_bytes{device="/dev/sda4",fstype="xfs",instance="localhost:9100",job="prometheus",mountpoint="/"}	

上の文言では、/dev/sda4のマウントポイント / の空き容量を示しています。
環境によって変更してください。

以上で空き容量のゲージ化が出来ました。

おまけ: Swap領域の使用率を表示

現在ではメインメモリが多くなりSwapがほとんど使われなくなっていますが、Swapの情報も表示してみます。

Add Panel から Graph を選択し、Data Source に「Prometheus」を設定Aに以下の文言を入力します。

node_memory_SwapTotal_bytes{instance="localhost:9100",job="prometheus"}

次にBに以下の文言を入力します。

node_memory_SwapFree_bytes{instance="localhost:9100",job="prometheus"}

Cに以下の文言を入力します。

node_memory_SwapCached_bytes{instance="localhost:9100",job="prometheus"}

AがSwapのトータル、BがSwapのフリーサイズ、CがSwapのキャッシュサイズとなります。

上記のようにグラフが出来上がれば完成です。

データのソース元をチェックする

prometheus + node_exporter を起動しているといろいろなデータが取られています。
実際にどのようなデータが取られているかをチェックするには下記にアクセスします。
http://[サーバアドレスまたはIP]:9090/graph

-insert metric at cursor -の部分をクリックすると現在利用できるメトリックが表示されます。
基本的に prometheus_[なんとか] は prometheus 自体がとってきているもの、
node_[なんとか] は node_exporter がとってきているものとなります。

適当に選択して、「Execute」を押すと下のConsoleタブにメトリックが表示されるので、これを grafana 側に貼り付けるだけでグラフ化が可能となっています。

逆を言うとここにない項目は別な exporter を入れるか、influxDB などをデータソースにしてグラフ化する必要があります。

システム情報に関しては、node exporter の node_ がほとんどとってきてくれているので、いろいろなグラフを簡単に作成することが出来ます。

-CentOS, grafana, Linux, prometheus

執筆者:

関連記事

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

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

PHPMyAdminの設置

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

CentOS7にApacheをインストール

CentOS7はnetworkインストールで最小構成だと httpd(Apache)が入りません。しかし、yumコマンドで簡単にインストールすることが出来ます。 インストール yum install …

Intel NUC BOXNUC7PJYHのUnix Bench

Intel NUC BOXNUC7PJYHを購入しました。 BOXNUC7PJYHのスペックは下記の通りとなります。 CPU: Intel Pentium Silver J5005 @ 1.5Ghz( …

CentOS7でローカルIPアドレスを固定する

CentOS7をサーバとして使用していると、ローカルのIPアドレスを固定したいことがあります。セットアップ時にもIPは設定できますが、セットアップ時はDHCPでの払い出しIPでおこない、その後に変更し …


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