Need an action script to check free disk space and apply cache setting of relay to become 50 GB

HI All, I need to make a fixlet and run it as a policy action on relays (by property) which will find the free space more than 20%

exists drive whose (type of it = “DRIVE_FIXED” AND (free space of it * 100 / total space of it) < 20)

and can deploy the relay cache setting to be 50 GB.

Please suggest.

Thank you!!

This is a more complex ask than it appears at first…

  • Only check the drive that is used for the BES Relay cache. Free space on “C:” doesn’t help if BESRelay is installed on “D:” for example.
  • Consider that some portion of the used space on disk, is being used by existing Relay cache files. So the calculation is really something along the lines of

((free space + Relay used space) * 100 ) / total space < 20

and also a check for the absolute space. Having 20% free of a 1 GB drive doesn’t mean we should apply a 50 GB cache.

I do have something very similar I built, you should be able to modify the following for your needs.

The basic idea is
Cache Limit = (Free space of drive + Cache Used on Drive) - (Desired Free Space)

I define a “maximum free space” (if there’s more free space, make the cache bigger); “minimum free space” (if there’s less free, make the cache smaller); and an “optimum free space” (when we resize, resize to this value).

In the following, assume we want a maximum of 20 GB of free space on the disk, a minimum of 10 GB of free space, and when we reset the cache size we reset it to 15 GB of free space (if the relay cache were to fill).

We want a range between the optimal value, and the max/min value, so we aren’t constantly changing the cache size by very small increments if a few MB frees up on the disk.

20/15/10

Relevance:

not exists ( value of setting "_BESGather_Download_CacheLimitMB" of client as integer , maximum of (item 3 of it; item 0 of it * 1024) , maximum of (item 3 of it; item 1 of it * 1024) , maximum of (item 3 of it; item 2 of it * 1024) ) whose (item 0 of it <= item 1 of it and item 0 of it >= item 3 of it) of ( item 0 of it + item 1 of it - item 2 of it , item 0 of it + item 1 of it - item 3 of it , item 0 of it + item 1 of it - item 4 of it , item 5 of it ) of ( item 1 of it , item 2 of it , maximum of (item 0 of it * 10 / 100 ; 10 ) , maximum of (item 0 of it * 15 / 100 ; 15 ) , maximum of (item 0 of it * 20 / 100 ; 20 ) , 8192 ) of ( total space of drive of it / 1024 / 1024 / 1024 , free space of drive of it / 1024 / 1024 / 1024 , sum of sizes of files of it / 1024 / 1024 / 1024 ) of folder "bfmirror/downloads/sha1" of folder(value of setting "_BESRelay_HTTPServer_ServerRootPath" of client as string)

ActionScript:

setting "_BESGather_Download_CacheLimitMB"="{item 1 of ( maximum of (item 3 of it; item 0 of it * 1024) /* max acceptable cache value */ , maximum of (item 3 of it; item 1 of it * 1024) /* optimum cache value */ , maximum of (item 3 of it; item 2 of it * 1024) /* minimum acceptable cache value */) of (item 0 of it + item 1 of it - item 2 of it /* free space + cache used - min free space */ , item 0 of it + item 1 of it - item 3 of it /* free space + cache used - opt free space */ , item 0 of it + item 1 of it - item 4 of it /* free space + cache used - max free space */ , item 5 of it) of (/* actual free */ item 1 of it , /* cache used */ item 2 of it , /*min free */ maximum of (item 0 of it * 10 / 100 ; 10 /* at least 10% or 10 GB free */) , /*opt free */ maximum of (item 0 of it * 15 / 100 ; 15 /* optimum 15% or 15 GB free */) , /*max free */ maximum of (item 0 of it * 20 / 100 ; 20 /* maximum 20% or 20 GB free */) , 8192 /* minimum relay cache size - for safety don't use negative values or anything below this in MB */) of (total space of drive of it / 1024 / 1024 / 1024 , free space of drive of it / 1024 / 1024 / 1024 , sum of sizes of files of it / 1024 / 1024 / 1024 ) of folder "bfmirror/downloads/sha1" of folder(value of setting "_BESRelay_HTTPServer_ServerRootPath" of client as string)}" on "{now}" for client

3 Likes

Thanks a LOT Jason for your time and effort in answering my querry. :slight_smile:

1 Like

If you are using Windows then you can use the service inspector and get the image path then https://developer.bigfix.com/relevance/reference/service.html#image-path-of-service-string to find the path. In 10.0 we also added folder of to make it easier (though its not in the docs yet it seems)

1 Like