expand filesystem to a fixed free space...

15 views
Skip to first unread message

Xander Cage

unread,
Sep 23, 2020, 4:46:40 AM9/23/20
to help-cfengine

hi,

i use the storage promise to monitor disk space. now i want to make
sure that some volume has always lets say 500MB free, but i could not
see a practical way to do it. i read in the docs of eval that there are
some math functions but i hope there issomething easier.


#
# control bundle
#
bundle agent b0002_system_diskspace {

meta:
"tags" slist => { "itsv" };


methods:
"call_diskspace" usebundle => diskspace,
comment => "monitor system filesystems",
ifvarclass => "SPARE_DAILY";
}

bundle agent diskspace
{
vars:
"disks[root][filesystem]" string => "/";
"disks[root][minfree]" string => "500M";
"disks[root][handle]" string => "system_root_fs_check";
"disks[root][comment]" string => "/ filesystem check";
"disks[root][class]" string => "system_root_full";
"disks[root][expire]" string => "60";

"disks[var][filesystem]" string => "/var";
"disks[var][minfree]" string => "500M";
"disks[var][handle]" string => "var_fs_check";
"disks[var][comment]" string => "/var filesystem check";
"disks[var][class]" string => "var_full";
"disks[var][expire]" string => "60";

"disks[usr][filesystem]" string => "/usr";
"disks[usr][minfree]" string => "1G";
"disks[usr][handle]" string => "usr_fs_check";
"disks[usr][comment]" string => "/usr filesystem check";
"disks[usr][class]" string => "usr_full";
"disks[usr][expire]" string => "60";

"disks[opt][filesystem]" string => "/opt";
"disks[opt][minfree]" string => "1G";
"disks[opt][handle]" string => "opt_fs_check";
"disks[opt][comment]" string => "/opt filesystem check";
"disks[opt][class]" string => "opt_full";
"disks[opt][expire]" string => "60";

"disks[tmp][filesystem]" string => "/tmp";
"disks[tmp][minfree]" string => "1G";
"disks[tmp][handle]" string => "tmp_fs_check";
"disks[tmp][comment]" string => "/tmp filesystem check";
"disks[tmp][class]" string => "tmp_full";
"disks[tmp][expire]" string => "30";

methods:
"disks" usebundle => checkdisk("diskspace.disks");

}

bundle agent checkdisk(d) {
vars:
"disk" slist => getindices("$(d)");

storage:
"$($(d)[$(disk)][filesystem])"
handle => "$($(d)[$(disk)][handle])",
comment => "$($(d)[$(disk)][comment])",
action => if_elapsed("$($(d)[$(disk)][expire])"),
classes => if_notkept("$($(d)[$(disk)][class])"),
volume => min_free_space("$($(d)[$(disk)][minfree])");

reports:

system_root_full::
"Report: / has to little free space.";

var_full::
"Report: /var has to little free space.";

usr_full::
"Report: /usr has to little free space.";

opt_full::
"Report: /opt has to little free space.";

tmp_full::
"Report: /tmp has to little free space.";
}

Nick Anderson

unread,
Sep 24, 2020, 3:22:12 PM9/24/20
to Xander Cage, help-cfengine

Xander Cage writes:

hi,

i use the storage promise to monitor disk space. now i want to make sure that some volume has always lets say 500MB free, but i could not see a practical way to do it. i read in the docs of eval that there are some math functions but i hope there issomething easier.

Hi Christian,

How would you make sure that some volume always has 500MB of free space?

Off the top of my head I can think of 2 relatively easy possibilities.

  1. Pre-fill each partition with 500MB chunks (fallocate or dd). Each time you hit the condition where you have less than desired space, delete a chunk.
  2. Extend the volume each time you hit the condition where you have less than desired space. You might use eval here to calculate how much space you need to add, or you could be simple and just add 500MB each time you hit the condition.

Then I start thinking about more crazy things like unionfs to merge in free space from some place afar but really getting into the rhelm of crazy here.

In either of the relatively simple ways I can think of you are obviously constrained by what was allocated to the host. Either your host is allocated a large PV of which very little is actually used or your filesystem is allocated significant space that you pre-fill with blobs that can be purged to free up space.

Does this help?

– Nick Anderson| Doer of Things | (+1) 785-550-1767 | https://northern.tech

Xander Cage

unread,
Sep 25, 2020, 1:24:07 PM9/25/20
to help-cfengine

Hi Nick,

Option 2 is exactly what i had in mind. As this is AIX and everything is managed through the AIX Volume Manager , so allocation contraints can be disregarded.

I looked at https://github.com/cfengine/masterfiles/blob/master/lib/storage.cf, but could not find evidence where the
 information/value about free space is gathered or is this done in C somewhere in the agent?
I need to know this classes/vars so that i can use eval functions  on it.

wbr

chris

Nick Anderson

unread,
Sep 25, 2020, 1:45:03 PM9/25/20
to Xander Cage, help-cfengine

Xander Cage writes:

Option 2 is exactly what i had in mind. As this is AIX and everything is managed through the AIX Volume Manager , so allocation contraints can be disregarded.

I looked at https://github.com/cfengine/masterfiles/blob/master/lib/storage.cf, but could not find evidence where the information/value about free space is gathered or is this done in C somewhere in the agent? I need to know this classes/vars so that i can use eval functions on it.

Are your reports promises from your policy emitted when the filesystem is too full?

reports:

system_root_full::
"Report: / has to little free space.";

var_full::
"Report: /var has to little free space.";

usr_full::
"Report: /usr has to little free space.";

opt_full::
"Report: /opt has to little free space.";

tmp_full::
"Report: /tmp has to little free space.";

If they are, you should just be able to leverage them with commands promises.

commands:
  var_full::
    "command to extend var +500M";

Storage promises don't define variables about the free space available, they simply check to see if the volume has the free space you want or not and then defines the class. So, if you really want to do math so that you extend volume by 500M-freespace you will need to get the current free space into a var so that you can do the caluclation.

Does that make sense or am I missing something obvious?

Reply all
Reply to author
Forward
0 new messages