LoginSignup
2
0

More than 3 years have passed since last update.

MySQLのセッション数を監視する

Posted at

セッション数を監視します。シェルスクリプトで実装します。

バージョンの確認

> select version();
+-----------------+
| version()       |
+-----------------+
| 10.1.40-MariaDB |
+-----------------+

セッション数の上限を確認

> show variables like "max_connections";
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+

現在利用しているセッション数確認

> select count(*) from information_schema.processlist;
+----------+
| count(*) |
+----------+
|        1 |
+----------+
1 row in set (0.00 sec)

監視用のシェル作成

test.sh
#! /usr/bin/bash
RESULT=`mysql -uroot -pkusakari -s -N < test.sql`
if [ $RESULT -ge $1 ]; then
  echo "FATAL"
else
  echo "NORMAL"
fi

インプット用ファイル

test.sql
select count(*) from information_schema.processlist;

実行するコマンド

$ ./test.sh 1
FATAL
$ ./test.sh 0
FATAL
$ ./test.sh 2
NORMAL

以上、よろしくお願いいたします

2
0
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
2
0