Final working version, for now
This commit is contained in:
parent
ae32ba4ae4
commit
354088b245
55
psi-alerts.sh
Normal file → Executable file
55
psi-alerts.sh
Normal file → Executable file
@ -44,6 +44,8 @@ sms_dst="${SMS_DST}"
|
|||||||
sms_domain="$(awk -F@ '{print $NF}' <<< ${SMS_DST})"
|
sms_domain="$(awk -F@ '{print $NF}' <<< ${SMS_DST})"
|
||||||
ssh_port="${SSH_PORT}"
|
ssh_port="${SSH_PORT}"
|
||||||
ssh_host="${SSH_HOST}"
|
ssh_host="${SSH_HOST}"
|
||||||
|
ssh_user="${SSH_USER}"
|
||||||
|
ssh_id_path="${SSH_ID_PATH}"
|
||||||
clear_threshold="${CLEAR_THRESHOLD}"
|
clear_threshold="${CLEAR_THRESHOLD}"
|
||||||
notification_cmd="${NOTIFICATION_CMD}"
|
notification_cmd="${NOTIFICATION_CMD}"
|
||||||
notification_opts="${NOTIFICATION_OPTS}"
|
notification_opts="${NOTIFICATION_OPTS}"
|
||||||
@ -51,32 +53,31 @@ id_idx="${NOTIFICATION_IDX}"
|
|||||||
|
|
||||||
print_psi () {
|
print_psi () {
|
||||||
local psi_file="${1}"
|
local psi_file="${1}"
|
||||||
cat "${(P)psi_file}"
|
cat "${(P)$(tr '[[:upper:]]' '[[:lower:]]' <<< "${psi_file}")}"
|
||||||
}
|
}
|
||||||
|
|
||||||
print_pidstat () {
|
print_pidstat () {
|
||||||
local psi_type="${1}"
|
local psi_type="${1}"
|
||||||
local opts="-l --human"
|
|
||||||
|
|
||||||
case "${psi_type}" in
|
case "${psi_type}" in
|
||||||
CPU)
|
CPU)
|
||||||
opts="-u ${opts}"
|
pidstat -ul --human
|
||||||
;;
|
;;
|
||||||
IO)
|
IO)
|
||||||
opts="-d ${opts}"
|
pidstat -dl --human
|
||||||
;;
|
;;
|
||||||
MEM)
|
MEM)
|
||||||
opts="-r ${opts}"
|
pidstat -rl --human
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
print "Invalid psi_type: ${psi_type}" >&2
|
print "Invalid psi_type: ${psi_type}" >&2
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
pidstat "${opts}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
send_notice () {
|
send_notice () {
|
||||||
|
#set -x
|
||||||
local psi_type="${1}"
|
local psi_type="${1}"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
@ -96,7 +97,7 @@ send_notice () {
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
integer notification_id
|
integer notification_id
|
||||||
if ! notification_id=$(ssh -q "${ssh_host}" -p ${ssh_port} \
|
if ! notification_id=$(ssh -q -i "${ssh_id_path}" "${ssh_user}@${ssh_host}" -p ${ssh_port} \
|
||||||
"${notification_cmd} ${notification_opts} '${host}: PSI ${psi_type} triggered!' '${psi}'"); then
|
"${notification_cmd} ${notification_opts} '${host}: PSI ${psi_type} triggered!' '${psi}'"); then
|
||||||
print "Connection to notification daemon failed!" >&2
|
print "Connection to notification daemon failed!" >&2
|
||||||
false
|
false
|
||||||
@ -104,6 +105,7 @@ send_notice () {
|
|||||||
echo ${notification_id}
|
echo ${notification_id}
|
||||||
true
|
true
|
||||||
fi
|
fi
|
||||||
|
#set +x
|
||||||
}
|
}
|
||||||
|
|
||||||
send () {
|
send () {
|
||||||
@ -128,29 +130,28 @@ send () {
|
|||||||
|
|
||||||
local psi="$(print_psi $(tr '[[:upper:]]' '[[:lower:]]' <<< ${psi_type}))"
|
local psi="$(print_psi $(tr '[[:upper:]]' '[[:lower:]]' <<< ${psi_type}))"
|
||||||
|
|
||||||
local subj="PSI on deltachunk ${psi_type} triggered!"
|
|
||||||
|
|
||||||
|
|
||||||
local body="Pressure Stall Information triggered on ${psi_type} at $(date +'%FT%T %Z')"
|
|
||||||
if [[ -n "${current_alarms}" ]]; then
|
|
||||||
body="${body}\nMultiple alarms triggered: ${current_alarms}"
|
|
||||||
# if this is not an SMS, include pidstat info
|
|
||||||
if [[ ! "${dst}" =~ "${sms_domain}" ]]; then
|
|
||||||
for p in $(tr '|' ' ' <<< "${current_alarms}"); do
|
|
||||||
body="${body}\n\n$(print_pidstat ${p})"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
local email=$(mktemp /tmp/psi.eml.XXXX)
|
local email=$(mktemp /tmp/psi.eml.XXXX)
|
||||||
|
local subj
|
||||||
|
printf "Pressure Stall Information triggered on ${psi_type} at $(date +'%FT%T %Z')\n\n" > ${email}
|
||||||
|
if [[ -n "${current_alarms}" ]]; then
|
||||||
|
subj="PSI on deltachunk ${current_alarms} triggered!"
|
||||||
|
printf "Multiple alarms triggered: ${current_alarms}\n\n" >> ${email}
|
||||||
|
else
|
||||||
|
subj="PSI on deltachunk ${psi_type} triggered!"
|
||||||
|
current_alarms="${psi_type}"
|
||||||
|
fi
|
||||||
|
|
||||||
cat <<-EOF > ${email}
|
# is this an email or SMS?
|
||||||
${body}
|
if [[ ! "${dst}" =~ "${sms_domain}" ]]; then
|
||||||
|
for p in $(tr '|' ' ' <<< "${current_alarms}"); do
|
||||||
EOF
|
printf "\npidstat info for ${p}\n\n" >> ${email}
|
||||||
|
print_pidstat "${p}" >> ${email}
|
||||||
|
printf "\n\n" >> ${email}
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# send the message
|
||||||
/usr/bin/mail --resource-files=/ \
|
/usr/bin/mail --resource-files=/ \
|
||||||
--subject="${subj}" \
|
--subject="${subj}" \
|
||||||
--end-options \
|
--end-options \
|
||||||
|
Loading…
Reference in New Issue
Block a user