github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/autoscaling/policy.mdx (about) 1 --- 2 layout: docs 3 page_title: Scaling Policies 4 sidebar_title: Policy 5 description: > 6 Scaling policies describe the target resource desired state and how to 7 perform calculations to ensure the current state reaches the desired. 8 --- 9 10 # Nomad Autoscaler Scaling Policies 11 12 Nomad Autoscaler scaling policies can be configured via the [`scaling` stanza][jobspec_scaling_stanza] 13 or by configuration files stored on disk. The options available differ whether 14 you are performing horizontal application/cluster scaling or Dynamic Application 15 Sizing. 16 17 ## Top Level Options 18 19 - `enabled` - A boolean flag that allows operators to administratively disable a 20 policy from active evaluation. 21 22 - `min` - The minimum running count of the targeted resource. This can be 0 or any 23 positive integer. 24 25 - `max` - The maximum running count of the targeted resource. This can be 0 or any 26 positive integer. 27 28 ## Task Group and Cluster Scaling `policy` Options 29 30 The following options are available when using the Nomad Autoscaler to perform 31 horizontal application scaling or horizontal cluster scaling. 32 33 - `cooldown` - A time interval after a scaling action during which no additional 34 scaling will be performed on the resource. It should be provided as a duration 35 (e.g.: `"5s"`, `"1m"`). If omitted the configuration value 36 [policy_default_cooldown][policy_default_cooldown_agent] from the agent will 37 be used. 38 39 - `evaluation_interval` - Defines how often the policy is evaluated by the 40 Autoscaler. It should be provided as a duration (e.g.: `"5s"`, `"1m"`). If 41 omitted the configuration value [default_evaluation_interval][eval_interval_agent] 42 from the agent will be used. 43 44 - `target` - Defines where the autoscaling target is running. Detailed information 45 on the configuration options can be found on the [Target Plugins][target_plugin_docs] 46 page. 47 48 - `check` - Specifies one or more checks to be executed when determining if a 49 scaling action is required. 50 51 ## `check` Options 52 53 - `source` - The APM plugin that should handle the metric query. If omitted, 54 this defaults to using the Nomad APM. 55 56 - `query` - The query to run against the specified APM. Currently this query 57 should return a single value. Detailed information on the configuration options 58 can be found on the [APM Plugins][apm_plugin_docs] page. 59 60 - `query_window` - Defines how far back to query the APM for metrics. It should 61 be provided as a duration (e.g.: `"5s"`, `"1m"`). Defaults to `1m`. 62 63 - `strategy` - The strategy to use, and it's configuration when calculating the 64 desired state based on the current count and the metric returned by the APM. 65 Detailed information on the configuration options can be found on the 66 [Strategy Plugins][strategy_plugin_docs] page. 67 68 ### Example in a Job 69 70 A full example of a policy document that can be written into the Nomad task group 71 `scaling` stanza can be seen below. 72 73 ```hcl 74 job "example" { 75 group "app" { 76 scaling { 77 min = 2 78 max = 10 79 enabled = true 80 81 policy { 82 evaluation_interval = "5s" 83 cooldown = "1m" 84 85 check "active_connections" { 86 source = "prometheus" 87 query = "scalar(open_connections_example_cache)" 88 89 strategy "target-value" { 90 target = 10 91 } 92 } 93 } 94 } 95 } 96 } 97 ``` 98 99 ### Example in a File 100 101 An example of a policy document that can be placed in a file within the 102 `policy_dir` can be seen below. Multiple policies can be defined in the same 103 file using multiple `scaling` blocks. 104 105 ```hcl 106 scaling "aws_cluster_policy" { 107 enabled = true 108 min = 1 109 max = 2 110 111 policy { 112 cooldown = "2m" 113 evaluation_interval = "1m" 114 115 check "cpu_allocated_percentage" { 116 source = "prometheus" 117 query = "..." 118 119 strategy "target-value" { 120 target = 70 121 } 122 } 123 124 check "mem_allocated_percentage" { 125 source = "prometheus" 126 query = "..." 127 128 strategy "target-value" { 129 target = 70 130 } 131 } 132 133 target "aws-asg" { 134 dry-run = "false" 135 aws_asg_name = "hashistack-nomad_client" 136 node_class = "hashistack" 137 node_drain_deadline = "5m" 138 } 139 } 140 } 141 142 scaling "azure_cluster_policy" { 143 enabled = true 144 min = 1 145 max = 2 146 147 policy { 148 ... 149 target "azure-vmss" { 150 resource_group = "hashistack" 151 vm_scale_set = "clients" 152 node_class = "hashistack" 153 node_drain_deadline = "5m" 154 } 155 } 156 } 157 ``` 158 159 ## Task (DAS) `policy` Options 160 161 <EnterpriseAlert> 162 This functionality only exists in Nomad Autoscaler 163 Enterprise. This is not present in the open source version of Nomad Autoscaler. 164 </EnterpriseAlert> 165 166 The following options are available when using the Nomad Autoscaler Enterprise 167 to perform Dynamic Application Sizing recommendations for task resources. When 168 using the [`scaling` stanza][jobspec_scaling_stanza] for Dynamic Application 169 Sizing, the stanza requires a label to identify which resource it relates to. It 170 currently supports `cpu` and `mem` labels, examples of which can be seen below. 171 172 - `cooldown` - A time interval after a scaling action during which no additional 173 scaling will be performed on the resource. It should be provided as a duration 174 (e.g.: `"5s"`, `"1m"`). If omitted the configuration value 175 [policy_default_cooldown][policy_default_cooldown_agent] from the agent will 176 be used. 177 178 - `evaluation_interval` - Defines how often the policy is evaluated by the 179 Autoscaler. It should be provided as a duration (e.g.: `"5s"`, `"1m"`). If 180 omitted the configuration value [default_evaluation_interval][eval_interval_agent] 181 from the agent will be used. 182 183 - `target` - Defines where the autoscaling target is running. Detailed information 184 on the configuration options can be found on the [Target Plugins][target_plugin_docs] 185 page. 186 187 - `check` - Specifies one check to be executed when determining if a recommendation 188 is required. Only one check is permitted per scaling block within Dynamic 189 Application Sizing. 190 191 ## `check` Options 192 193 - `strategy` - The strategy to use, and it's configuration when calculating the 194 desired state based on the current value and the available historic data. Detailed 195 information on the configuration options can be found on the 196 [Strategy Plugins][strategy_plugin_docs] page. 197 198 ### Example 199 200 The following examples are minimal blocks which can be used to configure CPU and 201 Memory based sizing recommendations for a Nomad job task. 202 203 ```hcl 204 scaling "cpu" { 205 policy { 206 check "96pct" { 207 strategy "app-sizing-percentile" { 208 percentile = "96" 209 } 210 } 211 } 212 } 213 214 scaling "mem" { 215 policy { 216 check "max" { 217 strategy "app-sizing-max" {} 218 } 219 } 220 } 221 ``` 222 223 [policy_default_cooldown_agent]: /docs/autoscaling/agent#default_cooldown 224 [eval_interval_agent]: /docs/autoscaling/agent#default_evaluation_interval 225 [target_plugin_docs]: /docs/autoscaling/plugins/target 226 [strategy_plugin_docs]: /docs/autoscaling/plugins/strategy 227 [apm_plugin_docs]: /docs/autoscaling/plugins/apm 228 [jobspec_scaling_stanza]: /docs/job-specification/scaling