Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
monocloud-health: Fix some FreeBSD systems not having nproc
Browse files Browse the repository at this point in the history
  • Loading branch information
kreatoo committed Jun 28, 2024
1 parent 2555504 commit 8de06b8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions monocloud/monocloud-health.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
###~ description: This script is used to check the health of the server
#~ variables
script_version="v4.3.11"
script_version="v4.3.12"

if [[ "$CRON_MODE" == "1" ]]; then
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Expand Down Expand Up @@ -35,6 +35,14 @@ grep_custom() {
fi
}

nproc_custom() {
if [[ "$(uname -s | tr '[:upper:]' '[:lower:]')" == "freebsd" ]]; then
sysctl -n hw.ncpu
else
nproc
fi
}

#~ check configuration file
check_config_file() {
[[ ! -f "$@" ]] && {
Expand Down Expand Up @@ -348,10 +356,10 @@ check_system_load_and_ram() {
local json="{\"load\":\"$load\",\"ram\":\"$ram_usage\"}"

if [[ $(echo "$load <= $LOAD_LIMIT_CPU" | bc -l) -eq 1 ]]; then
message="System load limit went below $LOAD_LIMIT_CPU (Current: $load, Multiplier: $LOAD_LIMIT_MULTIPLIER, CPU: $(nproc))"
message="System load limit went below $LOAD_LIMIT_CPU (Current: $load, Multiplier: $LOAD_LIMIT_MULTIPLIER, CPU: $(nproc_custom))"
alarm_check_up "load" "$message" "system"
else
message="The system load limit has exceeded $LOAD_LIMIT_CPU (Current: $load, Multiplier: $LOAD_LIMIT_MULTIPLIER, CPU: $(nproc))"
message="The system load limit has exceeded $LOAD_LIMIT_CPU (Current: $load, Multiplier: $LOAD_LIMIT_MULTIPLIER, CPU: $(nproc_custom))"
alarm_check_down "load" "$message" "system"
fi

Expand Down Expand Up @@ -603,7 +611,7 @@ main() {

check_config_file "$CONFIG_PATH" && . "$CONFIG_PATH"

export LOAD_LIMIT_CPU="$(echo "$(nproc) * ${LOAD_LIMIT_MULTIPLIER:-1}" | bc) "
export LOAD_LIMIT_CPU="$(echo "$(nproc_custom) * ${LOAD_LIMIT_MULTIPLIER:-1}" | bc) "

[[ -z "$ALARM_INTERVAL" ]] && ALARM_INTERVAL=3
[[ -z "$DYNAMIC_LIMIT_INTERVAL" ]] && DYNAMIC_LIMIT_INTERVAL=100
Expand Down

0 comments on commit 8de06b8

Please sign in to comment.