zuntan02のはてなブログ

備忘録的なものです。時々職場の技術者ブログにも転記してますが、メインはこちらで。

AWSユーザのためのNew Relicによるサーバ監視

【内容サマリ】

AWSユーザならNew Relicは使う価値あり。無料枠でもかなり楽しい。

【前提】

・AmazonLinuxを使っている人
・監視対象は、システムモニターの他にPHPMySQL(RDS)

【導入手順参考】

AWSユーザなら無料で使えるNew Relic導入方法

AWSユーザなら無料で使えるNew Relic導入方法 - Qiita
(例によってほぼそのまま)



AWS Monitoring with New Relic | AWS Monitoring | New Relic | New Relic Partner
f:id:zuntan02:20150130215331p:plain
[Sign up for New Relic]
”このページ経由でSign-UPするとStandard版が無料で使えます。”
無料でここまでできるのはホントスゴイ。


以下は適当に設定。この時Email AddressにAWSのアカウント名を入れると良い?

Your Name: hoge fuga
Your Phone Number:81-xxx-xxxx-xxxx
Your Email Address:hoge@fuga.hoge
Your New Relic Password:xxxxx
Select Your Country:Japan
Select Your Role:任意
Your Company:hogefuga Inc.
以下適当

上記アカウントにてNewRelicにログイン
f:id:zuntan02:20150130215314p:plain
[右上のアカウント名]-[Account Settings]から40文字のLicense keyをゲット
このライセンスキーを使って監視サーバに監視ツールを導入していきます。

■システムモニターをインストール

# New Relic のyumリポジトリを追加
# 32bit
rpm -Uvh http://download.newrelic.com/pub/newrelic/el5/i386/newrelic-repo-5-3.noarch.rpm
# 64bit
rpm -Uvh https://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm

上記のどっちかをOSに合わせて実施。

# エージェント(クライアント)をインストール
yum install newrelic-sysmond
# Installed:
# newrelic-sysmond.x86_64 0:1.4.0.471-1

# ライセンスキー設定
nrsysmond-config --set license_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# デーモン開始
service newrelic-sysmond start

# 自動起動
chkconfig --list newrelic-sysmond
# newrelic-sysmond 0:off 1:off 2:on 3:on 4:on 5:on 6:off

# 設定確認
cat /etc/newrelic/nrsysmond.cfg

# ログ確認
tail -f /var/log/newrelic/nrsysmond.log

■New Relic PHP をインストール

yum -y install newrelic-php5

newrelic-install install
→対話インストール開始。
 Enter New Relic license key (or leave blank): にライセンスキーをいれるのみ。

# 設定ファイルをコピー
cp -p /etc/newrelic/newrelic.cfg.template /etc/newrelic/newrelic.cfg

# newrelic.iniにアプリ名を追加
vi /etc/php-5.5.d/newrelic.ini
# - newrelic.appname
がNewRelicの監視画面に出る名前になるので適当に直しておく。



# 自動起動を設定
chkconfig newrelic-daemon on
chkconfig --list newrelic-daemon
# newrelic-daemon 0:off 1:off 2:on 3:on 4:on 5:on 6:off

# 再起動
service newrelic-daemon restart
# Stopping New Relic Daemon (newrelic-daemon) ... [ OK ]
# Starting newrelic-daemon: [ OK ]

■New Relic MySQL pluginをインストール

1)必要モジュールの確認と不足分追加

http://newrelic.com/plugins/new-relic-inc/52
To use this plugin, you must have:
a Java Runtime Environment (JRE) of 1.6 or higher
at least one database to monitor (MySQL 5.0 or higher)
a New Relic account

2) MySQLに接続確認、および監視用アカウントの作成

mysql -uroot -A -p
mysql> CREATE USER newrelic@'%' IDENTIFIED BY 'hogehoge';
mysql> GRANT PROCESS,REPLICATION CLIENT ON *.* TO newrelic@'%';
\q

3) New Relic Platform Installer(NPI) を使用して導入していく

mkdir /home/newrelic/newrelic-npi
PREFIX=/home/newrelic/newrelic-npi LICENSE_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx bash -c "$(curl -sSL https://download.newrelic.com/npi/release/install-npi-linux-redhat-x64.sh)"

# Are you sure you want to continue? (y/n) y
(中略)
# Successfully setup the New Relic Platform Installer!

cd /home/newrelic/newrelic-npi
./npi available で利用可能なnpiを確認できます。色々見れそう!

# mysql用のモジュールをインストール
./npi install nrmysql

対話インストールは基本的に全てyでOK
対話インストール中に編集するplugin.jsonファイルは以下の内容で。

{
"agents": [
{
"name" : "Localhost", →監視画面の表示に使う表示名
"host" : "localhost", →監視対象のサーバ名
"metrics" : "status,newrelic",
"user" : "USER_NAME_HERE", →監視用のデータベース接続ユーザ名
"passwd" : "USER_PASSWD_HERE" →監視用ユーザのパスワード
}
]
}

4) 自動起動確認

chkconfig --list
# newrelic_plugin_com.newrelic.plugins.mysql.instance 0:off 1:off 2:on 3:on 4:on 5:on 6:off


■このほかにもAWSのCloudWatchを取得するプラグインもあってRDSとかELBとか取れる。
zuntan02.hateblo.jp

以上。

■追記
yum updateで更新したらPHPの情報が出なくなった。
newrelic-install install
で再度設定しなおしたら復旧した

メモまで。