bronto has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

I am writing a custom, extensible framework for system monitoring (I am not going to compete with Nagios or Foglight anyway :-).

There are two NFS filesystems that are mounted on a server and I would like to check if the available space falls under a certain amount. Since I would like to do it in the most general way, so that I can reuse my work on other OSs as well, I was looking for a portable way to do it.

I started with Filesystem::Df which seemed the most portable between all solutions I could find with a CPAN search, and it seemed to work fine, until I discovered that it returned no information on the mounted device. This means that if I do $df = df('/mydir') the module handles no mean to check if /mydir was correctly mounted to, say, 10.10.10.10:/export/mydir or not...

I took a look at Filesys::DiskFree, but it uses the approach I don't like: it is an interface to various OSs' df commands.

One solution could be to compare $root = df('/') with $mydir = df('/mydir') and to return a warning if they contain all the same values, but I don't like the approach myself.

Dose someone have any cleaner solution?

Ciao!
--bronto

PS: It seems that df output is the argument of the day today :-)


The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz

Replies are listed 'Best First'.
Re: Portably get disk free information
by Abigail-II (Bishop) on Apr 20, 2004 at 11:07 UTC
    How far does your "other OSses" go? VMS? OS/390? VOS? QNX? Or is it just "Unices" and "Windows"? There's no portable way of finding out the free "disk space" (which is a misnomer, what people actually mean is free space available in a file system), at one level you've got to switch on the OS.

    Having said that, I'd go for 'df', which is available on all Unices, and has been ported to non-Unix systems like Windows as well. Many Unix tools have been ported to systems outside of Windows/Unix as well, including df, although I won't be able to give you a list of the platforms df runs on.

    Abigail

Re: Portably get disk free information
by eserte (Deacon) on Apr 20, 2004 at 15:17 UTC
    I'd always prefer a module solution over directly accessing a system command. So it is easier to create a workaround solution for a platform, which e.g. has another df format or no df at all. I think you should be comfortable with Filesys::DiskFree, and if you ever hit a platform where it does not work you could tell the author about it or provide a patch yourself.

      Well, unfortunately Filesys::DiskFree relies on the underlying df command, so you are indeed accessing a system command that the module is using on your behalf. Moreover, the docs talk about "blocks" when talking about the set method, and "bytes" everywhere else.

      At the moment I can test it just on Linux and Solaris 9, so I can't tell if it always returns sizes in bytes or if it returns sizes in blocks on some OS. Could anybody please test it on some other platform and tell me if it returns blocks instead of bytes somewhere?

      Thanks in advance

      Ciao!
      --bronto


      The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
      --John M. Dlugosz