ABOUT loadavgpct - Linux Load Average Percentage loadavgpct - Linux Load Average Percentage Capacity SYNOPSIS loadavgpct[cap] [LOADAVG_FIELD_1] [LOADAVG_FIELD_2] [COEFFICIENT] EXAMPLE $ loadavgpctcap 1 2 1 $ loadavgpct - - 10
Last active
June 9, 2022 20:05
-
-
Save mjf/eb4dc2d52dfc2cab1961 to your computer and use it in GitHub Desktop.
Linux Load Average Percentage (suitable as HAProxy Agent Check)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# loadavgpct - Linux Load Average Percentage | |
# Copyright (C) 2015 Matous Jan Fialka, <http://mjf.cz/> | |
# Released under the terms of "The MIT License" | |
export LC_ALL=C | |
export LANG=C | |
awk -v A=$1 -v B=$2 -v C=$3 ' | |
BEGIN { | |
A = ((A + 0) == 0) ? 1 : A | |
B = ((B + 0) == 0) ? 2 : B | |
C = ((C + 0) == 0) ? 0 : C | |
N = 0 | |
} | |
(ARGIND == 1) && ($1 == "processor") { | |
N++ | |
} | |
(ARGIND == 2) { | |
A = $A | |
B = $B | |
} | |
END { | |
printf "%d%%\n", (100*(A + B*C))/(A + C*(B + N) + N) | |
} | |
' /proc/cpuinfo /proc/loadavg | |
# vi:ft=sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# loadavgpctcap - Linux Load Average Percentage Capacity | |
# Copyright (C) 2015 Matous Jan Fialka, <http://mjf.cz/> | |
# Released under the terms of "The MIT License" | |
export LC_ALL=C | |
export LANG=C | |
awk -v A=$1 -v B=$2 -v C=$3 ' | |
BEGIN { | |
A = ((A + 0) == 0) ? 1 : A | |
B = ((B + 0) == 0) ? 2 : B | |
C = ((C + 0) == 0) ? 0 : C | |
N = 0 | |
} | |
(ARGIND == 1) && ($1 == "processor") { | |
N++ | |
} | |
(ARGIND == 2) { | |
A = $A | |
B = $B | |
} | |
END { | |
printf "%d%%\n", (100*(C + 1)*N)/(A + C*(B + N) + N) | |
} | |
' /proc/cpuinfo /proc/loadavg | |
# vi:ft=sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service loadavgpct | |
{ | |
disable = no | |
type = UNLISTED | |
protocol = tcp | |
port = 5623 | |
user = root | |
wait = no | |
# server = /usr/local/sbin/loadavgpct | |
server = /usr/local/sbin/loadavgpctcap | |
log_on_success = | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment