Compare commits

...

3 Commits

4 changed files with 65 additions and 2 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
!psi-alerts.sh !psi-alerts.sh
!psi-alerts@.service !psi-alerts@.service
!psi-monitor.service !psi-monitor.service
!psi-monitor.sh
!psi-by-example !psi-by-example
!.gitignore !.gitignore
!CONFIGURE.md !CONFIGURE.md

View File

@ -89,7 +89,7 @@ print_stats () {
pidstat -ul --human pidstat -ul --human
;; ;;
IO) IO)
sudo iotop --batch --only --iter=1 sudo iotop --batch --only --iter=10
printf "\n\n" printf "\n\n"
pidstat -dl --human pidstat -dl --human
;; ;;

@ -1 +1 @@
Subproject commit 08c476910fc09144cf8df631b72f3c8e063112a9 Subproject commit e09aacd35fed5cf8c9cc7441eab4578e70bdb04b

62
psi-monitor.sh Normal file
View File

@ -0,0 +1,62 @@
#!/usr/bin/env zsh
#
# Pressure Stall Information monitor
#
# Copyright © 2023 Trey Blancher $(base64 -d <<< dHJleUBibGFuY2hlci5uZXQK)
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Submodules may be distributed under a separate software license; see the
# LICENSE file within each submodule.
#
# This script monitors the three pressure stall information files
# /proc/pressure{cpu,io,memory} and reports if any resource is above threshold
# for the "some" values. It takes an optional single argument, the threshold at
# which to alert. If this is not supplied, it defaults to a threshold of 30.0
# percent.
#
local cpu="/proc/pressure/cpu"
local cpu_ctr=0
local io="/proc/pressure/io"
local io_ctr=0
local mem="/proc/pressure/memory"
local mem_ctr=0
local threshold=30.0
if [[ -n "${1}" ]]; then
threshold=${1}
fi
# main loop
while true; do
local cpu_pct=$(grep 'some' ${cpu} | awk '{print $2}' | awk -F'=' '{print $2}')
local io_pct=$(grep 'some' ${io} | awk '{print $2}' | awk -F'=' '{print $2}')
local mem_pct=$(grep 'some' ${mem} | awk '{print $2}' | awk -F'=' '{print $2}')
if (( cpu_pct > threshold )); then
cpu_ctr=$(( ${cpu_ctr} + 1 ))
printf "CPU PSI event %d triggered.\n" ${cpu_ctr}
fi
if (( io_pct > threshold )); then
io_ctr=$(( ${io_ctr} + 1 ))
printf "IO PSI event %d triggered.\n" ${io_ctr}
fi
if (( mem_pct > threshold )); then
mem_ctr=$(( ${mem_ctr} + 1 ))
printf "MEM PSI event %d triggered.\n" ${mem_ctr}
fi
sleep 10
done