Search code examples
monit

Script to update Monit config based on amount of processors


I am wanting to build a script to install a monit config to monitor load avg on a server. Is there a way to say "Use this threshold if the server has 1 CPU or use this threshold if the server has 2 CPU's? I have roughly 24 servers and adding more every day that I would love to just install the file and it adapts to the server or if a server is upgraded to have more CPU's. Any ideas? Thanks


Solution

  • Just see the latest release notes on Monit 5.26.0. There is a new option to check per Core.

    if loadavg(1m) per core > 2 then alert
    if loadavg(1m) > 8 then alert # same test on a 4 core system
    if loadavg(1m) > 18 then alert # same test on a 9 core system
    

    The only problem is that most OS' Repo will not provide a version that recent. So you might end up compiling it your own or the create the config-file with a bash script like

    #!/usr/bin/env bash
    
    # Integers only!
    percore=2
    
    cores=$(grep processor /proc/cpuinfo | wc -l)
    load=$(expr $cores \* $percore)
    
    echo "if loadavg(1m) > ${load} then alert" >> myMonitRcTemporaryFile
    

    this - for sure - will not react if CPUs are added (like in a VM)...