2015年1月6日火曜日

New RelicでMemcachedを監視する

http://www.flickr.com/photos/24293932@N00/2949281301


New RelicのMemcached監視プラグインです。
キャッシュの状態やコネクション数にとどまらず、CPU使用率など、かなり広範囲の監視をカバーしています。


以下、セットアップ方法です。


必須ライブラリをインストール。
# yum -y install java glibc.i686 libstdc++ libstdc++.so.6

New Relic Platform Installer (NPI)をインストール。
# LICENSE_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxx bash -c "$(curl -sSL https://download.newrelic.com/npi/release/install-npi-linux-redhat-x86.sh)"

You are about to download the New Relic Platform Installer v0.1.5.
This will download the 'npi' tool from the following URL: https://download.newrelic.com/npi/v0.1.5/platform_installer-linux-x86-v0.1.5.tar.gz
It will place the tool at '/root/newrelic-npi'.  It will not affect your path or global settings.

Are you sure you want to continue? (y/n) y
Setting default configurations
  user -> root
  license_key -> xxxxxxxxxxxxxxxxxxxxxxxxxxx
  distro -> redhat
Successfully setup the New Relic Platform Installer!

Next steps:
  - Navigate to the directory: '/root/newrelic-npi'
  - Run './npi available' to get a list of available plugins
  - Run './npi install ' to download, configure and start a plugin
  - For additional help run the following './npi --help'

ディレクトリ移動。
# cd /root/newrelic-npi

インストール可能なNew Relicプラグインの一覧を表示
# ./npi available
Available NPI compatible plugins on New Relic:
  ar.com.3legs.newrelic.cassandra (2.0.0)                      Java
  ar.com.3legs.newrelic.jmxremote (2.0.0)                      Java
  ar.com.3legs.newrelic.varnish (2.0.0)                        Java
  nrwikipedia_dotnet -> com.newrelic.dotnet.wikipedia (1.0.0)  .NET
  nrwikipedia_java -> com.newrelic.examples.wikipedia (1.0.8)  Java
  nrmssql -> com.newrelic.platform.microsoft.sqlserver (2.0.1) .NET
  nrmemcached -> com.newrelic.plugins.memcached (2.0.1)        Java
  nrmysql -> com.newrelic.plugins.mysql.instance (2.0.0)       Java
  com.rekko.newrelic.storm.kafka (1.0.0)                       Java
  com.sparkred.EndecaPlugin (0.1)                              Java
  com.sparkred.plugins.oracle.db (1.0.0)                       Java

Memcachedプラグインをインストール。質問には基本的に y と入力していけばOKです。
# ./npi install com.newrelic.plugins.memcached
Enter your New Relic license key (xxxxxxxxxxxxxxxxxxxxxxxxxxx): 
[13:22:30] [INFO] operations - Using license key: xxxxxxxxxxxxxxxxxxxxxxxxxxx
[13:22:30] [INFO] operations - Fetching the plugin to your file system...
You are about to download the following plugin:
- com.newrelic.plugins.memcached:
  - Details:
      download_url           https://github.com/newrelic-platform/newrelic_memcached_java_plugin/raw/master/dist/newrelic_memcached_plugin-2.0.1.tar.gz
      implementation         Java
      publisher_name         New Relic Inc.
      publisher_support_url  http://newrelic.com/support
      version                2.0.1

Are you sure you want to continue? (y/n): y
[13:22:35] [INFO] platform_helpers - Downloading compressed archive for 'com.newrelic.plugins.memcached'...
[13:22:37] [INFO] platform_helpers - Extracting archive for 'com.newrelic.plugins.memcached'...

Current state for the plugin: com.newrelic.plugins.memcached
- com.newrelic.plugins.memcached:
  - State:
      Downloaded   [x]
      Prepared     [ ]
      Installed    [ ]
      Running      [ ]

[13:22:37] [INFO] operations - Configuring the plugin to run...
[13:22:37] [INFO] operations - Generating 'newrelic.json' file for plugin...
Configure the plugin in a text editor before continuing? (y/n): y
{
  "agents": [
    {
      "name" : "[ホスト名を入力]",
      "host" : "localhost",
      "port" : 11211
    }
  ]
}

Current state for the plugin: com.newrelic.plugins.memcached
- com.newrelic.plugins.memcached:
  - State:
      Downloaded   [x]
      Prepared     [x]
      Installed    [ ]
      Running      [ ]

[13:22:52] [INFO] operations - Setting the plugin as a background process...
Do you want to set this plugin as a background process? (y/n): y
[13:22:59] [INFO] platform_helpers - Writing service script to: /etc/init.d/newrelic_plugin_com.newrelic.plugins.memcached...
[13:22:59] [INFO] platform_helpers - Changing permissions on service script to 0755...
[13:22:59] [INFO] platform_helpers - Running 'chkconfig' with arguments: ["--add","newrelic_plugin_com.newrelic.plugins.memcached"]
[13:22:59] [INFO] platform_helpers - Received '--start' flag, attempting to start the background service.
Starting newrelic_plugin_com.newrelic.plugins.memcached
Successfully added background service for 'com.newrelic.plugins.memcached'!

Next steps:
  Start plugin in the background:     npi start com.newrelic.plugins.memcached
[13:22:59] [INFO] operations - Plugin 'com.newrelic.plugins.memcached' has been successfully setup on your machine.  Run 'npi list com.newrelic.plugins.memcached' to see more information

Current state for the plugin: com.newrelic.plugins.memcached
- com.newrelic.plugins.memcached:
  - State:
      Downloaded   [x]
      Prepared     [x]
      Installed    [x]
      Running      [x]

Runningに [x] が付いていれば、Memcachedプラグインが立ち上がっています。

Memcachedプラグインのプロセスを確認。
# ps auxf | grep ewrelic_memcached_plugin | grep -v grep
root      6931  0.0  0.2  90464  2768 pts/0    S    13:26   0:00 sudo -u root java -Xmx128m -Dnewrelic.platform.config.dir=/root/newrelic-npi/plugins/com.newrelic.plugins.memcached/newrelic_memcached_plugin-2.0.1/config -jar /root/newrelic-npi/plugins/com.newrelic.plugins.memcached/newrelic_memcached_plugin-2.0.1/plugin.jar
root      6932  2.0  4.6 965852 47828 pts/0    Sl   13:26   0:01  \_ java -Xmx128m -Dnewrelic.platform.config.dir=/root/newrelic-npi/plugins/com.newrelic.plugins.memcached/newrelic_memcached_plugin-2.0.1/config -jar /root/newrelic-npi/plugins/com.newrelic.plugins.memcached/newrelic_memcached_plugin-2.0.1/plugin.jar

ログを確認します。
# tail -f /root/newrelic-npi/plugins/com.newrelic.plugins.memcached/newrelic_memcached_plugin-2.0.1/daemon.log

New Relicにログインして確認しましょう。
ダッシュボード -> PLUGINS -> Memcached

Memcachedプラグインのプロセスをストップ・スタートするには、serviceコマンドから可能です。
# service newrelic_plugin_com.newrelic.plugins.memcached stop/start

Enjoy!