-
Notifications
You must be signed in to change notification settings - Fork 10
/
check_nxload
executable file
·29 lines (22 loc) · 995 Bytes
/
check_nxload
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
#!/bin/sh
#
# check_nxload
# Kyle Anderson, 2011, Under the GPL 2
#
# nxcheckload - sample script for calculation of the load for a node.
# Reports back a metric for NX to load balance.
# Not really a nagios check, but abusing nrpe for poor-mans load balancing.
# Be sure to use C numeric for calculations
export LC_NUMERIC=C
# The 3 variables of load from uptime
LOADXX=$(awk '{ printf("(100-%s)+(100-%s)+(100-%s)\n", $1, $2, $3); }' /proc/loadavg | bc -q)
# Add of total memory and free memory
Mt=$(awk 'BEGIN { N=0 } /MemTotal|MemFree/ { N+=$2; } END { print N }' /proc/meminfo)
# NBCPU = number of CPU
NBCPU=$(cat /proc/cpuinfo | grep ^processor | wc -l)
# CPU = Mhz of the CPU
CPU=$(cat /proc/cpuinfo | grep "cpu MHz" | head -n1 | cut -d':' -f2 | cut -d' ' -f2)
# Number of Xorg already launch and running.
UNB=$(ps aux | grep Xorg | grep -v grep | wc -l)
# Final calcul of the number of load.
echo "100 * $LOADXX + $Mt + ( $NBCPU * $CPU ) / 100 + $UNB * 100" | bc -q | cut -d. -f1