Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Detecting free disk space by percentage?

0 views
Skip to first unread message

Hugo Gayosso

unread,
Apr 8, 2002, 3:19:38 PM4/8/02
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


I am aware of:

disks:

/filesystem freespace=size-limit define=class-list(,:.)


But I would like to check if I have 20% of my disk free instead of
761044 kbytes, because when I add more space to that partition I don't
want to recalculate how many bytes are 20% of the new assigned space.

The other option would be to run a shell script that gives me that
information (actually I am thinking on using check_disk from
Netsaint), but maybe this is an undocumented feature of cfengine :-),
so I decided to ask first.


Greetings,
- --
Hugo Gayosso
Support the Free Software Movement!
GNU Project <http://www.gnu.org>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8se1Kx2JZtTN6co8RAqzrAJ4z8QjUPlR8O4CqrKDSlOeG/gj6ZwCg1ppG
J4I+9U19IR+oJWewnA0/yHc=
=/Fcr
-----END PGP SIGNATURE-----

Hugo Gayosso

unread,
Apr 8, 2002, 4:36:47 PM4/8/02
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Ok, I think I found it as an undocumented feature.

Looking at the source of the function CheckFreeSpace:


if (kilobytes < 0) /* percentage */
{
free = GetDiskUsage(file,cfpercent);
kilobytes = -1 * kilobytes;
if (free < kilobytes)
{
snprintf(OUTPUT,bufsize*2,"Free disk space is under %d%% for partition\n",kilobytes);
CfLog(cfinform,OUTPUT,"");
snprintf(OUTPUT,bufsize*2,"containing %s (%d%% free)\n",file,free);
CfLog(cfinform,OUTPUT,"");
return false;
}
}


it seems that if I use a negative number when defining 'freespace',
cfengine will take it as a percentage instead of Kilobytes.

Mark, why were you hiding this gold nugget from us? :-)

I test it:

# Temporary test
disks:
myhost::
/tmp freespace=5000000 define=Fulltmp
/var freespace=-90 define=Fullvar

shellcommands:
myhost.Fulltmp::
"/bin/echo /tmp full !!"

myhost.Fullvar::
"/bin/echo /var full !!"


But when I try to use it, cfengine complains:

disk/required size attribute with silly value (must be > 0)

Which can be found in the function: HandleRequiredSize

if (i < 1)
{
yyerror("disk/required size attribute with silly value (must be > 0)");
}


So, how can use that undocumented feature? (or what are the reasons I
shouldn't be using it?)


Greetings,
- --
Hugo Gayosso
Support the Free Software Movement!
GNU Project <http://www.gnu.org>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8sf9ex2JZtTN6co8RAuRaAKDTteoDHamvQOELIq74BURAM3JBngCg+M4p
JfI4jMTMP227O1ofVtU/hr4=
=eD1k
-----END PGP SIGNATURE-----

Bas van der Vlies

unread,
Apr 9, 2002, 3:18:01 AM4/9/02
to
You must use the % sign (Inside the function it is a negative number to
distinquish between kb and %)

/home freespace=10%

> _______________________________________________
> Help-cfengine mailing list
> Help-c...@gnu.org
> http://mail.gnu.org/mailman/listinfo/help-cfengine

--
********************************************************************
* *
* Bas van der Vlies e-mail: ba...@sara.nl *
* SARA - Academic Computing Services phone: +31 20 592 8012 *
* Kruislaan 415 fax: +31 20 6683167 *
* 1098 SJ Amsterdam WWW: www.sara.nl *
* *
********************************************************************

Hugo Gayosso

unread,
Apr 9, 2002, 11:04:53 AM4/9/02
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bas van der Vlies <ba...@sara.nl> writes:

> You must use the % sign (Inside the function it is a negative number to
> distinquish between kb and %)
>
> /home freespace=10%

[...]

Ah!! (or should I say Duh! :-) )

Thanks!, so I guess I found another documentation bug, I will send a
bug report.


Greetings,
- --
Hugo Gayosso
Support the Free Software Movement!
GNU Project <http://www.gnu.org>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8swMVx2JZtTN6co8RAtLdAKDvt8jRg7xjfx+ntsaCA6oh/cI2iQCfZ5xE
3djmjiZwy3+7ToEElUF6dZU=
=e/2L
-----END PGP SIGNATURE-----

Hugo Gayosso

unread,
Apr 9, 2002, 12:53:03 PM4/9/02
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bas van der Vlies <ba...@sara.nl> writes:

> You must use the % sign (Inside the function it is a negative number to
> distinquish between kb and %)
>
> /home freespace=10%

[...]

Ok, I tried it and it works, as long as the directory is directly
under '/'.

So, for:

Filesystem 1k-blocks Used Available Use% Mounted on
/dev/sda2 350007 93964 237970 29% /
/dev/sda1 23302 4817 17282 22% /boot
/dev/vg00/lvol00 511980 41904 470076 9% /tmp
/dev/vg00/lvol01 511980 101268 410712 20% /var
/dev/vg00/lvol02 3145628 1809296 1336332 58% /usr
/dev/vg01/lvol00 4194172 2799244 1394928 67% /home

I can NOT use it to check '/home', '/tmp', and so on.

I can use it to check: '/', or '/etc'.

I guess it is getting trapped at function: CheckFreeSpace


if (IsMountedFileSystem(&statbuf,file,1)) /* only do this on server */
{
return true;
}


Running cfagent in debug mode "-d0", I think it is confirmed:

Filesystem /home looks sensible
[/home is on a different file system, not descending]
Free space above -95, defining


Notice that '/home' is NOT above 95% free space.

Any ideas?

- --
Hugo Gayosso
Support the Free Software Movement!
GNU Project <http://www.gnu.org>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8sxxvx2JZtTN6co8RAnGEAJ4guvRU9EgffPADxSiucWu5Y3ts2QCfZ9N/
dnUWJsRxYUM/gruIOvLPJUY=
=Gxjr
-----END PGP SIGNATURE-----

Bas van der Vlies

unread,
Apr 9, 2002, 2:45:33 PM4/9/02
to

I had the same problem. I solved it by creating a directory beneath
/home, namely cfengine and then it works. I know it is a ugly
construction and i think it is a bug! You must also set some
cfengine variables else cfengine thinks it is not a 'sensible' directory.

/home/cfengine freespace=10%

Hugo Gayosso

unread,
Apr 11, 2002, 10:57:59 AM4/11/02
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ba...@sara.nl (Bas van der Vlies) writes:

> I had the same problem. I solved it by creating a directory beneath
> /home, namely cfengine and then it works. I know it is a ugly
> construction and i think it is a bug! You must also set some
> cfengine variables else cfengine thinks it is not a 'sensible' directory.
>
> /home/cfengine freespace=10%

[...]

Thanks!, some comments, though:

I tried it and it almost work, I think it is a bug too
because even if you are checking inside that directory, it doesn't
change the fact that is "mounted" per cfengine definitions.


Now, I say it almost work, because I tried setting:

sensiblesize = ( 0 )
sensiblecount = ( 0 )

but, sensiblecount has to be ' > 0 ' (per install.c)

case cfscount:
sscanf(value,"%d",&number);
if (number > 0)
{
SENSIBLEFILECOUNT = number;
}
else
{
yyerror("Silly value for sensiblecount (must be positive integer)");
}

break;


so if I just create the directory, but don't place any
files/directories inside it, it won't be sensible for cfengine.

cfengine:myhost: Filesystem /home/.cfengine_freespace has only 0 files/directories.
cfengine:myhost: The file /home/.cfengine_freespace does not exist or is suspicious.


Did you changed the source code to fix this?


The other option is to put some stuff inside the directory (I used
'copy' to put a file there), that way cfengine is satisfied, but if
you want to check a lot of filesystems, then you have to do this for
each one, and your config file grows a lot, I tried using iterating
over a list (i.e. var = (home:tmp:usr)) , but it doesn't work for all
the commands involved in this operation (i.e. directories, copy,
disks).

Thanks for your help.

Greetings,


- --
Hugo Gayosso
Support the Free Software Movement!
GNU Project <http://www.gnu.org>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8taR3x2JZtTN6co8RAivmAKDTDi2HUtOcyhCCCjIjf0Q3oLrGugCfQ+Cs
yedr7snbZ5nJMNrOCvCz7Dw=
=YF2L
-----END PGP SIGNATURE-----

Bas van der Vlies

unread,
Apr 12, 2002, 3:31:48 AM4/12/02
to
I use the same solution as you have discovered.I put one file in the
directoryto overcome this. So for every filesystem that i checked on freespace
i must create a directory and one file in it!! This is not desirable.

Regards

0 new messages