6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PrometheusでApache監視(apache_exporter)

Last updated at Posted at 2017-03-12

まえがき

prometheus でnode_export を設定しても、サーバってそんなもんじゃない。
上で動いているものを監視しなくちゃ!ってことで、今回はapache_exporterについて記載します。

Dockerホスト上で叩くコマンドは、#
Dockerコンテナ上で叩くコマンドは、## とします。
※場所によって、ファイル内のコメントが# と記載されています。

・jecnua/apache-exporter でコンテナ起動する方法を試してみましたが、どうも動かない・・・。
ので、今回投稿したやり方で監視してみます。

環境

Azure 上で構築した仮想マシン(VM)にDokerを入れてます。
・Dockerホスト:CentOS7.3
・コンテナ:CentOS latest イメージを利用
・監視用コンテナ:prometheusを導入
・監視対象となるサーバ:Apache が動いているコンテナ

準備

監視対象となるApache が動いているコンテナにGo言語をインストールします。

<Apache稼働コンテナ>
## yum -y install golang git                  ★ インストール!

## export GOPATH=$HOME/go                     
## export PATH=$PATH:$GOROOT/bin:$GOPATH/bin  

apache_exporter インストール

github からインストールします。

<Apache稼働コンテナ>
## go get github.com/neezgee/apache_exporter     ★ 何も出力はありません。環境変数GOPATHにインストールされます。
## mv $HOME/go /usr/local/src/.                  ★ これは好き好きです。実施しなくてもいいです。
## ln -fs /usr/local/src/go/bin/apache_exporter /usr/bin   

自動起動設定

Apacheが起動されているコンテナ上で、apache_exporterが起動するようにしましょう。

<Apache稼働コンテナ>
## vi /usr/lib/systemd/system/apache_exporter.service
[Unit]
Description=Apache Exporter

[Service]
Type=simple
ExecStart=/usr/local/src/go/bin/apache_exporter
PrivateTmp=false

[Install]
WantedBy=multi-user.target


## systemctl enable apache_exporter.service          ★ 登録!
Created symlink from /etc/systemd/system/multi-user.target.wants/apache_exporter.service to /usr/lib/systemd/system/apache_exporter.service.

## systemctl start apache_exporter

alertルールに登録

<prometheus導入コンテナ>
## vi /etc/prometheus/alert.rules       ★ ルールファイルは、それぞれの環境で読み替えてください。
(略)
ALERT httpd_down                        ★ 丸っとコピーして追記ください。
  IF apache_up == 0
  ANNOTATIONS {
    summary = "Apache Daemon {{ $labels.instance }} down",
    description = "Apache Daemon is dead.",                  ★ 文字列は好きな文字列に変更ください。
  }
(略)


## systemctl restart alertmanager      ★ 一応、Alertmanager を再起動

prometheusに登録

prometheus(サーバ側)の監視設定にjobを追加します。

<prometheus導入コンテナ>
## vi /etc/prometheus/prometheus.yml

(略)
scrape_configs:
  - job_name: 'apache'
    scrape_interval: 5s
    static_configs:
    - targets: ['<Apache導入コンテナのIP or URL>:9117']
(略)

## systemctl restart prometheus         ★ prometheus を再起動

最後に

ちゃんとcommitして、9117ポートを開けておきましょ。

<Apache稼働コンテナ>
## exit

<Apache起動コンテナのDockerホスト>
# docker commit <コンテナ名> <イメージ名>          ★ ちゃんとcommit しておきましょう。
# docker stop <コンテナ名>
# docker rm <コンテナ名>
# docker run --privileged --name <コンテナ名> -dt -v <DockerホストDir>:<コンテナDir> -p 80:80 -p 9117:9117 <イメージ名> /sbin/init

参考サイト

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?