我想删除石墨的存储耳语数据,但石墨文档中没有任何内容。
/opt/graphite...../whispers/stats...
我做的一种方法是手动删除文件。
但这很乏味,那我该怎么做呢?
我想删除石墨的存储耳语数据,但石墨文档中没有任何内容。
/opt/graphite...../whispers/stats...
我做的一种方法是手动删除文件。
但这很乏味,那我该怎么做呢?
Currently, deleting files from /opt/graphite/storage/whisper/ is the correct way to clean up whisper data.
As for the tedious side of the process, you could use the find command if there is a certain pattern that your trying to remove.
find /opt/graphite/storage/whisper -name loadavg.wsp -delete
我想这将进入服务器故障领域,但我添加了以下 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
应该重复最后一步,因为可能会留下新的空目录。
正如人们指出的那样,删除文件是要走的路。扩展以前的答案,我制作了这个脚本,删除任何超过其最大保留期限的文件。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 秒)之前不会考虑删除任何文件 - 调整以适应您的需求。可能还有其他可以做的事情来分片工作或普遍提高其效率,但我还没有必要这样做。