Skip to content

Commit 22fbdcc

Browse files
committed
check_load.sh: Add support for FreeBSD
1 parent 2f36fdd commit 22fbdcc

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

localChecks/check_load.sh

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# check_load.sh - Shell script that checks load, intended
33
# for nagios style monitoring systems
44
#
@@ -23,11 +23,19 @@ FiveMinLoadCrit=${4:-$DefaultCrit}
2323
FiveteenMinLoadWarn=${5:-$DefaultWarn}
2424
FiveteenMinLoadCrit=${6:-$DefaultCrit}
2525

26-
OneMinLoad=$(cat /proc/loadavg | sed -r 's/\ +/\ /g' | cut -d \ -f 1)
27-
FiveMinLoad=$(cat /proc/loadavg | sed -r 's/\ +/\ /g' | cut -d \ -f 2)
28-
FiveteenMinLoad=$(cat /proc/loadavg | sed -r 's/\ +/\ /g' | cut -d \ -f 3)
26+
OS=$(uname -s)
2927

30-
numberOfCores=$(grep -c processor /proc/cpuinfo)
28+
if [ "${OS}" = "Linux" ]; then
29+
OneMinLoad=$(cat /proc/loadavg | sed -r 's/\ +/\ /g' | cut -d \ -f 1)
30+
FiveMinLoad=$(cat /proc/loadavg | sed -r 's/\ +/\ /g' | cut -d \ -f 2)
31+
FiveteenMinLoad=$(cat /proc/loadavg | sed -r 's/\ +/\ /g' | cut -d \ -f 3)
32+
numberOfCores=$(grep -c processor /proc/cpuinfo)
33+
elif [ "${OS}" = "FreeBSD" ]; then
34+
OneMinLoad=$(sysctl -n vm.loadavg | cut -d" " -f 2)
35+
FiveMinLoad=$(sysctl -n vm.loadavg | cut -d" " -f 3)
36+
FiveteenMinLoad=$(sysctl -n vm.loadavg | cut -d" " -f 4)
37+
numberOfCores=$(sysctl -n hw.ncpu)
38+
fi
3139

3240
OneMinLoadpct=$(bc <<< "100*$OneMinLoad/$numberOfCores")
3341
FiveMinLoadpct=$(bc <<< "100*$FiveMinLoad/$numberOfCores")

0 commit comments

Comments
 (0)