Created
December 2, 2022 20:50
-
-
Save guriandoro/73602b76509a687c60939ff9181b4272 to your computer and use it in GitHub Desktop.
Tests for integrating pt-stalk and pg_gather.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./anydbver deploy \ | |
node0 pg:13 sysbench sysbench-pg:node0 oltp_read_write \ | |
node1 sysbench sysbench-pg:node0 oltp_read_write | |
./anydbver ssh node1 | |
percona-release setup ppg-11 | |
yum -y install percona-postgresql11-libs | |
/usr/local/bin/run_sysbench.sh | |
./anydbver ssh node0 | |
sudo su - postgres | |
#rm -rf /tmp/pt/ | |
PT_STALK_COLLECT_DIR="/tmp/pt/collect/" | |
PT_STALK_CUSTOM_COLLECT_FILE=${PT_STALK_COLLECT_DIR}"/../pt-stalk-custom-collect.sh" | |
mkdir -p ${PT_STALK_COLLECT_DIR} | |
cd ${PT_STALK_COLLECT_DIR}/.. | |
curl -LOs https://raw.githubusercontent.com/percona/percona-toolkit/3.x/bin/pt-stalk | |
curl -LOs https://raw.githubusercontent.com/percona/support-snippets/master/postgresql/pg_gather/gather.sql | |
chmod +x ./pt-stalk | |
#rm -f ${PT_STALK_CUSTOM_COLLECT_FILE} | |
cat << 'EOF' > ${PT_STALK_CUSTOM_COLLECT_FILE} | |
#!/bin/bash | |
trg_plugin() { | |
### Example usage: get current count of clients connected to PostgreSQL | |
psql $EXT_ARGV -qtc "select count(*) from pg_stat_activity where backend_type = 'client backend'" | |
} | |
before_collect() { | |
echo "$prefix Running pg_gather. Collect $ITER triggered" | |
psql $EXT_ARGV -X -f /tmp/pt/gather.sql > $OPT_DEST/$prefix-pg-gather-out.txt & | |
} | |
EOF | |
chmod +x ${PT_STALK_CUSTOM_COLLECT_FILE} | |
### In both cases below, we need to send psql connection string for use with trg_plugin and pg_gather. | |
### In this case, the command will try to see if there are more than 4 clients connected to postgres | |
### for 2 seconds in a row and it will trigger collection. | |
./pt-stalk \ | |
--system-only \ | |
--function=${PT_STALK_CUSTOM_COLLECT_FILE} --threshold=4 --cycles=2 \ | |
--plugin=${PT_STALK_CUSTOM_COLLECT_FILE} \ | |
--dest=${PT_STALK_COLLECT_DIR} --log=${PT_STALK_COLLECT_DIR}/../pt-stalk.log --pid=${PT_STALK_COLLECT_DIR}/../pt-stalk.pid \ | |
--iterations=4 --sleep=30 -- --user=<username> --dbname=<database_name> | |
### In this case, we don't use the client checks, we just collect pt-stalk OS metrics and pg_gather. | |
./pt-stalk \ | |
--system-only \ | |
--no-stalk \ | |
--plugin=${PT_STALK_CUSTOM_COLLECT_FILE} \ | |
--dest=${PT_STALK_COLLECT_DIR} --log=${PT_STALK_COLLECT_DIR}/../pt-stalk.log --pid=${PT_STALK_COLLECT_DIR}/../pt-stalk.pid \ | |
--iterations=4 --sleep=30 -- --user=<username> --dbname=<database_name> | |
### To collect the data | |
tar czvf "/tmp/pt-stalk-`hostname`.tar.gz" ${PT_STALK_COLLECT_DIR}* | |
### Note: the tool will run the checks after every collection iteration | |
### We need to specify --dest and --pid because we won't run pt-stalk with root privileges | |
### Additionally --log is specified for cases when we'll use --daemonize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment