#!/bin/bash
# Monitor whether mysql db is locked

THRESHOLD=$1
ERROR=$(mysqladmin --defaults-file=/root/.my.cnf processlist 2>/dev/null | grep "Waiting for table metadata lock" | wc -l)

if [[ "$ERROR" -gt "$THRESHOLD" ]]; then
    echo "2; Mysql is locked. $ERROR transactions waiting for a lock"
else
    echo "0; All is good"
fi
