"Fossies" - the Fresh Open Source Software Archive

Member "unix/plugins/pandora_mem" (17 May 2019, 2479 Bytes) of package /linux/misc/pandorafms_agent_unix-7.0NG.740.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl
    2 
    3 # Pandora FMS Plugin to get memory information on Linux
    4 # (c) 2014 Sancho Lerena <slerena@artica.es
    5 
    6 use POSIX;
    7 
    8 my $TOTAL=`vmstat -s | grep "total memory" | awk  '{ print $1 } '`;
    9 my $FREE=`vmstat -s | grep "free memory" | awk  '{ print $1 } '`;
   10 my $FREEP;
   11 eval {
   12 $FREEP=($FREE/$TOTAL)*100; 
   13 };
   14 if ($@) {
   15     $FREEP = 0;
   16 }
   17 my $STOTAL=`vmstat -s | grep "total swap" | awk  '{ print $1 } '`;
   18 my $SUSED=`vmstat -s | grep "free swap" | awk  '{ print $1 } '`;
   19 my $SFREE;
   20 eval {
   21 $SFREE=($SUSED/$STOTAL)*100;
   22 };
   23 if ($@) {
   24     $SFREE = 0;
   25 }
   26 
   27 $SFREE = floor($SFREE); 
   28 $FREEP = floor($FREEP);
   29 
   30 # Added 30/Dec/2014, slerena
   31 # Available memory as FreeMemory + Cached + SwapCached.
   32 my $freemem=`cat /proc/meminfo | grep 'MemFree' | awk '{ print \$2 } '`;
   33 my $cached=`cat /proc/meminfo | grep '^Cached:' | awk '{ print \$2 } '`;
   34 my $cachedswap=`cat /proc/meminfo | grep '^SwapCached:' | awk '{ print \$2 }'`;
   35 my $total_meminfo=`cat /proc/meminfo | grep 'MemTotal:' | awk '{ print \$2 }'`;
   36 my $available=$freemem+$cached+$cachedswap;
   37 my $available_percent = floor(($available / $total_meminfo)*100);
   38 
   39 
   40 print "<module>\n";
   41 print "<name><![CDATA[FreeMemory]]></name>\n";
   42 print "<type><![CDATA[generic_data]]></type>\n";
   43 print "<description><![CDATA[Free memory %. Note most linux use 99% of available memory by default, check Availablememory module for more accurate information on available physical memory on system]]></description>\n";
   44 print "<unit><![CDATA[%]]></unit>\n";
   45 print "<min_critical><![CDATA[0]]></min_critical>\n";
   46 print "<max_critical><![CDATA[2]]></max_critical>\n";
   47 print "<data><![CDATA[$FREEP]]></data>\n";
   48 print "</module>\n";
   49 
   50 print "<module>\n";
   51 print "<name><![CDATA[FreeSwap]]></name>\n";
   52 print "<type><![CDATA[generic_data]]></type>\n";
   53 print "<description><![CDATA[Free Swap %]]></description>\n";
   54 print "<unit><![CDATA[%]]></unit>\n";
   55 print "<min_critical><![CDATA[0]]></min_critical>\n";
   56 print "<max_critical><![CDATA[5]]></max_critical>\n";
   57 print "<data><![CDATA[$SFREE]]></data>\n";
   58 print "</module>\n";
   59 
   60 print "<module>\n";
   61 print "<name><![CDATA[AvailableMemory]]></name>\n";
   62 print "<type><![CDATA[generic_data]]></type>\n";
   63 print "<description><![CDATA[Available Physical Memory % (Free+Cached+CachedSwap)]]></description>\n";
   64 print "<unit><![CDATA[%]]></unit>\n";
   65 print "<min_critical><![CDATA[0]]></min_critical>\n";
   66 print "<max_critical><![CDATA[10]]></max_critical>\n";
   67 print "<data><![CDATA[$available_percent]]></data>\n";
   68 print "</module>\n";