---
layout: docs
page_title: 'Autoscaling Plugins: Target Value'
description: The "target-value" strategy plugin tracks a target metric value.
---

# Target Value Strategy Plugin

The `target-value` strategy plugin performs count calculations in order to
keep the value resulting from the APM query at or around a specified target.

It accomplishes this by extrapolating the current metric value and used
capacity linearly to determine if a scaling action is required and how many
instances need to be added or removed. More specify, the new scaling value is
calculated as:

```
factor = current_metric_value / target
new_count = factor * current_count
```

As an example, a policy that tracks memory usage with target defined as `70`
(representing 70% of memory usage) and in a scenario where there are `10`
instances running will generate a scaling action with scaling factor of
`1.1428571429`, which will add `2` new instances when the metric reaches `80`
(80% of memory usage) because:

```
factor = 80/70 = 1.1428571429
new_count = 1.1428571429 * 10 ~= 12
```

In other words, if with 10 instances the memory usage in 80%, it's expected
that with 12 instances the memory usage will be lower and closer to the target
value of 70%.

This means that this strategy expects your infrastructure to have the following
characteristics:

- **inverse relationship** between metric and number of instances, meaning that
  adding _more_ instances will cause your metric value to go _down_.

- **linear response** to infrastructure changes, meaning that a _2x_ increase
  in instance count will cut the metric value approximately in _half_.

~> **Note:** These properties may not be true for your infrastructure. Make
  sure you have a good grasp of your query result dynamic as the number of
  instances changes.

To fine-tune scaling decisions you can adjust the `threshold` configuration.
This value defines a range between `1 ± threshold` where scaling actions with a
scaling factor within this range are ignored. For example, with the default
value of `0.01` only scaling actions with a factor lower than `0.99` and larger
than `1.01` are taken into account.

With a low `threshold` you are expected to observe more scaling actions with
smaller changes, while a high `threshold` value is expected to generate fewer
scaling actions with bigger changes in count.

Since `threshold` is compared against the computed scaling factor, and the
factor is based on your expected metric values and specified `target`,
adjusting the `threshold` value can take some time and a few trial and error
attempts.

## Agent Configuration Options

```hcl
strategy "target-value" {
  driver = "target-value"
}
```

## Policy Configuration Options

```hcl
check "target-value-check" {
  # ...
  strategy "target-value" {
    target    = 20
    threshold = 0.0001
  }
  # ...
}
```

- `target` `(float: <required>)` - Specifies the metric value the Autoscaler
  should try to meet.

- `threshold` `(float: 0.01)` - Specifies how significant a change in the input
  metric should be considered. Small threshold values can lead to output
  fluctuation.
