26 lines
679 B
Bash
Executable file
26 lines
679 B
Bash
Executable file
#!/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
|