LoginSignup
2
2

More than 5 years have passed since last update.

EC2へSupervisorの監視ツール入れてみた

Last updated at Posted at 2016-02-09

参考URL

インストール

  • py-supervisord-monitorのソースを引っ張るために必要なツール(mercurial)をインストールしていく。
$ sudo vim /etc/yum.repos.d/mercurial.selenic.com.repo
  • 上記ファイルへ下記をコピペ。
[mercurial.selenic.com]
name=mercurial.selenic.com
baseurl=https://www.mercurial-scm.org/release/centos$releasever  ← Amazon Linuxだと、「"The requested URL returned error: 404 Not Found"」が起こるので、「centos6」に直した
enabled=1
# Temporary until we get a serious signing scheme in place,
# check https://www.mercurial-scm.org/wiki/Download again
gpgcheck=0
  • mercurialのインストールして、ツールをダウンロード
$ sudo yum install mercurial
$ hg clone https://symfo@bitbucket.org/symfo/py-supervisord-monitor
  • supervisorのconfigファイルを編集
$ sudo vim /etc/supervisord.conf
  • 下記を設定
[supervisord]
http_port=127.0.0.1:9001  ; (alternately, ip_address:port specifies AF_INET)
[supervisorctl]
serverurl=unix:///var/tmp/supervisor.sock ; use a unix:// URL  for a unix socket
serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
[inet_http_server]
port = 0.0.0.0:9001
  • supervisorの再起動
$ sudo service supervisord status
supervisord (pid  1543) is running...
$ sudo service supervisord restart
Stopping supervisord:                                      [  OK  ]
Starting supervisord:                                      [  OK  ]
$ curl http://localhost:9001
※HTMLがレスポンスされるが、Supervisor2.Xだと、コマンド入力待ちにならない。。。
  • supervisordのアップデート
$ sudo pip install --upgrade pip
Successfully installed pip-8.0.2
$ sudo pip install --upgrade supervisor
Successfully installed meld3-1.0.2 supervisor-3.2.1
$ sudo service supervisord stop
Stopping supervisord:                                      [  OK  ]
$ sudo service supervisord start
Starting supervisord: /usr/lib/python2.6/site-packages/supervisor/options.py:296: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
  'Supervisord is running as root and it is searching '
                                                           [  OK  ]
  • なんか、Warning出てるので、起動スクリプトをエラーにならい、一部変更
$ sudo vim /etc/init.d/supervisord
start() {
        echo -n $"Starting supervisord: "
        daemon supervisord
                      ↓
        daemon supervisord -c /etc/supervisord.conf

$ sudo service supervisord restart
Stopping supervisord:                                      [  OK  ]
Starting supervisord:                                      [  OK  ]
  • 怒られなくなったw
$ curl http://localhost:9001
※HTMLがレスポンスされるが、次のコマンド入力待ちになればOK
  • 次に、監視ツール側のsupervisor.confを修正
$ sudo vim py-supervisord-monitor/supervisor.conf 
[server:server01]
#url = http://192.168.1.101/RPC2
url = http://127.0.0.1/RPC2
port = 9001
#username = user
#password = P@ssw0rd
  • 起動してみる。
$ sudo python index.py 
Bottle v0.13-dev server starting up (using WSGIRefServer())...
Listening on http://0.0.0.0:8080/
Hit Ctrl-C to quit.
$ sudo vim /etc/supervisord.conf
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
  • チェックしてみる。
$ sudo pythonsample.py
{'statename': 'RUNNING', 'statecode': 1}
  • キター!!!!! Py Supervisord Monitor (2).jpg
  • 最後に、ログがうざいので、supervisordで起動するようにする。
$ sudo chmod +x /opt/py-supervisord-monitor/index.py 
$ sudo vim /etc/supervisord.conf 
[program:monitor]
command=/opt/py-supervisord-monitor/index.py
directory=/opt/py-supervisord-monitor
process_name=%(program_name)s
numprocs=1
autostart=true
autorestart=true

$ sudo service supervisord status
supervisord (pid  4168) is running...
$ sudo service supervisord restart
Stopping supervisord:                                      [  OK  ]
Starting supervisord:                                      [  OK  ]

ツールのアップデートは下記でできるらしい。。。

$ cd /opt/py-supervisord-monitor
$ hg pull
$ hg update
2
2
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
2