Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
linux_wiki:xymon_cpu_load_threshold_calc [2016/11/27 00:06] billdozor created |
linux_wiki:xymon_cpu_load_threshold_calc [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Xymon Cpu Load Threshold Calc ====== | + | ====== Xymon CPU Load Threshold Calc ====== |
**General Information** | **General Information** | ||
Line 21: | Line 21: | ||
Installation instructions. | Installation instructions. | ||
- | ===== Client side ===== | + | ===== Xymon Client side ===== |
No client modifications required. | No client modifications required. | ||
- | ===== Server side ===== | + | ---- |
+ | |||
+ | ===== Xymon Server side ===== | ||
- Install the ' | - Install the ' | ||
Line 45: | Line 47: | ||
/ | / | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== The Script ====== | ||
+ | |||
+ | <code bash cpu-load-calc.sh> | ||
+ | #!/bin/bash | ||
+ | # Title: cpu-load-calc.sh | ||
+ | # Description: | ||
+ | # Dependency: Requires ' | ||
+ | # Last Change: 2018-05-22 | ||
+ | # Recent Changes: | ||
+ | |||
+ | # | ||
+ | # Customize Here | ||
+ | # | ||
+ | |||
+ | # Warning and Critical Load Multipliers (num of procs * multiplier) | ||
+ | load_warn_multiplier=1.0 | ||
+ | load_crit_multiplier=1.5 | ||
+ | |||
+ | # Directory to save auto load thresholds | ||
+ | auto_load_dir="/ | ||
+ | |||
+ | # Xymon server' | ||
+ | xymon_hostdata_dir="/ | ||
+ | |||
+ | # Xymon server' | ||
+ | xymon_analysis_cfg="/ | ||
+ | # | ||
+ | # End of Customize | ||
+ | # | ||
+ | |||
+ | # | ||
+ | # Pre-Run Error Checking | ||
+ | # | ||
+ | ## Dependency Check ## | ||
+ | which bc &> /dev/null | ||
+ | if [[ $? -eq 1 ]]; then | ||
+ | echo ">> | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | ## Does the Auto Load Directory exist? | ||
+ | if [[ ! -d ${auto_load_dir} ]]; then | ||
+ | echo ">> | ||
+ | exit | ||
+ | fi | ||
+ | |||
+ | ## Write Access Check | ||
+ | touch ${auto_load_dir}/ | ||
+ | if [[ $? -eq 1 ]]; then | ||
+ | echo ">> | ||
+ | exit 1 | ||
+ | else | ||
+ | rm -f ${auto_load_dir}/ | ||
+ | fi | ||
+ | |||
+ | ## Check if the auto_load_dir is included in main analysis config file | ||
+ | grep " | ||
+ | if [[ $? -eq 1 ]]; then | ||
+ | echo -e ">> | ||
+ | fi | ||
+ | # | ||
+ | # End of Pre-Run Error Checking | ||
+ | # | ||
+ | |||
+ | # | ||
+ | # Functions; Main starts after | ||
+ | # | ||
+ | |||
+ | function show_usage | ||
+ | { | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e "$0 -v => Verbose output." | ||
+ | echo -e "$0 -r => Refresh CPU load data (force hostdata update)." | ||
+ | echo -e "$0 -h => Display usage." | ||
+ | } | ||
+ | |||
+ | # Force snapshots of hostdata | ||
+ | function force_hostdata | ||
+ | { | ||
+ | # Use node name passed as argument | ||
+ | node_name=${1} | ||
+ | |||
+ | # Lie to Xymon that the node's cpu is green, then yellow, forcing a hostdata snapshot | ||
+ | xymon 127.0.0.1 " | ||
+ | xymon 127.0.0.1 " | ||
+ | } | ||
+ | |||
+ | # | ||
+ | # Get Script Arguments | ||
+ | # | ||
+ | # Reset POSIX variable in case it has been used previously in this shell | ||
+ | OPTIND=1 | ||
+ | |||
+ | # By default, no verbose output | ||
+ | verbose_output=" | ||
+ | refresh_cpus=" | ||
+ | |||
+ | while getopts " | ||
+ | case " | ||
+ | h) # -h (help) argument | ||
+ | show_usage | ||
+ | exit 0 | ||
+ | ;; | ||
+ | r) # -r (refersh cpus) argument | ||
+ | refresh_cpus=" | ||
+ | ;; | ||
+ | v) # -v (verbose) argument | ||
+ | verbose_output=" | ||
+ | ;; | ||
+ | *) # invalid argument | ||
+ | show_usage | ||
+ | exit 0 | ||
+ | ;; | ||
+ | esac | ||
+ | done | ||
+ | |||
+ | # | ||
+ | # Main Program | ||
+ | # | ||
+ | echo -e "== Xymon Client Auto Load Thresholds ==" | ||
+ | echo -e "Load Warning Multiplier: ${load_warn_multiplier}" | ||
+ | echo -e "Load Critical Multiplier: ${load_crit_multiplier}" | ||
+ | echo -e " | ||
+ | |||
+ | # For each node reporting host data | ||
+ | for node in $(ls ${xymon_hostdata_dir}); | ||
+ | |||
+ | if [[ ${verbose_output} == " | ||
+ | echo -e " | ||
+ | fi | ||
+ | |||
+ | if [[ ${refresh_cpus} == " | ||
+ | if [[ ${verbose_output} == " | ||
+ | echo -e " | ||
+ | fi | ||
+ | # Force an update of hostdata | ||
+ | force_hostdata ${node} | ||
+ | fi | ||
+ | |||
+ | # Get the number of procs reported from node's most recent host data file | ||
+ | node_num_procs=" | ||
+ | | ||
+ | # If node_num_procs is empty or not a number, move to the next node | ||
+ | if [[ -z ${node_num_procs} || ! ${node_num_procs} =~ [0-9][0-9]* ]]; then | ||
+ | # Did not find ' | ||
+ | |||
+ | if [[ ${verbose_output} == " | ||
+ | echo "-> Warning! Could not find ' | ||
+ | fi | ||
+ | |||
+ | continue | ||
+ | fi | ||
+ | |||
+ | # Calculate the warning and critical load thresholds (normalize as a floating point with bc) | ||
+ | load_warning=$(echo " | ||
+ | load_critical=$(echo " | ||
+ | |||
+ | if [[ ${verbose_output} == " | ||
+ | echo -e "-> Number of Procs: ${node_num_procs}" | ||
+ | echo -e "-> Warning at: ${load_warning}" | ||
+ | echo -e "-> Critical at: ${load_critical}" | ||
+ | echo -e "-> Creating node analysis drop in file..." | ||
+ | fi | ||
+ | |||
+ | # Create analysis drop in file | ||
+ | echo "# ${node}' | ||
+ | echo " | ||
+ | echo " | ||
+ | done | ||
+ | |||
+ | echo -e "\n== Auto Load Thresholds Complete ==" | ||
+ | |||
+ | exit 0 | ||
+ | </ | ||
---- | ---- | ||