Using the App Autoscaler CLI

This topic explains how to use the App Autoscaler command-line interface (CLI).

The App Autoscaler automatically scales Cloud Foundry apps in response to demand. The App Autoscaler CLI lets you control the App Autoscaler from your local command line by extending the Cloud Foundry command-line interface (cf CLI).

To use the App Autoscaler CLI, you must first install the App Autoscaler CLI plugin.

Install the App Autoscaler CLI Plugin

Before you can run App Autoscaler CLI commands on your local machine, you must install the App Autoscaler CLI plugin.

To install the plugin, do the following:

  1. Download the plugin from Pivotal Network.

  2. Run the following command:

    cf install-plugin LOCATION-OF-PLUGIN
    

    Where LOCATION-OF-PLUGIN is the path to the binary file you downloaded from Pivotal Network. For example:

    $ cf install-plugin ~/Downloads/autoscaler-for-pcf-cliplugin-macosx64-binary-2.0.91
    

Create and Bind the Autoscaling Service

Before you can use the App Autoscaler, you must create an Autoscaling service and bind that service to your app. See the Managing Service Instances with the cf CLI topic for more information.

View Apps

Run cf autoscaling-apps to view all the apps that are bound to an autoscaler service instance in a space, their instance limits, and whether or not they are enabled.

$ cf autoscaling-apps
Presenting autoscaler apps in org my-org / my-space autoscaling as user Name Guid Enabled Min Instances Max Instances test-app guid true 1 4 test-app-2 guid-2 false 10 40 OK

Update Instance Limits

Run cf update-autoscaling-limits APP-NAME MIN-INSTANCE-LIMIT MAX-INSTANCE-LIMIT to update the upper and lower app instance limits. The App Autoscaler does not scale beyond these limits. Replace APP-NAME with the name of your app. Replace MIN-INSTANCE-LIMIT with the minimum number of apps, and MAX-INSTANCE-LIMIT with the maximum number of apps.

$ cf update-autoscaling-limits test-app 10 40
Updated autoscaling instance limits for app test-app for org my-org / my-space testing as admin OK

Enable Autoscaling

Run cf enable-autoscaling APP-NAME to enable autoscaling on your app. Replace APP-NAME with the name of your app.

$ cf enable-autoscaling test-app-2
Enabled autoscaling for app test-app-2 for org my-org / my-space testing as admin OK

Note: By default, instance limits are set to Min Instances:-1 and Max Instances:-1. To enable autoscaling, you must first Update Instance Limits.

Disable Autoscaling

Run cf disable-autoscaling APP-NAME to disable autoscaling on your app. Replace APP-NAME with the name of your app.

$ cf disable-autoscaling test-app
Disabled autoscaling for app test-app for org my-org / my-space testing as admin OK

View Rules

Run cf autoscaling-rules APP-NAME to view the rules that the App Autoscaler uses to determine when to scale your app. Replace APP-NAME with the name of your app.

$ cf autoscaling-rules test-app
Presenting autoscaler rules for app test-app for org my-org / my-space autoscaling as user Rule Guid Rule Type Rule Sub Type Min Threshold Max Threshold guid cpu 10 20 guid-2 http_throughput 20 30 OK

Create a Rule

Run create-autoscaling-rule APP-NAME RULE-TYPE MIN-THRESHOLD MAX-THRESHOLD [--subtype SUBTYPE] [--metric METRIC] [--comparison-metric COMPARISON-METRIC] to create a new autoscaling rule.

Replace the placeholders as follows:

  • APP-NAME is the name of your app.
  • RULE-TYPE is the type of your scaling rule.
  • MIN-THRESHOLD is the minimum threshold for the metric.
  • MAX-THRESHOLD is the maximum threshold for the metric.

You can use the following command options:

  • --metric, -m is the metric for a Custom rule.
  • --comparison-metric, -c is the comparison metric for a Compare rule.
  • --subtype, -s is the rule subtype.
$ cf create-autoscaling-rule test-app http_latency 10 20 -s avg_99th
Created autoscaler rule for app test-app for org my-org / space my-space as user Rule Guid Rule Type Rule Sub Type Min Threshold Max Threshold guid-3 http_latency avg_99th 10 20

Valid Rule Types and Subtypes

For a list of valid types and subtypes, see the following:

  • type CPU
  • type memory
  • type http_throughput
  • type http_latency
    • sub_type avg_99th or avg_95th

      Note: http_latency requires a rule subtype.

      Note: http_latency threshold units are in ms.

  • type rabbit-mq
    • queue_name YOUR-QUEUE-NAME
  • type custom
    • metric METRIC-NAME
  • type compare
    • metric METRIC-NAME
    • comparison_metric METRIC-NAME

Delete a Rule

Run delete-autoscaling-rule APP-NAME RULE-GUID [--force] to delete a single autoscaling rule. Replace APP-NAME with the name of your app, and replace RULE-GUID with the GUID.

$ cf delete-autoscaling-rule test-app guid-2
Really delete rule guid-2 for app test-app?> [yN]:y Deleted rule guid-2 for autoscaler app test-app for org my-org / space my-space as admin OK

Delete All Rules

Run delete-autoscaling-rules APP-NAME [--force] to delete all autoscaling rules. Replace APP-NAME with the name of your app.

$ cf delete-autoscaling-rules test-app
Really delete ALL rules for app test-app?> [yN]:y Deleted rules for autoscaler app test-app for org my-org / space my-space as admin OK

View Autoscaling Events

Run cf autoscaling-events APP-NAME to view recent events related to autoscaling for your app. Replace APP-NAME with the name of your app.

$ cf autoscaling-events test-app
Time Description 2032-01-01T00:00:00Z Scaled up from 3 to 4 instances. Current cpu of 20 is above upper threshold of 10.

Configure with a Manifest

Run configure-autoscaling APP-NAME MANIFEST-FILE-PATH to use a service manifest to configure your rules, add instance limits, and set scheduled limit changes at the same time. Replace APP-NAME with the name of your app, and replace MANIFEST-FILE-PATH with the path and name of your Autoscaler manifest.

An example manifest:

  ---
  instance_limits:
    min: 1
    max: 2
  rules:
    - rule_type: "http_latency"
      rule_sub_type: "avg_99th"
      threshold:
        min: 10
        max: 20
  scheduled_limit_changes:
    - recurrence: 10
      executes_at: "2032-01-01T00:00:00Z"
      instance_limits:
        min: 10
        max: 20
$ cf configure-autoscaling test-app autoscaler-manifest.yml
Setting autoscaler settings for app test-app for org my-org / space my-space as user OK

A scheduled_limit_changes block must be present in your Autoscaler manifest. If your app does not require any scheduled instance limit changes, include an empty block:

  ---
  instance_limits:
    min: 1
    max: 2
  rules:
    - rule_type: "http_latency"
      rule_sub_type: "avg_99th"
      threshold:
        min: 10
        max: 20
  scheduled_limit_changes: []

App Autoscaler CLI Known Issues

The App Autoscaler CLI has the following known issues:

  • The CLI returns an error message if you have more than one instance of the App Autoscaler service running in the same space.

    • To prevent this error, delete all but one App Autoscaler service instance from any space that the App Autoscaler service runs in.
  • The CLI may output odd characters in Windows shells that do not support text color.

    • To prevent this error, run SET CF_COLOR=false in your Windows shell pane before you run App Autoscaler CLI commands. But note that some Windows shells do not support the CF_COLOR setting.