Skip to content

Instantly share code, notes, and snippets.

@d10v
Last active September 13, 2023 05:10
Show Gist options
  • Save d10v/f8c02d37d661b731abd1 to your computer and use it in GitHub Desktop.
Save d10v/f8c02d37d661b731abd1 to your computer and use it in GitHub Desktop.
opentsdb delete old data
#!/bin/bash
set -o nounset
set -o errexit
set -o pipefail
EXTRA_TAGS=${1}
TSDB_CMD=$( /usr/bin/which tsdb )
START_TIME="1y-ago"
END_TIME="45d-ago"
METRICS=$( ${TSDB_CMD} uid grep . | grep -a ^metrics | cut -d\ -f2 | sed 's/\:$//g' )
for METRIC in ${METRICS}; do
CMD="${TSDB_CMD} scan --delete ${START_TIME} ${END_TIME} sum ${METRIC} ${EXTRA_TAGS}"
echo "RUNNING: ${CMD}"
${CMD} > /dev/null
done
@d10v
Copy link
Author

d10v commented Dec 18, 2017

(tip by @kylebrandt ) There's also a way to do that with HBase table TTL, e.g.
hbase(main):004:0> alter 'tsdb', NAME => 't', TTL => 65664000 from the hbase shell
and the run a major compaction (can increase load on cluster a lot) major_compact 'tsdb' (edited)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment