Skip to content

Instantly share code, notes, and snippets.

@streeter
Forked from dcramer/cleanup_redis_tsdb.py
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save streeter/70a3486823e458a806c4 to your computer and use it in GitHub Desktop.

Select an option

Save streeter/70a3486823e458a806c4 to your computer and use it in GitHub Desktop.

Revisions

  1. streeter revised this gist Jan 23, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion cleanup_redis_tsdb.py
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,6 @@ def delete(key):
    def cleanup():
    epoch = tsdb.normalize_to_rollup(datetime.utcnow() - timedelta(days=7), 3600)
    print('Epoch set to {}'.format(epoch))
    import pdb; pdb.set_trace()
    for connection in tsdb.conn.hosts.itervalues():
    print('> Checking connection {}'.format(connection))
    cleanup_connection(connection, epoch)
  2. streeter revised this gist Jan 23, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions cleanup_redis_tsdb.py
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,7 @@ def delete(key):
    def cleanup():
    epoch = tsdb.normalize_to_rollup(datetime.utcnow() - timedelta(days=7), 3600)
    print('Epoch set to {}'.format(epoch))
    import pdb; pdb.set_trace()
    for connection in tsdb.conn.hosts.itervalues():
    print('> Checking connection {}'.format(connection))
    cleanup_connection(connection, epoch)
  3. streeter revised this gist Jan 23, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cleanup_redis_tsdb.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/usr/bin/env python
    from sentry.utils.runner import configure
    configure(default_config_path='sentry.conf.py')
    configure(config_path='sentry.conf.py')

    from datetime import datetime, timedelta
    from sentry.app import tsdb
  4. streeter revised this gist Jan 23, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cleanup_redis_tsdb.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/usr/bin/env python
    from sentry.utils.runner import configure
    configure()
    configure(default_config_path='sentry.conf.py')

    from datetime import datetime, timedelta
    from sentry.app import tsdb
  5. @dcramer dcramer revised this gist Jan 22, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions cleanup_redis_tsdb.py
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    from sentry.utils.runner import configure
    configure()

    from datetime import datetime
    from datetime import datetime, timedelta
    from sentry.app import tsdb


    @@ -18,7 +18,7 @@ def delete(key):


    def cleanup():
    epoch = tsdb.normalize_to_rollup(datetime.utcnow(), 3600)
    epoch = tsdb.normalize_to_rollup(datetime.utcnow() - timedelta(days=7), 3600)
    print('Epoch set to {}'.format(epoch))
    for connection in tsdb.conn.hosts.itervalues():
    print('> Checking connection {}'.format(connection))
  6. @dcramer dcramer revised this gist Jan 22, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion cleanup_redis_tsdb.py
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,8 @@ def delete(key):
    connection.delete(key)
    for key in connection.scan_iter('ts:*'):
    bits = key.split(':', 4)
    if int(bits[3]) < epoch: # 7 days
    assert len(bits) == 4
    if int(bits[2]) < epoch: # 7 days
    delete(key)


  7. @dcramer dcramer revised this gist Jan 22, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion cleanup_redis_tsdb.py
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    from sentry.utils.runner import configure
    configure()

    from datetime import datetime
    from sentry.app import tsdb


    @@ -16,7 +17,7 @@ def delete(key):


    def cleanup():
    epoch = (time.time() - 60 * 60 * 24 * 7) / 3600
    epoch = tsdb.normalize_to_rollup(datetime.utcnow(), 3600)
    print('Epoch set to {}'.format(epoch))
    for connection in tsdb.conn.hosts.itervalues():
    print('> Checking connection {}'.format(connection))
  8. @dcramer dcramer revised this gist Jan 22, 2015. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions cleanup_redis_tsdb.py
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,7 @@ def delete(key):
    connection.delete(key)
    for key in connection.scan_iter('ts:*'):
    bits = key.split(':', 4)
    epoch = int(bits[3])
    if epoch < epoch: # 7 days
    if int(bits[3]) < epoch: # 7 days
    delete(key)


  9. @dcramer dcramer revised this gist Jan 22, 2015. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions cleanup_redis_tsdb.py
    Original file line number Diff line number Diff line change
    @@ -5,21 +5,23 @@
    from sentry.app import tsdb


    def cleanup_connection(connection):
    def cleanup_connection(connection, epoch):
    def delete(key):
    print('Removing key {}'.format(key))
    print('>> Removing key {}'.format(key))
    connection.delete(key)
    for key in connection.scan_iter('ts:*'):
    bits = key.split(':', 4)
    epoch = int(bits[3])
    if epoch < 394798: # 7 days
    if epoch < epoch: # 7 days
    delete(key)


    def cleanup():
    epoch = (time.time() - 60 * 60 * 24 * 7) / 3600
    print('Epoch set to {}'.format(epoch))
    for connection in tsdb.conn.hosts.itervalues():
    print('Checking connection {}'.format(connection))
    cleanup_connection(connection)
    print('> Checking connection {}'.format(connection))
    cleanup_connection(connection, epoch)


    if __name__ == '__main__':
  10. @dcramer dcramer created this gist Jan 22, 2015.
    26 changes: 26 additions & 0 deletions cleanup_redis_tsdb.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/usr/bin/env python
    from sentry.utils.runner import configure
    configure()

    from sentry.app import tsdb


    def cleanup_connection(connection):
    def delete(key):
    print('Removing key {}'.format(key))
    connection.delete(key)
    for key in connection.scan_iter('ts:*'):
    bits = key.split(':', 4)
    epoch = int(bits[3])
    if epoch < 394798: # 7 days
    delete(key)


    def cleanup():
    for connection in tsdb.conn.hosts.itervalues():
    print('Checking connection {}'.format(connection))
    cleanup_connection(connection)


    if __name__ == '__main__':
    cleanup()