From b2c40e542b5b4593393f6dd617cf9c4332002e37 Mon Sep 17 00:00:00 2001
From: Ian Wienand <iwienand@redhat.com>
Date: Wed, 13 Aug 2014 10:42:01 +1000
Subject: [PATCH] Remove old stats from whisper

Over time, graphite seems to have acquired a range of keys that are no
longer updated and can be quite confusing when trying to find data.

This small cron job (cribbed from suggestions in [1]) should remove
all old data that hasn't been updated in nine months (this should be
long-enough to cover all manner of periodic jobs)

[1] http://stackoverflow.com/questions/9587161/how-to-cleanup-the-graphite-whispers-data

Change-Id: I598b9d370a337866e9086cbe0238569da70aa471
---
 modules/graphite/manifests/init.pp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/modules/graphite/manifests/init.pp b/modules/graphite/manifests/init.pp
index f681bc8dab..5f94c2cbb7 100644
--- a/modules/graphite/manifests/init.pp
+++ b/modules/graphite/manifests/init.pp
@@ -218,5 +218,15 @@ class graphite(
                     Vcsrepo['/opt/statsd']],
   }
 
+  # remove any stats that haven't been updated for ~9 months and
+  # remove empty dirs
+  cron { 'remove_old_stats':
+    user        => 'root',
+    hour        => '2',
+    minute      => '0',
+    command     => 'find /var/lib/graphite/storage/whisper -type f -mtime +270 -name \*.wsp -delete; find /var/lib/graphite/storage/whisper -depth -type d -empty -delete > /dev/null',
+    environment => 'PATH=/usr/bin:/bin:/usr/sbin:/sbin',
+  }
+
 }