Created
November 27, 2017 19:17
-
-
Save victorpendleton/d08d1530e50ab38b0018f3ad73dd2539 to your computer and use it in GitHub Desktop.
Script used to fire off action when load crosses threshold
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
RUNTIME=$(date +'%F %T'); # Get date/time | |
NUMOFCPUS=$(grep -c ^processor /proc/cpuinfo); # Grab the number of CPUs | |
THRESHOLD=$(echo "${NUMOFCPUS}*.5" | bc); # Calculate the threshold | |
CPU=$(top -bn1 | grep load | awk '{printf "%.2f\t\t\n", $(NF-2)}'); # Grab the current load from top NumberFields minus 2 should be last minute average | |
EXCEEDED=$(echo "${CPU} > ${THRESHOLD}" | bc); # Determine if current load is higher than threshold | |
if (( ${EXCEEDED} > 0 )) | |
then | |
echo "${RUNTIME} - Current load: ${CPU}" >> /some/file; | |
echo "${RUNTIME} - CPU has execeed threshold of: ${THRESHOLD}. Capturing processlist..." >> /some/file; | |
# Use a mysql properties file or store the user/password information in this script | |
/usr/bin/mysql --socket= --user --execute="SHOW PROCESSLIST" >> /some/file; | |
echo "" >> /some/file; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment