Created
June 17, 2021 23:47
-
-
Save hotta/b82ae8351df2c1e03d67b52818779585 to your computer and use it in GitHub Desktop.
A script to monitor pgpool status
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
#!/bin/bash | |
[email protected] | |
_INITDIR=~/.pgpool-check/init/ | |
_CHECKDIR=~/.pgpool-check/current/ | |
function _die { | |
echo $1 | |
exit 1 | |
} | |
function _init { | |
rm -rf $_INITDIR $_CHECKDIR | |
mkdir -p $_INITDIR $_CHECKDIR | |
_check $_INITDIR | |
echo "initialize done." | |
exit 0 | |
} | |
function _check { | |
if [ $# -eq 0 ]; then | |
die "Please specify DIR." | |
fi | |
_DIR=$1 | |
cd $_DIR || _die "Do $0 -z to initialize app first." | |
echo "pcp_node_count = $(pcp_node_count -w)" > pgpool_check.txt | |
cat >> pgpool_check.txt <<___ | |
pcp_node_info: | |
1. node hostname | |
2. node port number | |
3. status | |
4. wait for load balancing | |
5. backend status name | |
6. backend role | |
7. replication delay | |
8. replicaiton status (from pg_stat_replication) | |
9. streaming replication status(from pg_stat_replication) | |
10. last update time of status | |
___ | |
pcp_node_info -w 0 |\ | |
awk '{print $1,$2,$3,$4,$5,$6,$8,$9}' >> pgpool_check.txt | |
pcp_node_info -w 1 |\ | |
awk '{print $1,$2,$3,$4,$5,$6,$8,$9}' >> pgpool_check.txt | |
cat >> pgpool_check.txt <<___ | |
pcp_watchdog_info: | |
The 1st line indicates watchdog cluster info: | |
1. all watchdog node number in a cluster | |
2. Is the virtual IP activated on this node? | |
3. master node name | |
4. master node hostname | |
Following lines indicates watchdog nodes list: | |
1. node name | |
2. hostname | |
3. pgpool port number | |
4. watchdog port number | |
5. current node status | |
6. current node status name | |
___ | |
pcp_watchdog_info -w >> pgpool_check.txt | |
# echo "pcp_pool_status:" >> pgpool_check.txt | |
# pcp_pool_status -w >> pgpool_check.txt | |
} | |
if [ $# -ne 0 ] && [ "$1" == "-z" ]; then | |
_init | |
else | |
_check $_CHECKDIR | |
fi | |
diff -r $_INITDIR $_CHECKDIR >& /dev/null | |
if [ $? -ne 0 ]; then | |
# echo Sending mail | |
diff -r $_INITDIR $_CHECKDIR > /tmp/pgpool-check-report.txt | |
cat $_CHECKDIR/pgpool_check.txt >> /tmp/pgpool-check-report.txt | |
cat /tmp/pgpool-check-report.txt | mail -s "pgpool-check.sh infomation." $MAILTO | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment