Skip to content

Instantly share code, notes, and snippets.

View BrandonBordeaux's full-sized avatar

Brandon Bordeaux BrandonBordeaux

View GitHub Profile
#!/usr/bin/env bash
# Schedule this in crontab to run one every 15 minutes.
# NOTE: User environment variables are not accessible to cron by default,
# so you may need to introduce these in order for the nodetool commands
# to be found and work properly.
# Example crontab where /etc/profile has the vars needed to find nodetool and java:
# */15 * * * * . /etc/profile && /path/to/collect_histograms.sh >> /path/to/collect_histograms.log 2>&1
set -o errexit
@BrandonBordeaux
BrandonBordeaux / iostat_for_cron.sh
Created June 2, 2025 18:43
Schedule to run once per hour in cron: 0 * * * * The iostat command will run once a second for 1 hour and write to an output file with the day + hour, so each is unique.
iostat -x -c -d -t 1 3600 > $(hostname -i)-$(date +%Y%m%d_%H)-iostat.out
@BrandonBordeaux
BrandonBordeaux / tpstats_for_cron.sh
Created June 2, 2025 18:42
Schedule in cron every 5-10 minutes (depending on what you're after): 0/5 * * * * One output file per hour.
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
shopt -s expand_aliases
# Enable debugging by setting TRACE=1
if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi
@BrandonBordeaux
BrandonBordeaux / jfr_cron.sh
Created June 2, 2025 18:41
JFR trigger script for cron. Run once every 5 minutes in cron: 0/5 * * * * The condition can be modified for the application, but the inner if/else will only run JFR if it's not running already.
#!/usr/bin/env bash
# Enable debugging by setting TRACE=1
if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi
OUTPUT_DIR="/tmp/$(hostname -i)_$(date +%Y%m%d_%H-%M-%S).jfr"
IS_JFR_RUNNING="$(sudo -u cassandra jcmd $(cat /run/dse/dse.pid) JFR.check | grep -o Recording)"
TPSTATS_CONDITION="$(nodetool tpstats | grep ^MemtableFlushWriter | awk '$2 > 4')"
if [[ "${TPSTATS_CONDITION}" ]]; then