Skip to content

Instantly share code, notes, and snippets.

@seidler2547
Created March 25, 2021 09:09
Show Gist options
  • Select an option

  • Save seidler2547/762fb4c6d1cfa333f9f730eb017c47ac to your computer and use it in GitHub Desktop.

Select an option

Save seidler2547/762fb4c6d1cfa333f9f730eb017c47ac to your computer and use it in GitHub Desktop.

Revisions

  1. seidler2547 created this gist Mar 25, 2021.
    29 changes: 29 additions & 0 deletions check_mem_full
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/usr/bin/awk -E
    BEGIN {
    while ((getline <"/proc/meminfo") > 0 ) {
    gsub(/:/,"");
    gsub(/\(/,"_");
    gsub(/\)/,"");
    a[$1]=$2;
    u[$1]=toupper($3);
    }
    swapfactor=(ENVIRON["swapfactor"]~/^[0-9]+$/)?ENVIRON["swapfactor"]:0.5;
    critical=(ENVIRON["critical"]~/^[0-9]+$/)?ENVIRON["critical"]:10;
    warning=(ENVIRON["warning"]~/^[0-9]+$/)?ENVIRON["warning"]:20;
    }
    END {
    ma=a["MemAvailable"];
    mt=a["MemTotal"];
    sf=a["SwapFree"];
    if (mt<10000 || ma<10) exit 3;
    mr=100*(ma+(sf*swapfactor))/mt;
    ec=0;
    printf "Memory ";
    if (mr<critical) { printf "CRITICAL"; ec=2; } else
    if (mr<warning) { printf "WARNING"; ec=1; } else
    printf "OK";
    printf ", %.1f%% (%d/%d MB + %d MB swap) available|",(ma*100/mt),(ma/1024),(mt/1024),(sf/1024);
    for (k in a) printf k"="a[k]u[k]";;; ";
    print "";
    exit ec;
    }
    13 changes: 13 additions & 0 deletions check_mem_full.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    object CheckCommand "mem_full" {
    command = [ "/var/lib/nagios/check_mem_full", ]
    env = {
    swapfactor = "$memory_swapfactor$"
    warning = "$memory_warning$"
    critical = "$memory_critical$"
    }
    arguments = {
    }
    vars.memory_swapfactor = ""
    vars.memory_warning = ""
    vars.memory_critical = ""
    }