Permalink
Browse files

Script to cleanup old stats in redis

  • Loading branch information...
1 parent 4b277f3 commit 8ea7a7cf788f8198da0d1beb1d190353bec9be10 @lalinsky lalinsky committed Oct 20, 2012
Showing with 28 additions and 0 deletions.
  1. +2 −0 admin/cron/hourly.sh
  2. +26 −0 scripts/cleanup_stats.py
View
@@ -12,3 +12,5 @@ if [ "$1" != "--slave" ]; then
python $DIR/scripts/update_lookup_stats.py -q -c $DIR/acoustid.conf
fi
+python $DIR/scripts/cleanup_stats.py -q -c $DIR/acoustid.conf
+
View
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+# Copyright (C) 2012 Lukas Lalinsky
+# Distributed under the MIT license, see the LICENSE file for details.
+
+import datetime
+from acoustid.script import run_script
+
+
+def main(script, opts, args):
+ two_days_ago = datetime.datetime.now() - datetime.timedelta(days=2)
+ last_key = two_days_ago.strftime('%Y-%m-%d:%H:%M')
+ redis = script.redis
+ tables = ('lookups.time.ms', 'lookups.time.count')
+ for table in tables:
+ to_delete = []
+ for key in redis.hkeys(table):
+ if key < last_key:
+ to_delete.append(key)
+ if to_delete:
+ for table in tables:
+ redis.hdel(table, *to_delete)
+
+
+run_script(main)
+

0 comments on commit 8ea7a7c

Please sign in to comment.