Skip to content

Instantly share code, notes, and snippets.

@inokappa
Last active October 13, 2017 07:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inokappa/8dd7291ac41333611d20 to your computer and use it in GitHub Desktop.
Save inokappa/8dd7291ac41333611d20 to your computer and use it in GitHub Desktop.
Sensu / Graphite 調査メモ

Graphite

Graphite の基本

アーキテクチャ

  • メトリクスを収集するのが carbon
  • データを保存しておくのが whisper
  • whisper に保存されたメトリクスを表示するのが graphite-web

設定ファイル

  • /etc/carbon/carbon.conf
  • /etc/httpd/conf.d/graphite-web.conf
  • /etc/graphite-web/ 以下

最小構成

  • carbon-cache が利用される

whisper のデータ保存先

/var/lib/carbon/whisper

上記のディレクトリ以下にメトリクスのルートパス毎にディレクトリが生成されている。

各種ログ

各種ログは /var/log/carbon 以下に出力される。

  • listener.log(tcp 接続のログ)
05/06/2014 17:33:09 :: MetricLineReceiver connection with xxx.xxx.xxx.xxx:44789 established
05/06/2014 17:33:09 :: MetricLineReceiver connection with xxx.xxx.xxx.xxx:44789 closed cleanly
  • creates.log(carbon が初めてログを収集して whisper にデータベースを作成した際に出力される)
05/06/2014 22:49:13 :: new metric stats.localhost.cpu.waiting matched schema default_1min_for_1day
05/06/2014 22:49:13 :: new metric stats.localhost.cpu.waiting matched aggregation schema default
05/06/2014 22:49:13 :: creating database file /var/lib/carbon/whisper/stats/localhost/cpu/waiting.wsp (archive=[(60, 1440)]
  • query.log(whisper への接続とクエリーのログ)
05/06/2014 23:03:59 :: 127.0.0.1:51648 connected
05/06/2014 23:04:05 :: 127.0.0.1:51305 disconnected
05/06/2014 23:04:05 :: 127.0.0.1:51649 connected
05/06/2014 23:04:17 :: 127.0.0.1:51661 connected
05/06/2014 23:05:35 :: 127.0.0.1:51301 disconnected
  • console.log

Sensu との連携

一番簡単な連携

事前に必要なプラグインを用意しておく。

cd /etc/sensu/plugins/
wget https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/plugins/system/vmstat-metrics.rb
chmod +x vmstat-metrics.rb
cd /etc/sensu/mutators/
wget https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/mutators/graphite.rb
chmod +x graphite.rb

一番簡単な連携には handler のタイプが tcp を利用する。

cat << EOT > /etc/sensu/conf.d/handler_graphite.json
{
  "handlers": {
    "graphite": {
      "type": "tcp",
      "socket": {
        "host": "127.0.0.1",
        "port": 2003
      },
      "mutator": "mutator_graphite"
    }
  }
}
EOT

また、mutator プラグインを利用して Graphite に保存する為に必要なメトリクスに整形する(しないとメトリクスが保存されなかった)。

cat << EOT > /etc/sensu/conf.d/mutator_graphite.json
{
  "mutators": {
    "mutator_graphite": {
      "command": "/etc/sensu/mutators/graphite.rb"
    }
  }
}
EOT

事前に /etc/sensu/plugins/vmstat-metrics.rb は用意しておいて...メトリクスプラグインの handler に設定するだけ。

cat << EOT > /etc/sensu/conf.d/metrics_vmstat.json
{
  "checks": {
    "vmstat_metrics": {
      "type": "metric",
      "handlers": ["graphite"],
      "command": "/etc/sensu/plugins/vmstat-metrics.rb --scheme stats.:::name:::",
      "interval": 60,
      "subscribers": [ "test" ]
    }
  }
}
EOT

Grafana との連携

Graphite のグラフは正直ダサいので Grafana を使おう。

2014060601.png


Sensu

メトリクスプラグインの出力フォーマット

以下のような Graphite のデータフォーマットが利用されている。

<metric path> <metric value> <metric timestamp>

以下、vmstat-metrics.rb の出力例。vmstat-metrics.rb を直接実行すると以下のように出力される。

9b8d3c9bd69f.vmstat.cpu.user    3       1402005112
9b8d3c9bd69f.vmstat.cpu.system  1       1402005112
9b8d3c9bd69f.vmstat.cpu.idle    96      1402005112
9b8d3c9bd69f.vmstat.cpu.waiting 0       1402005112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment