-
-
Save m3rlinux/4cb7278e20b488c3d3ca51718513bdce to your computer and use it in GitHub Desktop.
omd tuning script
This file contains hidden or 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
#!/usr/bin/env bash | |
# License: BSD | |
# Author: Florian Heigl (@FlorianHeigl) | |
# Contributors: Davide Gibilisco (@m3rlinux) | |
set -eu | |
# Function to convert bytes to human-readable format | |
human_readable() { | |
awk 'function human_readable(bytes) { | |
if (bytes >= 1099511627776) { | |
suffix = "TB" | |
divisor = 1099511627776 | |
} else if (bytes >= 1073741824) { | |
suffix = "GB" | |
divisor = 1073741824 | |
} else if (bytes >= 1048576) { | |
suffix = "MB" | |
divisor = 1048576 | |
} else if (bytes >= 1024) { | |
suffix = "KB" | |
divisor = 1024 | |
} else { | |
suffix = "B" | |
divisor = 1 | |
} | |
return sprintf("%.2f %s", bytes / divisor, suffix) | |
} | |
{ print human_readable($1) }' | |
} | |
# pull variables if not present | |
SITECFG=~/etc/omd/site.conf | |
if [ -r "$SITECFG" ]; then | |
source "$SITECFG" || true | |
fi | |
# determine total memory (in kilobyte like RSS in ps) | |
MEM_TOTAL=$(free --kilo | awk '/Mem:/ {print $2}') | |
# NET Interfaces | |
ETH_NAMES=($(ip -o link show up | awk '!/lo/ {print $2}' | cut -d ':' -f 1)) | |
# list of test commands | |
tests=( | |
"grep -c ^processor /proc/cpuinfo" # 1 | |
"echo $((MEM_TOTAL * 1024)) | human_readable" # 2 | |
"cat /proc/sys/kernel/pid_max" # 3 | |
"cat /proc/sys/fs/file-max" # 4 | |
"awk '{print \$1}' /proc/sys/fs/file-nr | human_readable" # 5 | |
"df --output=source $OMD_ROOT | grep ^/dev | awk '{print \$4}' | human_readable" # 6 | |
"ps hux -U $OMD_SITE | awk -v total=$MEM_TOTAL '{sum +=\$6} END {printf \"%.2f%%\\n\", sum / total * 100}'" # 7 | |
"ulimit -n" # 8 | |
"ulimit -u" # 9 | |
"lsof -u $OMD_SITE -e /sys/kernel/debug/tracing | wc -l" # 10 | |
"ps -u $OMD_SITE | grep -v 'PID' | wc -l" # 11 | |
"grep ^write_bytes /proc/\$(pgrep -u $OMD_SITE rrdcached)/io | awk '{print \$2}' | human_readable" # 12 | |
"grep ^read_bytes /proc/\$(pgrep -u $OMD_SITE rrdcached)/io | awk '{print \$2}' | human_readable" # 13 | |
"pgrep -u $OMD_SITE checkhelper | wc -l" # 14 | |
"pgrep -u $OMD_SITE -f 'python /omd/sites/$OMD_SITE/bin/cmk --keepalive' | wc -l" # 15 | |
"grep -c 'Resource temp' ~/var/log/cmc.log" # 16 | |
"pgrep -u $OMD_SITE -f 'python /omd/sites/$OMD_SITE/bin/liveproxyd' | wc -l" # 17 | |
"grep -c 'Site is considered dead. Closing all connections.' ~/var/log/liveproxyd.log" # 18 | |
"grep -c -E 'Cannot forward next' ~/var/log/liveproxyd.log" # 19 | |
"curl -s localhost:${CONFIG_APACHE_TCP_PORT}/server-status | grep -E 'requests currently being processed' | sed 's/<dt>//; s/<\/dt>//'" # 20 | |
"grep -c 'WARNING: ping-queueing has lasted' ~/var/log/cmc.log" # 21 | |
) | |
# list of test descriptions | |
messages=( | |
"System: CPU Cores" # 1 | |
"System: Total Memory" # 2 | |
"System: process limit" # 3 | |
"System: file descriptors limit" # 4 | |
"System: opened file descriptors" # 5 | |
"System: OMD_ROOT mount info" # 6 | |
"OMD Site: Total memory used" # 7 | |
"OMD Site: file limit" # 8 | |
"OMD Site: processes limit" # 9 | |
"OMD Site: open files" # 10 | |
"OMD Site: running processes" # 11 | |
"rrdcached: written" # 12 | |
"rrdcached: read" # 13 | |
"CMC: active check workers" # 14 | |
"CMC: check_mk workers" # 15 | |
"CMC: resources exhaustion errors" # 16 | |
"Liveproxyd: processes" # 17 | |
"Liveproxyd: remote site conn dead errors" # 17 | |
"Liveproxyd: remote site query aborted errors" # 18 | |
"Apache: worker usage" # 20 | |
"icmphelper: ping-queue over 100ms errors" # 21 | |
) | |
# Run tests and output values | |
for index in "${!messages[@]}"; do | |
echo "${messages[index]} : $(eval "${tests[index]}")" | |
done | |
# Execute ethtool commands for each network interface | |
for eth in "${ETH_NAMES[@]}"; do | |
echo "$eth - RX buffer size : $(ethtool -g $eth | awk '/Current hardware/{found=1} found && /^RX/{print $2; found=0}')" | |
echo "$eth - NIC out of buffer errors : $(ethtool -S $eth | awk -F":" '/OOB/ {sum += $2} END {print sum}')" | |
echo "$eth - Driver rx/tx drop errors : $(ethtool -S $eth | awk '/drv dropped tx total/ {tx_sum += $NF} /drv dropped rx total/ {rx_sum += $NF} END {print rx_sum"/"tx_sum}')" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@m3rlinux hey thank you, that was a lot of cleanups & improvements!