From cf33dc92f338a1e4721ce9993a9433204828bda9 Mon Sep 17 00:00:00 2001 From: Trey Blancher Date: Thu, 31 Aug 2023 22:57:09 -0400 Subject: [PATCH] Initial commit of psi-monitor.sh (psi-by-example is too granular) --- .gitignore | 1 + psi-monitor.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 psi-monitor.sh diff --git a/.gitignore b/.gitignore index 471e1b4..efbe6eb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ !psi-alerts.sh !psi-alerts@.service !psi-monitor.service +!psi-monitor.sh !psi-by-example !.gitignore !CONFIGURE.md diff --git a/psi-monitor.sh b/psi-monitor.sh new file mode 100644 index 0000000..75bc6bc --- /dev/null +++ b/psi-monitor.sh @@ -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 . +# +# 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