Skip to main content

Custom Scaling Policies

The default elastic policy scales on CPU. A custom policy lets the Scaler make scaling decisions based on any metric you choose — memory usage, network traffic, disk I/O, request count, queue depth, or any application-specific signal.

With a custom policy, you are responsible for publishing the metric value to each group node. The Scaler reads that value from every node, averages it across the group, and applies your scale-up and scale-down thresholds to the average.

Read Auto Scaling Concepts and Create a Scale Group first — this page builds on the elastic-policy fields described there.


How a Custom Policy Works

  1. You choose a custom policy name (the custom attribute), for example CUSTOM_ATTR or NETWORK_TRAFFIC.
  2. On each node, a script measures the metric and writes the value into that attribute, refreshed periodically by a cron job.
  3. The Scaler reads the attribute from every node, averages it, and compares it against your scale-up and scale-down thresholds.
  4. The attribute must be configured on the node before you capture the saved image, so that every node the Scaler launches publishes the metric automatically.
info

The custom attribute must be configured on the image used to create the scale group. The default value of a custom attribute is 0 until your script writes to it.

Custom Policy Name

Enter the attribute name in the Policy parameter name field when you create or edit an elastic policy. Use a descriptive, uppercase name (letters, digits, and underscores; it must start and end with a letter or digit) — for example MEMORY for memory usage, NETTX for transmitted network traffic, or DISKWRIOPS for disk write operations.

note

Some attributes are reported automatically by the platform and need no script: MEMORY, NETTX, NETRX, DISKWRIOPS, DISKRDIOPS, and DISKWRBYTES. If your custom policy name is one of these, the value is already populated for you. For any other attribute, follow the scripting steps below.

Node Utilization Thresholds

As with the default policy, you set the value that triggers a scale-up (increase cardinality) and the value that triggers a scale-down (decrease cardinality), plus the watch period, period duration, and cooldown. Scaling is evaluated on the average value of the attribute across the group.


Set a Custom Attribute on a Node

Suppose you set the custom policy name to CUSTOM_ATTR, with a scale-up threshold of 60 and a scale-down threshold of 30. The Scaler adds a node when the average CUSTOM_ATTR exceeds 60 and removes one when it drops below 30. The example below tracks memory-utilization percentage in CUSTOM_ATTR.

  1. Create a new node and connect to it over SSH.
  2. Add a measurement script (below) to the node.
  3. Schedule the script with cron so the attribute refreshes continuously.

The script needs three values, all found in /var/run/one-context/one_env:

  • ONEGATE_ENDPOINT
  • TOKENTXT
  • VMID

Create the Script

Create a file such as file_name.sh. Use either of the following two approaches.

Option 1 — publish via the OneGate endpoint

TMP_DIR=`mktemp -d`
echo "" > $TMP_DIR/metrics

MEM_TOTAL=`grep MemTotal: /proc/meminfo | awk '{print $2}'`
MEM_FREE=`grep MemFree: /proc/meminfo | awk '{print $2}'`
MEM_USED=$(($MEM_TOTAL-$MEM_FREE))
MEM_USED_PERC="0"

if ! [ -z $MEM_TOTAL ] && [ $MEM_TOTAL -gt 0 ]; then
MEM_USED_PERC=`echo "$MEM_USED $MEM_TOTAL" | \
awk '{ printf "%.2f", 100 * $1 / $2 }'`
fi

CUSTOM_ATTR=$MEM_USED_PERC

echo "CUSTOM_ATTR = $CUSTOM_ATTR" >> $TMP_DIR/metrics

VMID=$(source /var/run/one-context/one_env; echo $VMID)
ONEGATE_ENDPOINT=$(source /var/run/one-context/one_env; echo $ONEGATE_ENDPOINT)
ONEGATE_TOKEN=$(source /var/run/one-context/one_env; echo $TOKENTXT)

curl -X "PUT" $ONEGATE_ENDPOINT/vm \
--header "X-ONEGATE-TOKEN: $ONEGATE_TOKEN" \
--header "X-ONEGATE-VMID: $VMID" \
--data-binary @$TMP_DIR/metrics

Option 2 — publish with the onegate CLI

MEM_TOTAL=`grep MemTotal: /proc/meminfo | awk '{print $2}'`
MEM_FREE=`grep MemFree: /proc/meminfo | awk '{print $2}'`
MEM_USED=$(($MEM_TOTAL-$MEM_FREE))
MEM_USED_PERC="0"

if ! [ -z $MEM_TOTAL ] && [ $MEM_TOTAL -gt 0 ]; then
MEM_USED_PERC=`echo "$MEM_USED $MEM_TOTAL" | \
awk '{ printf "%.2f", 100 * $1 / $2 }'`
fi

VMID=$(source /var/run/one-context/one_env; echo $VMID)

onegate vm update $VMID --data CUSTOM_ATTR=$MEM_USED_PERC

Make the Script Executable and Run It

chmod +x file_name.sh
./file_name.sh

Schedule It with Cron

For continuous monitoring, run the script on a schedule:

crontab -e

Add a line that runs the script at the interval you want (here, every minute):

* * * * * /root/file_name.sh

Build the Image and Launch the Scale Group

  1. After the script and cron are in place and working, save an image from the node.
  2. Create a scale group from that image, choosing Custom as the elastic policy parameter type and entering the same attribute name (CUSTOM_ATTR) you used in the script.

The Scaler will now watch the average CUSTOM_ATTR across the group and scale according to the increment and decrement thresholds you defined.


Update a Custom Value with cURL

Each scale group with a custom policy exposes a cURL command you can call from scripts, cron jobs, or webhooks to push a metric value. Open the Scale Group Details tab and select Get cURL in the Elastic Policy panel.


Inspect the Attribute on a Node

To confirm an attribute is set, run on the node:

onegate vm show VMID --json

The output includes your attribute under USER_TEMPLATE, for example:

{
"VM": {
"NAME": "machine_name",
"ID": "machine_id",
"STATE": "machine_state",
"LCM_STATE": "machine_lcm_state",
"USER_TEMPLATE": {
"CUSTOM_ATTR": "set_attribute",
...
},
...
}
}

To find the VM ID, run:

onegate vm show
VM 8
NAME : web_0_(service_1)
STATE : RUNNING
IP : 192.168.122.23

ResourceUse it for
Auto Scaling ConceptsPolicy terminology and how thresholds work.
Create a Scale GroupWhere to enter the custom policy name.
Scale Group Details and EditingGet the cURL command and edit the policy.
Node ImagesCapture the saved image with your script baked in.

Last updated on June 9, 2026.