【发布时间】:2012-03-24 03:15:29
【问题描述】:
我想删除石墨的存储耳语数据,但石墨文档中没有任何内容。
我做的一种方法是手动删除/opt/graphite...../whispers/stats... 处的文件。
但这很乏味,我该怎么做呢?
【问题讨论】:
-
如果它们在删除后再次出现,请检查另一个问题:stackoverflow.com/questions/15501677/…
标签: graphite
我想删除石墨的存储耳语数据,但石墨文档中没有任何内容。
我做的一种方法是手动删除/opt/graphite...../whispers/stats... 处的文件。
但这很乏味,我该怎么做呢?
【问题讨论】:
标签: graphite
目前,从 /opt/graphite/storage/whisper/ 中删除文件是清理耳语数据的正确方法。
至于繁琐的过程,如果您尝试删除某种模式,您可以使用 find 命令。
找到 /opt/graphite/storage/whisper -name loadavg.wsp -delete
【讨论】:
.wsp 文件?
正如人们所指出的,删除文件是可行的方法。扩展以前的答案,我制作了这个脚本,删除任何超过其最大保留期限的文件。定期以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 秒)之前不会考虑删除任何文件 - 调整以适应您的需求。可能还有其他可以做的事情来分片工作或普遍提高其效率,但我还没有需要。
【讨论】:
Must specify a directory to clean 是一条错误消息。因此,它应该写入正确的位置:echo "Must ..." >&2。
我想这是进入服务器故障领域,但我补充说 以下 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
最后一步应该重复,因为可能会留下新的空目录。
【讨论】:
find /opt/graphite/storage/whisper -type f -mtime +120 -name \*.wsp -delete; find /opt/graphite/storage/whisper -depth -type d -empty -delete