-
Notifications
You must be signed in to change notification settings - Fork 5
/
nxcheckload.sample
executable file
·67 lines (53 loc) · 1.7 KB
/
nxcheckload.sample
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
#
# nxcheckload - sample script for calculation of the load for a node.
#
# Version 0.5
#
# Under GPL
#
# Jonathan "Arrouan" ROUZAUD-CORNABAS ([email protected])
#
# Fabian Franz <[email protected]>
#
# 0.5
# - Rewrote huge parts
#
# Change between 0.3 and 0.4
# - Add of TMP_FILE
# - Add of lock file to avoid two run at once.
#
# Change between 0.2 and 0.3
# - SMP support.
#
if [ "$1" != "" ]; then
# Connect to a remote node
# Note: This is a ssh sample, you'll need to tweak it for your setup
# and setup the secret keys for yourself.
#exec $COMMAND_SSH nxcal@"$1" "$PATH_BIN/nxcheckload"
# Note: This is a netcat example. You need to have nxcheckload running through
# netpipes or netcat like follows:
# node1:~$ faucet 9876 -io $PATH_BIN/nxcheckload
#
# Connect to another node running the load-service on some port.
#
#exec $COMMAND_NETCAT "$1" 9876
# Same as loadbalance_rr_random
# pick a node by random.
echo $RANDOM
exit 0
fi
# 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