From e764a59877529f052b324c65b9b9cd2fa2e7de28 Mon Sep 17 00:00:00 2001
From: Ian Wienand <iwienand@redhat.com>
Date: Tue, 29 Sep 2020 14:20:50 +1000
Subject: [PATCH] graphite: add cleanup job

Add the cron job that existed in puppet-graphite to cleanup old,
un-updated stats and directories.

Change-Id: Iac4676ae0ea1d5f1b96b6214ab6ab193c71a2d20
---
 playbooks/roles/graphite/tasks/main.yaml | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/playbooks/roles/graphite/tasks/main.yaml b/playbooks/roles/graphite/tasks/main.yaml
index bcedd75dc4..e78aea1ec0 100644
--- a/playbooks/roles/graphite/tasks/main.yaml
+++ b/playbooks/roles/graphite/tasks/main.yaml
@@ -53,3 +53,21 @@
     name:
       - netcat
     state: present
+
+# Removes files not updated for ~9 months, and clears out empty directories
+- name: Run periodic cleanup
+  cron:
+    name: "Graphite cleanup"
+    minute: "0"
+    hour: "2"
+    job: >
+        bash -c 'echo "--- $(date) ---";
+        find /opt/graphite/storage/whisper -type f -mtime +270 -name "*.wsp" -delete -print;
+        find /opt/graphite/storage/whisper -depth -type d -empty -delete -print'
+        >> /var/log/graphite-cleanup.log 2>&1
+
+- name: Rotate cleanup logs
+  include_role:
+    name: logrotate
+  vars:
+    logrotate_file_name: '/var/log/graphite-cleanup.log'