LoginSignup
2
4

More than 5 years have passed since last update.

IBM Cloud 仮想サーバーを IBM Cloud Monitoring で監視する

Last updated at Posted at 2018-07-13

目的

タイトルの通り、IBM Cloud の PaaS にある Monitoring サービスを使って、IaaS の仮想サーバーを監視します。

Sending and retrieving data
Kobito.3hcNu1.png

2018年7月現在、Windows はサポートされていないので、Linux で試します。
「collectd」というオープンソースのエージェントを導入して、データを送って、「Grafana」というダッシュボードサービスからグラフを確認します。

Kobito.UhE6Sm.png

IBM Cloud Monitoring を注文する

まずは Catalog - IBM Cloud から Monitoring サービスを注文します。

Kobito.IDTPdy.png

今回のケースでは、有料の Premium Plan を使う必要があり、それを注文します。
以下のような価格体系になっているので、比較的使いやすいのかなと思います。

  • $2.00 USD/Million data points ingested per month
  • $0.10 USD/Single metric alerting rules per month

Kobito.2W2Uc8.png

参考:Lite と Premium Plan の違い

Service plans

Kobito.zEPSoI.png

参考:Lite Plan で進めると

ちなみに無料の Lite Plan でやろうとすると、以下のエラーが出て怒られました。

[ERROR] IBMCM plugin: client.go:424: Failed acknowledge due to error in metrics. Ignoring compressed pack. Sequence: 0. BXNMSMG02E: Metrics can only be accepted on a paid plan

IBM Cloud 仮想サーバーに設定する

こちらを参考に進めます。

Sending data by using the Monitoring plugin (collectd)

Kobito.85P2br.png

Firewall の設定

以下のエンドポイントに対して、監視データを送信できるようにしておきましょう。

Sending and retrieving data

Region URL collectd port
Germany https://metrics.eu-de.bluemix.net 9095
Sydney https://metrics.au-syd.bluemix.net 9095
United Kingdom https://metrics.eu-gb.bluemix.net 9095
US South https://metrics.ng.bluemix.net 9095

設定の確認

こちらの OS を使います。

cat /etc/redhat-release

CentOS Linux release 7.5.1804 (Core) 

NTP の設定を確認して、「NTP synchronized: no」と設定されていなければ、時刻同期の設定をおこないます。

timedatectl status

      Local time: Thu 2018-07-12 03:27:53 CDT
  Universal time: Thu 2018-07-12 08:27:53 UTC
        RTC time: Thu 2018-07-12 08:27:53
       Time zone: America/Chicago (CDT, -0500)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2018-03-11 01:59:59 CST
                  Sun 2018-03-11 03:00:00 CDT
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2018-11-04 01:59:59 CDT
                  Sun 2018-11-04 01:00:00 CST

時刻同期の設定

必要なモジュールのインストール・最新化をおこないます。

yum update -y
yum install chrony -y
yum install ntpdate -y
systemctl stop chronyd

CentOS7 からは ntp ではなく chrony を使用するのが推奨のようなので、その設定をします。

head /etc/chrony.conf -n 3

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server time.service.softlayer.com iburst

事前に手動で時刻同期をおこなっておきます。

ntpdate -u time.service.softlayer.com

12 Jul 03:34:21 ntpdate[13446]: adjust time server 10.0.77.54 offset 0.137563 sec

サービスを開始します。

systemctl start chronyd
systemctl enable chronyd

時刻同期が有効になったのを確認します。

timedatectl status

      Local time: Thu 2018-07-12 03:47:44 CDT
  Universal time: Thu 2018-07-12 08:47:44 UTC
        RTC time: Thu 2018-07-12 08:47:44
       Time zone: America/Chicago (CDT, -0500)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2018-03-11 01:59:59 CST
                  Sun 2018-03-11 03:00:00 CDT
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2018-11-04 01:59:59 CDT
                  Sun 2018-11-04 01:00:00 CST

Monitoring サービスへの接続情報取得

IBM Cloud CLI を使って事前に接続情報を取得します。
新規インストールは Installing the stand-alone IBM Cloud CLI からどうぞ。

ibmcloud --version

ibmcloud version 0.7.1+8a6d40e-2018-06-07T07:13:39+00:00

Monitoring サービス用の API Key を発行して、変数として定義します。

bx iam api-key-create ibmcloud-monitoring-key -d "ibmcloud-monitoring-key"

export APIKEY="kjshdgf...ldkdjdj"

Monitoring サービスのエンドポイントを、変数として定義します。

export METRIC_ENDPOINT="metrics.au-syd.bluemix.net"

スペース ID を取得して、変数として定義します。

bx iam space Sydney --guid

32247b60-827f-4e8a-b4e9-8918d77073ad

export SpaceID="32247b60-827f-4e8a-b4e9-8918d77073ad"

Monitoring エージェント (collectd) の導入

必要なモジュールのインストールをおこないます。

yum install epel-release -y
yum install collectd -y
wget -O - https://downloads.opvis.bluemix.net/client/IBM_Logmet_repo_install.sh | bash
yum install ibmcloud-monitoring -y

Monitoring サービス用の設定作成コマンドを CentOS7 で実行するとエラーになります。

/opt/ibmcloud_monitoring/configure -e $METRIC_ENDPOINT -a $APIKEY -s s-$SpaceID

Collectd configuration file '/etc/collectd/collectd.conf' does not exist

原因は、collectd の設定ファイル格納場所が以下で異なるからです。

  • CentOS --- /etc/collectd.conf
  • Ubuntu --- /etc/collectd/collectd.conf

気を取り直して、「-d /etc」のオプションをつけて再度実行します。

/opt/ibmcloud_monitoring/configure -e $METRIC_ENDPOINT -a $APIKEY -s s-$SpaceID -d /etc

Successfully configured IBM Cloud Monitoring Plugin for collectd at /etc/ibmcloud-monitoring.conf

Monitoring サービス用の設定が追加されたことを確認します。

tail /etc/collectd.conf -n 1

Include "/etc/ibmcloud-monitoring.conf"

今回は CPU 使用率をみるために、一部設定を変更します。

vi /etc/collectd.conf 

#CPU時間情報を取得
LoadPlugin cpu

#CPU使用率として取得
<Plugin cpu>
  ReportByCpu true
  ReportByState true
  ValuesPercentage true
</Plugin>

サービスを再起動します。

systemctl restart collectd

以下のようなサービスログがみえていれば問題ありません。

systemctl status collectd -l

● collectd.service - Collectd statistics daemon
   Loaded: loaded (/usr/lib/systemd/system/collectd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2018-07-12 04:52:16 CDT; 29s ago
     Docs: man:collectd(1)
           man:collectd.conf(5)
 Main PID: 25561 (collectd)
   CGroup: /system.slice/collectd.service
           └─25561 /usr/sbin/collectd

Jul 12 04:52:16 khayama-collectd.ibmcloud.com collectd[25561]: [INFO] IBMCM plugin:Fetching Configuration for IBMCloudMonitoring plugin
Jul 12 04:52:16 khayama-collectd.ibmcloud.com collectd[25561]: plugin_load: plugin "IBMCloudMonitoring" successfully loaded.
Jul 12 04:52:16 khayama-collectd.ibmcloud.com systemd[1]: Started Collectd statistics daemon.
Jul 12 04:52:16 khayama-collectd.ibmcloud.com collectd[25561]: Systemd detected, trying to signal readyness.
Jul 12 04:52:16 khayama-collectd.ibmcloud.com collectd[25561]: [INFO] IBMCM plugin:Successfully validated configuration.
Jul 12 04:52:16 khayama-collectd.ibmcloud.com collectd[25561]: Initialization complete, entering read-loop.
Jul 12 04:52:16 khayama-collectd.ibmcloud.com collectd[25561]: configfile: Cannot get unknown global option `Flushinterval'.
Jul 12 04:52:16 khayama-collectd.ibmcloud.com collectd[25561]: [INFO] IBMCM plugin:Found Flushinterval = 64424509440
Jul 12 04:52:16 khayama-collectd.ibmcloud.com collectd[25561]: [INFO] IBMCM plugin:==========Configuration======
                                                               Name: au-syd
                                                               Server: metrics.au-syd.bluemix.net:9095
                                                               Scope ID: s-32247b60-827f-4e8a-b4e9-8918d77073ad
                                                               Prefix: .
                                                               Postfix: .
                                                               Apikey: *******
                                                               Version: 3
                                                               Buffer Size: 1000
                                                               Interval: 60sec
                                                               SkipInternalPrefixForStatsd: false
                                                               RateCounter: false
                                                               MaxConnections: 10
                                                               Escapechar: _
                                                               SeparateInstances: false
                                                               Debug: false
                                                               Trace Metrics: false
Jul 12 04:52:16 khayama-collectd.ibmcloud.com collectd[25561]: [INFO] IBMCM plugin:Successfully registered writer - IBMCloudMonitoring
systemctl status collectd -l

● collectd.service - Collectd statistics daemon
   Loaded: loaded (/usr/lib/systemd/system/collectd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2018-07-12 04:52:16 CDT; 2min 42s ago
     Docs: man:collectd(1)
           man:collectd.conf(5)
 Main PID: 25561 (collectd)
   CGroup: /system.slice/collectd.service
           └─25561 /usr/sbin/collectd

Jul 12 04:52:16 khayama-collectd.ibmcloud.com collectd[25561]: [INFO] IBMCM plugin:==========Configuration======
                                                               Name: au-syd
                                                               Server: metrics.au-syd.bluemix.net:9095
                                                               Scope ID: s-32247b60-827f-4e8a-b4e9-8918d77073ad
                                                               Prefix: .
                                                               Postfix: .
                                                               Apikey: *******
                                                               Version: 3
                                                               Buffer Size: 1000
                                                               Interval: 60sec
                                                               SkipInternalPrefixForStatsd: false
                                                               RateCounter: false
                                                               MaxConnections: 10
                                                               Escapechar: _
                                                               SeparateInstances: false
                                                               Debug: false
                                                               Trace Metrics: false
Jul 12 04:52:16 khayama-collectd.ibmcloud.com collectd[25561]: [INFO] IBMCM plugin:Successfully registered writer - IBMCloudMonitoring
Jul 12 04:53:16 khayama-collectd.ibmcloud.com collectd[25561]: [WARN] IBMCM plugin:client.go:334: Sending 181 metrics in Buffer.
Jul 12 04:53:16 khayama-collectd.ibmcloud.com collectd[25561]: [NOTICE] IBMCM plugin:client.go:490: Connecting to metrics.au-syd.bluemix.net:9095
Jul 12 04:53:16 khayama-collectd.ibmcloud.com collectd[25561]: [NOTICE] IBMCM plugin:client.go:573: Successfully established a connection with metrics.au-syd.bluemix.net
Jul 12 04:53:16 khayama-collectd.ibmcloud.com collectd[25561]: [NOTICE] IBMCM plugin:client.go:435: Successfully wrote 181 metrics to the socket.
Jul 12 04:54:16 khayama-collectd.ibmcloud.com collectd[25561]: [WARN] IBMCM plugin:client.go:334: Sending 162 metrics in Buffer.
Jul 12 04:54:16 khayama-collectd.ibmcloud.com collectd[25561]: [NOTICE] IBMCM plugin:client.go:490: Connecting to metrics.au-syd.bluemix.net:9095
Jul 12 04:54:16 khayama-collectd.ibmcloud.com collectd[25561]: [NOTICE] IBMCM plugin:client.go:573: Successfully established a connection with metrics.au-syd.bluemix.net
Jul 12 04:54:16 khayama-collectd.ibmcloud.com collectd[25561]: [NOTICE] IBMCM plugin:client.go:435: Successfully wrote 162 metrics to the socket.

Grafana ダッシュボードの確認

取得したデータをダッシュボードから確認します。

IBM Cloud Monitoring : https://metrics.au-syd.bluemix.net/app/#/grafana4

Kobito.m6Fjuk.png

新規にダッシュボードを作成します。

Kobito.qwphki.png

グラフ作成を選択します。

Kobito.7e6svX.png

グラフタイトルから「edit」を選び、メトリクスから CPU 使用率を表示できます。

Kobito.QoMH5k.png

細かくみると、1分ごとにデータが送られていることがわかります。

Kobito.gkSGsk.png

さいごに

IBM Cloud Monitoring は、仮想サーバーと同時に、コンテナや PaaS アプリの監視を一元的にできるところが特徴です。
システムの監視サービスに何を使うかを迷う方もいると思いますが、今回のように PaaS で提供されている安定したサービス基盤に対して、API Key ベースの連携でデータを一元的に監視できる、というのは1つの選択肢になるのではと思います。

2
4
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
2
4