How to cleanup the graphite whisper's data?

妖精的绣舞 提交于 2019-11-28 14:49:02

问题


I want to delete the graphite's storage whisper's data but there ain't anything in the graphite docs.

One way I did is deleting the the files at /opt/graphite...../whispers/stats... manually.

But this is tedious, so how do I do it?


回答1:


currently deleting the files from /opt/graphite/storage/whisper/ is the correct way to delete 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

Similar Question on answers.launchpad.net/graphite




回答2:


I suppose that this is going into Server Fault territory, but I added the following cron job to delete old metrics of ours that haven't been written to for over 30 days (e.g. of cloud instances that have been disposed):

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

This will delete directories which have valid data.

First:

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

And then delete empty dirs

find . -type d -empty | xargs rmdir

This last step should be repeated, because may be new empty directories will be left.




回答3:


As people have pointed out, removing the files is the way to go. Expanding on previous answers, I made this script that removes any file that has exceeded its max retention age. Run it as a cronjob fairly regularly.

#!/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

A couple of bits to be aware of - the whisper-info call is quite heavyweight. To reduce the number of calls to it I've put the MINRET constant in, so that no file will be considered for deletion until it is 1 day old (24*60*60 seconds) - adjust to fit your needs. There are probably other things that can be done to shard the job or generally improve its efficiency, but I haven't had need to as yet.



来源:https://stackoverflow.com/questions/9587161/how-to-cleanup-the-graphite-whispers-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!