【问题标题】:How to cleanup the graphite whisper's data?如何清理石墨耳语的数据?
【发布时间】:2012-03-24 03:15:29
【问题描述】:

我想删除石墨的存储耳语数据,但石墨文档中没有任何内容。

我做的一种方法是手动删除/opt/graphite...../whispers/stats... 处的文件。

但这很乏味,我该怎么做呢?

【问题讨论】:

标签: graphite


【解决方案1】:

目前,从 /opt/graphite/storage/whisper/ 中删除文件是清理耳语数据的正确方法。

至于繁琐的过程,如果您尝试删除某种模式,您可以使用 find 命令。

找到 /opt/graphite/storage/whisper -name loadavg.wsp -delete

Similar Question on answers.launchpad.net/graphite

【讨论】:

  • 我正在使用石墨 + statsd。我尝试过这种方式并且它可以工作,但是过了一会儿,桶被重新创建了。知道为什么以及如何阻止它吗?
  • 如何重启 statsd?我没有在进程列表中找到 statsd,但我遇到了这个问题。
  • 需要注意的是,删除未使用的路径后,Graphite本身并不一定要重启。 Statsd 是一个单独的问题,请继续并重新启动它,但 Graphite 会很好地处理已删除的路径。我认为我应该澄清这一点,因为这在某些时候对我来说是一个绊脚石。
  • search_index 呢?是否也应该删除或截断?
  • 有没有办法查看是否所有数据都过期了(例如自上次更新后maxRetention已过)?删除旧的过期.wsp 文件?
【解决方案2】:

正如人们所指出的,删除文件是可行的方法。扩展以前的答案,我制作了这个脚本,删除任何超过其最大保留期限的文件。定期以cronjob 的形式运行它。

#!/bin/bash
d=$1
now=$(date +%s)

MINRET=86400

if [ -z "$d" ]; then
  echo "Must specify a directory to clean" >&2
  exit 1
fi

find $d -name '*.wsp' | while read w; do
  age=$((now - $(stat -c '%Y' "$w")))
  if [ $age -gt $MINRET ]; then
    retention=$(whisper-info.py $w maxRetention)
    if [ $age -gt $retention ]; then
      echo "Removing $w ($age > $retention)"
      rm $w
    fi
  fi
done

find $d -empty -type d -delete

有几点需要注意——whisper-info 调用是相当重量级的。为了减少对它的调用次数,我将 MINRET 常量放入其中,这样在 1 天前(24*60*60 秒)之前不会考虑删除任何文件 - 调整以适应您的需求。可能还有其他可以做的事情来分片工作或普遍提高其效率,但我还没有需要。

【讨论】:

  • nit: Must specify a directory to clean 是一条错误消息。因此,它应该写入正确的位置:echo "Must ..." >&2
  • 这是很棒的 tyvm!
【解决方案3】:

我想这是进入服务器故障领域,但我补充说 以下 cron 作业用于删除我们尚未删除的旧指标 写入超过 30 天(例如已被 处置):

find /mnt/graphite/storage -mtime +30 | grep -E \
"/mnt/graphite/storage/whisper/collectd/app_name/[^/]*" -o \
| uniq | xargs rm -rf

这将删除具有有效数据的目录。

第一:

find whisperDir -mtime +30 -type f | xargs rm 

然后删除空目录

find . -type d -empty | xargs rmdir

最后一步应该重复,因为可能会留下新的空目录。

【讨论】:

  • 在几乎所有现代 Unix 系统上,这应该可以使用 find builtins 来压缩 - 例如find /opt/graphite/storage/whisper -type f -mtime +120 -name \*.wsp -delete; find /opt/graphite/storage/whisper -depth -type d -empty -delete
  • 在 ubuntu 中仅供参考,路径是 /var/lib/graphite/whisper
  • 我们不能使用 tmpreaper 来做这件事有什么原因吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-18
相关资源
最近更新 更多