adding mysql_threads

This commit is contained in:
tengel 2024-03-20 11:28:46 -05:00
parent b5f0c0ef82
commit 1c3f05e36b

26
shell/mysql_threads.sh Executable file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env bash
#
# crontab:
# */10 * * * * /usr/local/sbin/mysql_threads.sh
#
# logrotate:
# /var/log/mysql_threads.log {
# rotate 4
# missingok
# notifempty
# size 5M
# weekly
# }
#
# SPDX-License-Identifier: MIT
SERVER=localhost
LOG=/var/log/mysql_threads.log
DTS=$(date +"%Y-%m-%d %H:%M:%S %Z")
THREADS=$(mysql -h ${SERVER} -B -N -e "SHOW STATUS LIKE 'Threads_connected';" | tr "\011" " ")
USERS=$(mysql -h ${SERVER} -B -N -e "SELECT DISTINCT USER AS users, COUNT(*) FROM information_schema.processlist GROUP BY users;" | tr "\011" ":" | tr "\n" "," | sed '$s/.$//')
echo "${DTS} ${THREADS}, Users_connected [${USERS}]" >> "${LOG}"
exit 0