prometheusのログ保存期間を伸ばす延ばす長くする

習慣化169日目

prometheusのログ保存期間について

Prometheusはデフォルトの設定では取得したデータを 360時間(15日間) しか保存しないならしい。
これをすぎたデータは自動的に破棄される。
ちょっと短すぎるので下記対応を検討したい。

  • 保存期間を延ばす(1年とか)
  • node_exporterで不要なものは取得しないようにする
  • influxDBに書き込むようにする

promethesのログ保存期間を延ばす

こういうデータはあまり長くしないのが一般的らしいが、延ばしてしまう。

Prometheusでのさまざまな監視データ取得法 | さくらのナレッジ
https://knowledge.sakura.ad.jp/12057/
→Prometheus Serverのストレージ関連設定

promethesプロセスを確認

[root@centos6 prometheus-2.22.1.linux-amd64]# ps aux |grep prome
root       307  0.0  0.0 103336   916 pts/2    S+   09:16   0:00 grep prome
root      2827  0.1  0.7 717576 31596 ?        Sl   Nov13   4:06 node_exporter --collector.textfile.directory /root/prometheus/textfilecollector
root     27459  0.0  1.7 1115916 69764 ?       Sl   Nov11   4:23 ./prometheus --config.file=prometheus.yml

promethesプロセスを一旦killする

[root@centos6 prometheus-2.22.1.linux-amd64]# kill 27459
[root@centos6 prometheus-2.22.1.linux-amd64]# ps aux |grep prome
root       322  0.0  0.0 103336   916 pts/2    S+   09:18   0:00 grep prome
root      2827  0.1  0.7 717576 29500 ?        Sl   Nov13   4:06 node_exporter --collector.textfile.directory /root/prometheus/textfilecollector
[root@centos6 prometheus-2.22.1.linux-amd64]#

オプションを付けてPrometheusを起動する

[root@centos6 prometheus-2.22.1.linux-amd64]# /usr/local/src/prometheus-2.22.1.linux-amd64/prometheus --config.file=prometheus.yml --storage.tsdb.retention 365d &

これで365日間はログが保存される。

プロセスを確認する

[root@centos6 prometheus-2.22.1.linux-amd64]# ps aux |grep prome
root       383  1.1  1.3 786308 53708 pts/2    Sl   09:21   0:01 /usr/local/src/prometheus-2.22.1.linux-amd64/prometheus --config.file=prometheus.yml --storage.tsdb.retention 365d
root       410  0.0  0.0 103336   916 pts/2    S+   09:23   0:00 grep prome
root      2827  0.1  0.7 717576 29500 ?        Sl   Nov13   4:06 node_exporter --collector.textfile.directory /root/prometheus/textfilecollector
[root@centos6 prometheus-2.22.1.linux-amd64]#

node_exporterで不要なものは取得しないようにする

ログの保存期間を長くした分、ディスク容量を使い切ってしまうのが心配だった。
不要なデータは取得しないようにしておく。

node_exporterはTextfile Collectorでの値くらいしか見てないので、それ以外は取得しなくてOK。

prometheusのnode_exporterの監視項目と設定例 - Qiita
https://qiita.com/kanga/items/21acb042237f8a27f437
→取得している内容がリスト化されている。分かりやすい。

GitHub - prometheus/node_exporter: Exporter for machine metrics
https://github.com/prometheus/node_exporter
→node_exporterのマニュアル

起動中の node_exporter を確認してkillする

[root@centos6 prometheus-2.22.1.linux-amd64]# ps aux | grep node_
root       666  0.0  0.0 103336   916 pts/2    S+   09:42   0:00 grep node_
root      2827  0.1  0.7 717576 30276 ?        Sl   Nov13   4:08 node_exporter --collector.textfile.directory /root/prometheus/textfilecollector
[root@centos6 prometheus-2.22.1.linux-amd64]#
[root@centos6 prometheus-2.22.1.linux-amd64]# kill 2827
[root@centos6 prometheus-2.22.1.linux-amd64]# ps aux | grep node_
root       678  0.0  0.0 103336   916 pts/2    S+   09:43   0:00 grep node_
[root@centos6 prometheus-2.22.1.linux-amd64]#

オプションを指定して起動する

node_exporter  --no-collector.arp --no-collector.bcache --no-collector.bonding --no-collector.conntrack --no-collector.cpu --no-collector.cpufreq --no-collector.diskstats --no-collector.edac --no-collector.entropy --no-collector.filefd --no-collector.filesystem --no-collector.hwmon --no-collector.infiniband --no-collector.ipvs --no-collector.loadavg --no-collector.mdadm --no-collector.meminfo --no-collector.netclass --no-collector.netdev --no-collector.netstat --no-collector.nfs --no-collector.nfsd --no-collector.pressure --no-collector.rapl --no-collector.schedstat --no-collector.sockstat --no-collector.softnet --no-collector.stat --no-collector.thermal_zone --no-collector.time --no-collector.timex --no-collector.udp_queues --no-collector.uname --no-collector.vmstat --no-collector.xfs --no-collector.zfs --no-collector.btrfs --no-collector.powersupplyclass --web.disable-exporter-metrics --collector.textfile.directory /root/prometheus/textfilecollector &

出力結果の確認

もともとの起動では :9100 にアクセスしたときの表示行数が 956行 変更後は 79行

これで結構少なく出来たのでは?

influxDBに書き込むようにする

一旦保留。