-
Notifications
You must be signed in to change notification settings - Fork 0
/
load-is-high
executable file
·42 lines (34 loc) · 1.41 KB
/
load-is-high
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# Check if the load is too high.
# Copyright (C) 2021 Scott Weldon
# 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 <http://www.gnu.org/licenses/>.
# Requires:
# - bc
# Returns 0 when load is high, after checking all three load numbers
# (1-minute, 5-minute, and 15-minute averages). If *any* of those numbers are
# high then it counts as high load.
#
# High load counted as double the core count, so the computer is 100%
# overloaded, or has double the amount of work to do than what it can handle.
IFS=' ' read -r -a loads <<< $(cat /proc/loadavg)
NUM_CORES=$(grep -c ^processor /proc/cpuinfo)
MAX_LOAD=$(expr $NUM_CORES \* 2)
if (( $(echo "${loads[0]} > $MAX_LOAD" | bc -l) )) ||
(( $(echo "${loads[1]} > $MAX_LOAD" | bc -l) )) ||
(( $(echo "${loads[2]} > $MAX_LOAD" | bc -l) ))
then
# The load is high.
exit 0
else
# Load is not too high.
exit 1
fi