LoginSignup
1
1

More than 3 years have passed since last update.

MySQL監視用の簡易スクリプト

Last updated at Posted at 2019-04-21

bashを用いたMySQL監視用の簡易スクリプトです。
Zabbixなどの監視サービスがない環境で利用できます。

できること

・MySQLサービスの死活監視と指定DBへの接続監視。

前提

・bashを利用できること
・出力したログの監視はSwatch等で実施する。

スクリプト

mysql_monitor.sh
#!/bin/bash

############################################
# 変数定義
############################################
#本処理用ログファイル
MYSQL_LOG="/var/log/mysql_check.log"

############################################
# 処理
############################################
echo "`date`" >> $MYSQL_LOG

##MySQL死活監視
mysqladmin ping -h "MySQLサーバのIP" -u hogehoge -phogehoge  2>&1 | sed -e "/Using a password on the command line interface can be insecure/d" >> $MYSQL_LOG 2>&1
##MySQL DB接続監視
mysql -h "MySQLサーバのIP" -u hogehoge -phogehoge "DB名" -e "exit" 2>&1 | sed -e "/Using a password on the command line interface can be insecure/d" >> $MYSQL_LOG 2>&1

exit
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1