diff --git a/Makefile b/Makefile index dddb309..6c50765 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ SCRIPTS = cgroup \ date \ rpm \ common \ + monitor \ selinux BIN_FILE = engine-stressor diff --git a/engine-stressor.spec b/engine-stressor.spec index c5cb20f..40776ef 100644 --- a/engine-stressor.spec +++ b/engine-stressor.spec @@ -63,6 +63,7 @@ are memory, CPU or others interferences in the system. %{_datadir}/engine-stressor/engine-operations %{_datadir}/engine-stressor/processes %{_datadir}/engine-stressor/network +%{_datadir}/engine-stressor/monitor %{_datadir}/engine-stressor/volume %{_datadir}/engine-stressor/systemd %{_datadir}/engine-stressor/system diff --git a/monitor b/monitor new file mode 100644 index 0000000..663ff70 --- /dev/null +++ b/monitor @@ -0,0 +1,59 @@ +#!/bin/bash +# shellcheck disable=SC1091 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +CONFIG_DIR="$HOME/.config/engine-stressor" +CONSTANTS_FILE="$CONFIG_DIR/constants" + +if [ ! -f "$CONSTANTS_FILE" ]; then + echo "Error: File $CONSTANTS_FILE does not exist." + exit 1 +fi + +source "$CONSTANTS_FILE" +source "$SHARE_DIR/common" + +# Function to monitor system performance using vmstat +monitor_system() { + echo "Monitoring system performance..." + vmstat 1 5 > vmstat.log + + # Calculate average values + avg_free=$(awk 'NR>2 { sum += $4 } END { printf "%.0f", sum/(NR-2) }' vmstat.log) + avg_si=$(awk 'NR>2 { sum += $7 } END { print sum/(NR-2) }' vmstat.log) + avg_so=$(awk 'NR>2 { sum += $8 } END { print sum/(NR-2) }' vmstat.log) + avg_bi=$(awk 'NR>2 { sum += $9 } END { print sum/(NR-2) }' vmstat.log) + avg_bo=$(awk 'NR>2 { sum += $10 } END { print sum/(NR-2) }' vmstat.log) + avg_wa=$(awk 'NR>2 { sum += $16 } END { print sum/(NR-2) }' vmstat.log) + + echo "Average Free Memory: $avg_free KB" + echo "Average Swap In: $avg_si KB/s" + echo "Average Swap Out: $avg_so KB/s" + echo "Average Blocks In: $avg_bi blocks/s" + echo "Average Blocks Out: $avg_bo blocks/s" + echo "Average IO Wait: $avg_wa%" + + # Determine if the system is under pressure + if (( $(echo "$avg_free < 50000" | bc -l) )) || (( $(echo "$avg_si > 0" | bc -l) )) || (( $(echo "$avg_so > 0" | bc -l) )); then + echo "System is under memory pressure." + else + echo "Memory usage is within acceptable limits." + fi + + if (( $(echo "$avg_bi > 1000" | bc -l) )) || (( $(echo "$avg_bo > 1000" | bc -l) )) || (( $(echo "$avg_wa > 20" | bc -l) )); then + echo "System is under disk pressure." + else + echo "Disk usage is within acceptable limits." + fi +}