This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Need help with a Perl script please!

The screenshot shows a default Linux Perl script to monitor disk space for the root partition. Where do I edit the script to point to another partition instead? Specifically either the /boot or /dev/shm partition?


Thanks for any help.

  • Hello,

    Try to use "du" Linux command that summarize disk usage of each FILE, recursively for directories (du - Linux Command - Unix Command) with parameters "-s " (summarize) and "-b" (print size in bytes). I'm not sure, but default value is in kilobytes.

    #!/usr/bin/perl

    @stat=split(" ", `du -sb /boot`);

    $exit=`echo $?`;

    if ($exit == 0) {

        print "Message: Directory size of /boot is $stat[0] B\n";

        print "Statistic: $stat[0]\n";

        exit 0;

    }

    print "Message: ERROR: Check the command (du) syntax in script.\n";

    exit 1;

    I hope that helps.

    Lukas Belza (SolarWinds development)

  • That did not work. See the screenshot of the script output message:

    pastedImage_0.png

    Any idea why it did not work?

  • Please change $stat[3] to $stat[0] (because "du" command returns the disk usage in the first column). Or you can copy and paste my whole script. One note - the original script returns the available space, but my script returns used space by specified directory.

  • OK, that last change at least caused the script to run correctly, but now the statistical result seems to be incorrect. The first screenshot shows the space information for the target node from the NPM node details page, while the second screenshot is the output for the Linux monitor script.

    script1.jpg

    script2.jpg

    Why the discrepancy?

  • Hello,

    The Volumes information is taken from SNMP - it uses hrStorageUsed (1.3.6.1.2.1.25.2.3.1.6) and hrStorageAllocationUnits (1.3.6.1.2.1.25.2.3.1.4) for computing the used space.

    The "du" command returns estimate file space usage (according to documentation). So maybe this information is not accurate or doesn't contain space used by system.

    Unfortunately I'm not Linux expert to answer why there is this discrepancy between data returned by SNMP and data returned by shell command.

    Thanks,

    Lukas Belza

  • There is a great thread started by that might explain the discrepancies you're seeing between the two different methods you're using to collect this information. It can be found here ->

  • SAM 6.3 Beta 2 is now available which includes a Linux Agent for Node, Volume, Interface, and Application monitoring. This agent should address many of the shortcomings associated with monitoring Linux host via SNMP, up to and including properly calculating volume usage statistics referenced in this thread. If you already own Server & Application Monitor and are under active maintenance, you can sign-up to participate in the beta at the link below.