Forum: Cfengine Help Subject: Re: Random variable persistence problem -- crontab randomization Author: Justin Link to topic: https://cfengine.com/forum/read.php?3,20077,20081#msg-20081
I wanted a randomization of calls to a web server and used a dist class. Here's an excerpt from a policy file of ours: #========================================================================= # The "dist" class operator creates probabilistic classes. Given a class # name and a list of numbers, it will always define the base class name # and it will create a class with one of the numbers in the list appended, # based on that number's weight in the whole list. In this case, the # dist_percent class will always be defined, while dist_percent_1 will # be defined 1% of the time (1/(1+99)) and dist_percent_99 will be # defined 99% of the time (99/(1+99)). (The numbers don't need to total # 100. That is just a convenience for this particular case.) #========================================================================= any:: "dist_percent" dist => { "1", "99" }, comment => "Probability distribution class whose values are percentages"; #========================================================================= # Fetch the host's information from Asset Tracker if the cache file does # not exist, the force_asset_fetch class is defined (meaning the external # class file had very recently been created to force the update) or in the # ~1% of cf-agent executions that the dist_percent_1 class (see above) is # defined. Since Cfengine runs every 5 minutes, which is 288 times per day, # on average the dist_percent_1 class will be defined randomly about # 3 (2.88) times per day. This method allows for random retrieval of # asset tracker information to spread the load on the asset tracker web # server. # # This is used mainly for the side effect of the data fetch, rather than # for the actual class definition. However, the class can be used to # implement special logic, if desired, for immediately after the data is # retrieved and locally cached in a file. #========================================================================= asset_command_exists.(!asset_cache_exists|dist_percent_1|force_asset_fetch):: "fetched_asset_data" expression => returnszero( "$(asset_command) -o $(asset_cache_file) data -d '|' -q '' $(sys.uqhost)", "noshell" ), comment => "Fetch asset data and store it in a local cache file."; _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine