「Understanding Metrics in the Age of the TSDB」を読んだ時のメモ



Think for example to the Unix load averages, those three numbers shown in top to give you an idea of how loaded the machine has been in the last minutes. 3.9 3.1 1.2 would tell you, for example, that the machine has been doing 400% for the last 3 to 6 minutes--not 1, not 20.

topコマンドの上に出る3つの数字。あれって直近1分、5分、15分の単純な平均だと思ってたんですけど、指数移動平均(exponentially weighted moving average、EWMA)というやつらしいです。なにそれ?、という話はおいておいて読み進めます。

We'll refer to the terminology of the Metrics Java library, a port of which is the most popular Go metrics library.



  • Gauge: 任意の値(例:CPU負荷)
  • Counter: 単調増加する値(例:エラーの回数)
  • Meter: 割合、頻度(例:エラー率)
  • Histogramヒストグラム


(略)for example the 1-minute EWMA will add up 63% of the rate from the last 60s, plus 37% of the rate since start to 60s ago. The code might be clearer. A graph of a EWMA is slow to change, and probably not what you want unless you really understand what a EWMA shows.



The mean rate instead is as simple as it is useless. It's just total events divided by seconds since start.

どうもここで言っているEWMAは、「moving」と言いつつsliding windowみたいなのはなくて、計測開始からの累計値に対してのEWMAのことを指しているようです(そういうものなの?)。それはたしかに役に立たなそう…。たぶんその方が、どの値がいつ記録されたかとかをいちいち記録しておかなくてすんで省エネなんですね。きっと。


But not all events are discrete, some have values of which we want to keep track. Like, how long it took to serve each HTTP request. This is what the library addresses with a Histogram.

The fundamental concept is that you can't easily visualize all the individual measures, so you have to compute some numeric distribution statistics.


it's reasonably easy to keep a buffer of the last N values, or of the values from the last N seconds, and to store the statistics computed over those.

もちろん、計測し始めからの値にたいして計算するんじゃなくて、sliding window使おうよまじで、と。(でもgo-metricsには用意されていないらしい…)


If performance allows, an alternative approach is to delegate the distribution analysis to an external system. You send all raw measurements (like, one for each HTTP request) to a different system, and that system does the statistics and exports them to the TSDB.