Prometheusのストレージ
Prometheusのストレージ周りに関してちょっと調べたのでメモっておく。
間違っているところや補足すべきものがあれば教えてもらえると嬉しいです。
公式ドキュメントはこちら
https://prometheus.io/docs/operating/storage
他に参考になりそうな資料としてはこの辺
https://promcon.io/2016-berlin/talks/the-prometheus-time-series-database
簡単に説明するとchunkという1024bytesの固定長データをもとに処理しておりインデックスはLevelDBに保持している。
メモリにデータを保持して高速化をはかりつつ予期せぬ停止によるデータロストを最小限にするため定期的にディスクに書き出している。HBaseのようにWALを持っているわけではなさそうなのでデータロストはありそう。
storage.local.memory-chunksというのが何個のchunkをメモリに保持するかのパラメータでデフォルトは1048576(1024*1024)である。chunkが1024 bytesなので1024**1024*1024つまり1GBのメモリがmaxの使用量となっている。
英語の説明はこちら
How many chunks to keep in memory. While the size of a chunk is 1kiB, the total memory usage will be significantly higher than this value * 1kiB. Furthermore, for various reasons, more chunks might have to be kept in memory temporarily. Sample ingestion will be throttled if the configured value is exceeded by more than 10%.
storage.local.max-chunks-to-persistの英語の説明はこちら
How many chunks can be waiting for persistence before sample ingestion will be throttled. Many chunks waiting to be persisted will increase the checkpoint size.
まだディスクに書き込んでなくてメモリに保持しているchunkの数がこれを超えるとスロットルされるのでデータが書き込まれない。
デファルトが512*1024でstorage.local.memory-chunksの50%になっている。
storage.local.memory-chunksだけ増やしてstorage.local.max-chunks-to-persistがそのままだとスロットルされてしまうのでstorage.local.max-chunks-to-persist/storage.local.memory-chunksが0.5になるように設定しましょう。
storage.local.retentionはディスク保持期間でデフォルトは15日。
これを増やした場合、1ヶ月以上にした場合はstorage.local.series-file-shrink-ratioも増やす方がよい。
storage.local.series-file-shrink-ratioはデファルト0.1で、Prometheusがディスクに書き込んだファイルの10%を削除する必要があったらファイルを全書き換えする実装になっているが、ファイルサイズが大きい場合は0.3とかにする方が良い。
Prometheus自身のメトリクスをGrafanaで表示するためには以下のダッシュボードを参考にするといい。
How To Add a Prometheus Dashboard to Grafana | DigitalOcean