#!/bin/bash

whisper_dir='<%= @graphite_path %>/storage/whisper'

# Delete files which haven't been modified in over 2 years
find $whisper_dir -type f -mtime +730 -delete

<%- if scope.lookupvar('::aws_migration') %>
# Delete directories where none of the files inside have been modified in the
# last 14 days. This effectively removes stats about machines which no longer
# exist.
for dir in $whisper_dir/*; do
  if [[ ! -z $dir && -z "$(find $dir -mtime -14)" && $? -eq 0 ]]; then
    rm -rf $dir;
  fi
done
<% end -%>

# Delete empty directories
find $whisper_dir -type d -empty -delete

#!/bin/bash

whisper_dir='<%= @graphite_path %>/storage/whisper'

# Delete files which haven't been modified in over 2 years
find $whisper_dir -type f -mtime +730 -delete

<%- if scope.lookupvar('::aws_migration') %>
# Delete directories where none of the files inside have been modified in the
# last 14 days. This effectively removes stats about machines which no longer
# exist.
for dir in $whisper_dir/*; do
  if [[ ! -z $dir && -z "$(find $dir -mtime -14)" && $? -eq 0 ]]; then
    rm -rf $dir;
  fi
done

for dir in stats/timers stats_counts; do
  find "$whisper_dir/$dir" -maxdepth 1 -name "*ip-*" -type d -print0 | while IFS= read -r -d '' dir; do
    if [[ ! -z $dir && -z "$(find $dir -mtime -56)" && $? -eq 0 ]]; then
      rm -rf "$dir";
    fi
  done
done
<% end -%>

# Delete empty directories
find $whisper_dir -type d -empty -delete

Improve clearing out old Graphite data in AWS
Improve clearing out old Graphite data in AWS

There's already support for deleting the directories with metrics from
collectd relating to a single machine, but inside the stats and
stats_counts namespaces, there are plenty of old machine specific
metrics.

Use the distinctive "ip-" string in the name to identify the
directories that likely contain machine specific metrics, then delete
them if they haven't been updated in around 8 weeks.

For the moment, this is also limited by looking directly (through
-maxdepth 1) in just stats/timers and stats_counts, which contains
mostly timer data related to NGinx logs, that I believe can be
deleted. I think there are other cases where deleting old statsd data
could change the data on dashboards.
