「入門監視」からStatsDの話

Etsyはハンドメイドのクラフトを売買するプラットフォーム。そのEtsyが自社の監視用に作ったStatsdも「入門監視」で詳しく取り上げられている。

A network daemon that runs on the Node.js platform and listens for statistics, like counters and timers, sent over UDP or TCP and sends aggregates to one or more pluggable backend services (e.g., Graphite).

昨日に取り上げたGraphiteなどのバックエンドと一緒に動くデーモンだ。Unixコマンドが分かる人には下記のコマンドで何をするデーモンかわかるだろうか。

echo "foo:1|c" | nc -u -w0 127.0.0.1 8125

Github上からもリンクが貼られ、「入門監視」でも紹介されているEtsyによるブログがこちら。

If Engineering at Etsy has a religion, it’s the Church of Graphs. If it moves, we track it. Sometimes we’ll draw a graph of something that isn’t moving yet, just in case it decides to make a run for it. In general, we tend to measure at three levels: network, machine, and application.

もし信仰があるなら、それはグラフ教会だというユニークな書き出しから始まる。

Here’s how we do it using our PHP StatsD library:
StatsD::increment("grue.dinners");
That’s it. That line of code will create a new counter on the fly and increment it every time it’s executed. You can then go look at your graph and bask in the awesomeness, or for that matter, spot someone up to no good in the middle of the night:

PHPのライブラリで"grue.dinners"という文字列を送るコードを挿入するだけでStatsdが受信し、graphiteがグラフにしてくれる。

In addition to plain counters, we can track times too:
$start = microtime(true);
eat_adventurer();
StatsD::timing("grue.dinners", (microtime(true) - $start) * 1000);
StatsD automatically tracks the count, mean, maximum, minimum, and 90th percentile times (which is a good measure of “normal” maximum values, ignoring outliers). Here, we’re measuring the execution times of part of our search infrastructure:

関数の実行時間を送るとStatsDが合計値、平均値に加え90%値なども出してくれる。

これまでだったらシスログに出力し、それを集計する手間があったものを、そういう手間などを考えずに送って可視化できるわけだ。こういった仕組みを持っているかどうかで、システムのチューニングに差が付き、ビジネススピードに差が付くのだと思う。





この記事が気に入ったらサポートをしてみませんか?