Code Monkey home page Code Monkey logo

app-autoscaler-cli-plugin's Introduction

Cloud Foundry CLI AutoScaler Plug-in Build Status

App-AutoScaler plug-in provides the command line interface to manage App AutoScaler policies, retrieve metrics and scaling event history.

Install plugin

From CF-Community

cf install-plugin -r CF-Community app-autoscaler-plugin

From source code

$ git clone [email protected]:cloudfoundry-incubator/app-autoscaler-cli-plugin.git
$ cd app-autoscaler-cli-plugin
$ git submodule update --init --recursive
$ make build
$ cf install-plugin out/ascli

Uninstall plugin

cf uninstall-plugin AutoScaler

Command List

Command Description
autoscaling-api, asa Set or view AutoScaler service API endpoint
autoscaling-policy, asp Retrieve the scaling policy of an application
attach-autoscaling-policy, aasp Attach a scaling policy to an application
detach-autoscaling-policy, dasp Detach the scaling policy from an application
create-autoscaling-credential, casc Create custom metric credential for an application
delete-autoscaling-credential, dasc Delete the custom metric credential of an application
autoscaling-metrics, asm Retrieve the metrics of an application
autoscaling-history, ash Retrieve the scaling history of an application

Command usage

cf autoscaling-api

Set or view AutoScaler service API endpoint. If the CF API endpoint is https://api.example.com, then typically the autoscaler API endpoint will be https://autoscaler.example.com. Check the manifest when autoscaler is deployed to get the autoscaler service API endpoint.

cf autoscaling-api [URL] [--unset] [--skip-ssl-validation]

ALIAS: asa

OPTIONS:

  • --unset: Unset the api endpoint
  • --skip-ssl-validation : Skip verification of the API endpoint. Not recommended!

EXAMPLES:

  • Set AutoScaler API endpoint, replace DOMAIN with the domain of your Cloud Foundry environment:
$ cf autoscaling-api https://autoscaler.<DOMAIN>
Setting AutoScaler api endpoint to https://autoscaler.<DOMAIN>
OK
  • View AutoScaler API endpoint:
$ cf autoscaling-api
Autoscaler api endpoint: https://autoscaler.<DOMAIN>
  • Unset AutoScaler API endpoint:

Note you will get a error prompt if the AutoScaler API endpoint is not set when you execute other commands.

$ cf autoscaling-api --unset
Unsetting AutoScaler api endpoint.
OK

$ cf autoscaling-api
No api endpoint set. Use 'cf autoscaling-api' to set an endpoint.

$ cf autoscaling-policy APP_NAME
FAILED
Error: No api endpoint set. Use 'cf autoscaling-api' to set an endpoint.

cf autoscaling-policy

Retrieve the scaling policy of an application, the policy will be displayed in JSON format.

cf autoscaling-policy APP_NAME [--output PATH_TO_FILE]

ALIAS: asp

OPTIONS:

  • --output : dump the policy to a file in JSON format

EXAMPLES:

  • View scaling policy, replace APP_NAME with the name of your application:
$ cf autoscaling-policy APP_NAME

Showing policy for app APP_NAME...
{
	"instance_min_count": 1,
	"instance_max_count": 5,
	"scaling_rules": [
		{
			"metric_type": "memoryused",
			"breach_duration_secs": 120,
			"threshold": 15,
			"operator": ">=",
			"cool_down_secs": 120,
			"adjustment": "+1"
		},
		{
			"metric_type": "memoryused",
			"breach_duration_secs": 120,
			"threshold": 10,
			"operator": "<",
			"cool_down_secs": 120,
			"adjustment": "-1"
		}
	]
}
  • Dump the scaling policy to a file in JSON format:
$ cf asp APP_NAME --output PATH_TO_FILE

Saving policy for app APP_NAME to PATH_TO_FILE...
OK

cf attach-autoscaling-policy

Attach a scaling policy to an application, the policy file must be a JSON file, refer to policy specification for the policy format.

cf attach-autoscaling-policy APP_NAME PATH_TO_POLICY_FILE

ALIAS: aasp

EXAMPLES:

$ cf attach-autoscaling-policy APP_NAME PATH_TO_POLICY_FILE

Attaching policy for app APP_NAME...
OK

cf detach-autoscaling-policy

Detach the scaling policy from an application, the policy will be deleted when detached.

cf detach-autoscaling-policy APP_NAME

ALIAS: dasp

EXAMPLES:

$ cf detach-autoscaling-policy APP_NAME

Detaching policy for app APP_NAME...
OK

cf create-autoscaling-credential

Credential is required when submitting custom metrics to app-autoscaler. If an application is connecting to autoscaler through a service binding approach, the required credential could be found in Cloud Foundry VCAP_SERVICES environment variables. Otherwise, you need to generate the required credential explicitly with this command.

The command will generate autoscaler credential and display it in JSON format. Then you need to set this credential to your application through environment variables or user-provided-service.

Note: Auto-scaler only grants access with the most recent credential, so the newly generated credential will overwritten the old pairs. Please make sure to update the credential setting in your application once you launch the command create-autoscaling-credential.

Random credential pair will be created by default when username and password are not specified by --username and --password option.

cf create-autoscaling-credential APP_NAME [--username USERNAME --password PASSWORD] [--output PATH_TO_FILE]

ALIAS: casc

OPTIONS:

  • --username, -u : username of the custom metric credential, random username will be set if not specified
  • --password, -p : password of the custom metric credential, random password will be set if not specified
  • --output : Dump the credential to a file in JSON format

EXAMPLES:

  • Create and view custom credential with user-defined username and password:
$ cf create-autoscaling-credential APP_NAME --username MY_USERNAME --password MY_PASSWORD

Creating custom metric credential for app APP_NAME...
{
	"app_id": "<APP_ID>",
	"username": "MY_USERNAME",
	"password": "MY_PASSWORD",
	"url": "https://autoscalermetrics.<DOMAIN>"
}
  • Create random username and password and dump the credential to a file:
$ cf create-autoscaling-credential APP_NAME --output PATH_TO_FILE

Saving new created credential for app APP_NAME to PATH_TO_FILE...
OK

cf delete-autoscaling-credential

Delete the custom metric credential of an application.

cf delete-autoscaling-credential APP_NAME

ALIAS: dasc

EXAMPLES:

$ cf delete-autoscaling-credential APP_NAME

Deleting custom metric credential for app APP_NAME...
OK

cf autoscaling-metrics

Retrieve the aggregated metrics of an application. You can specify the start/end time of the returned query result, and the display order(ascending or descending). The metrics will be shown in a table.

cf autoscaling-metrics APP_NAME METRIC_NAME [--start START_TIME] [--end END_TIME] [--asc] [--output PATH_TO_FILE]

ALIAS: asm

OPTIONS:

  • METRIC_NAME : default metrics "memoryused, memoryutil, responsetime, throughput, cpu" or customized name for your own metrics.
  • --start : start time of metrics collected with format yyyy-MM-ddTHH:mm:ss+/-HH:mm or yyyy-MM-ddTHH:mm:ssZ, default to very beginning if not specified.
  • --end : end time of the metrics collected with format yyyy-MM-ddTHH:mm:ss+/-HH:mm or yyyy-MM-ddTHH:mm:ssZ, default to current time if not speficied.
  • --asc : display in ascending order, default to descending order if not specified
  • --output : dump the metrics to a file

EXAMPLES:

$ cf autoscaling-metrics APP_NAME memoryused --start 2018-12-27T11:49:00+08:00 --end 2018-12-27T11:52:20+08:00 --asc

Retriving aggregated metrics for app APP_NAME...
Metrics Name     	Value     	Timestamp
memoryused       	62MB      	2018-12-27T11:49:00+08:00
memoryused       	62MB      	2018-12-27T11:49:40+08:00
memoryused       	61MB      	2018-12-27T11:50:20+08:00
memoryused       	62MB      	2018-12-27T11:51:00+08:00
memoryused       	62MB      	2018-12-27T11:51:40+08:00
  • Metrics Name: name of the current metric item
  • Value: the value of the current metric item with unit
  • Timestamp: collect time of the current metric item

cf autoscaling-history

Retrieve the scaling event history of an application. You can specify the start/end time of the returned query result, and the display order(ascending or descending). The scaling event history will be shown in a table.

cf autoscaling-history APP_NAME [--start START_TIME] [--end END_TIME] [--asc] [--output PATH_TO_FILE]

ALIAS: ash

OPTIONS:

  • --start : start time of the scaling history with format yyyy-MM-ddTHH:mm:ss+/-HH:mm or yyyy-MM-ddTHH:mm:ssZ, default to very beginning if not specified.
  • --end : end time of the scaling history with format yyyy-MM-ddTHH:mm:ss+/-HH:mm or yyyy-MM-ddTHH:mm:ssZ, default to current time if not speficied.
  • --asc : display in ascending order, default to descending order if not specified
  • --output : dump the scaling history to a file

EXAMPLES:

$ cf autoscaling-history APP_NAME --start 2018-08-16T17:58:53+08:00 --end 2018-08-16T18:01:00+08:00 --asc

Showing history for app APP_NAME...
Scaling Type     	Status        	Instance Changes     	Time                          	Action                                                        	Error
dynamic          	failed        	2->-1                	2018-08-16T17:58:53+08:00     	-1 instance(s) because throughput < 10rps for 120 seconds     	app does not have policy set
dynamic          	succeeded     	2->3                 	2018-08-16T17:59:33+08:00     	+1 instance(s) because memoryused >= 15MB for 120 seconds
scheduled        	succeeded     	3->6                 	2018-08-16T18:00:00+08:00     	3 instance(s) because limited by min instances 6
  • Scaling Type: the trigger type of the scaling action, possible scaling types: dynamic and scheduled
    • dynamic: the scaling action is triggered by a dynamic rule (memoryused, memoryutil, responsetime or throughput)
    • scheduled: the scaling action is triggered by a recurring schedule or specific date rule
  • Status: the result of the scaling action: succeeded or failed
  • Instance Changes: how the instances number get changed (e.g. 1->2 means the application was scaled out from 1 instance to 2)
  • Time: the finish time of scaling action, no mater succeeded or failed
  • Action: the detail information about why and how the application scaled
  • Error: the reason why scaling failed

app-autoscaler-cli-plugin's People

Contributors

asalan316 avatar bonzofenix avatar boyang9527 avatar cdlliuy avatar christopherclark avatar dependabot[bot] avatar donacarr avatar joergdw avatar kevinjcross avatar maximilien avatar norman-abramovitz avatar odidev avatar olivermautschke avatar qibobo avatar rohitsharma04 avatar salzmannsusan avatar silvestre avatar zyjiaobj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

app-autoscaler-cli-plugin's Issues

Please configure GITBOT

Pivotal provides the Gitbot service to synchronize issues and pull requests made against public GitHub repos with Pivotal Tracker projects.

If you are a Pivotal employee, you can configure Gitbot to sync your GitHub repo to your Pivotal Tracker project with a pull request.

Steps:

  • Fork this repo: cfgitbot-config (an ask+cf@ ticket is the fastest way to get read access if you get a 404)
  • Add the Toolsmiths-Bots team to have admin access to your repo
  • Add the cf-gitbot ([email protected]) user to have owner access to your Pivotal Tracker project
  • Add your new repo and or project to config-production.yml file
  • Submit a PR, which will get auto-merged if you've done it right

If you are not a pivotal employee, you can request that [email protected] set up the integration for you.

You might also be interested in configuring GitHub's Service Hook for Tracker on your repo so you can link your commits to Tracker stories. You can do this yourself by following the directions at:

https://www.pivotaltracker.com/blog/guide-githubs-service-hook-tracker/

If you do not want to use Pivotal Tracker to manage this GitHub repo, Please add this repo to the Ignored repositories list

If there are any questions, please reach out to [email protected].

"cf asp APP_NAME" failed with "no config.json" when I installed the plugin first time

when I got my app-autoscaler-cli-plugin installed first time, cf asp APP_NAME return a failue

$ cf asp demoapp2
FAILED

Error: open /Users/zyjiaobj/.cf/plugins/autoscaler_config/config.json: no such file or directory

the expected return msg should be

[zyjiaobj@zyjiaobjs-mbp scripts (master โœ—)]$ cf asa
No api endpoint set. Use 'cf autoscaling-api' to set an endpoint.

fail to display policy with adjustment: +100%

The original policy json is defined as:

{"instance_max_count":10,"instance_min_count":1,"scaling_rules":[{"adjustment":"+100%","breach_duration_secs":60,"cool_down_secs":120,"metric_type":"throughput","operator":">","threshold":500},{"adjustment":"-50%","breach_duration_secs":60,"cool_down_secs":120,"metric_type":"throughput","operator":"<=","threshold":100}],"schedules":{"recurring_schedule":[{"days_of_week":[1,2,3],"end_time":"18:00","initial_min_instance_count":50,"instance_max_count":100,"instance_min_count":1,"start_time":"10:00"}],"timezone":"Europe/Zurich"}}

But when querying with "cf asp" , the display adjustment is shown as below:
"adjustment": "+100%!"(MISSING)
"adjustment": "-50%!"(MISSING)

Receive "Error: invalid character 'C' looking for beginning value"

After installing the 1.0.0.1 plugin and setting the autoscaling-api to "https://appscalerapi.cf.test.domain.com:6100" we successfully set a policy using the "cf aasp" command and this works, scaling our application as defined in the policy we uploaded. However, when executing "cf asm" or "cf ash" we receive the output of "Error: invalid character 'C' looking for beginning value".

We installed "https://github.com/cloudfoundry-incubator/app-autoscaler-release/tree/475d3bd134a4a0f089a13fac6a1fcb4829cca630", which is assoicated with the current last commit of this repository.

Minimum instances

Hi everyone :)

I'm pretty to Foundry and the Autoscaler and I would like to set the minimum number of instances to 0. I want to make sure, that the service is only running, when it has throughput.
I can remove all running instances of a service manually and then scale it back up to one with the help of the autoscaler, but I can't manage to go back to zero instances. I think it might be because I can't set the min_instaces to 0.

trace log does not hide token in request when refreshing access token

$CF_TRACE=true cf ash testapp

REQUEST: [2018-12-21T15:44:25-08:00]
POST /cloudfoundry/login/8d63fb1cc5e99e86dd7229dddf9e5b7b-1f183af0-451c-43e4-81c9-ef8354d39c7e/oauth/token HTTP/1.1
Host: iam.bluemix.net
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
Content-Type: application/x-www-form-urlencoded
User-Agent: go-cli 6.41.0+dd4c76cdd.2018-11-28 / darwin

grant_type=refresh_token&refresh_token=eyJhb????????????&scope=

RESPONSE: [2018-12-21T15:44:26-08:00]
HTTP/1.1 200 OK
Connection: close
Cache-Control: no-store
Content-Language: en-US
Content-Type: application/json
Date: Fri, 21 Dec 2018 23:44:26 GMT
Pragma: no-cache
Set-Cookie: sessioncookie=6d89b7e4a757e9f0fb9e5030bf3d8c62; Path=/; Secure; HttpOnly
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
Transaction-Id: d0a3973f087a49549d845e76da04e2b1
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Powered-By: Servlet/3.1
X-Xss-Protection: 1; mode=block

{"access_token":"[PRIVATE DATA HIDDEN]","token_type":"[PRIVATE DATA HIDDEN]","refresh_token":"[PRIVATE DATA HIDDEN]","expires_in":599,"scope":"cloud_controller.read password.write cloud_controller.write openid doppler.firehose cloud_controller.admin uaa.user","jti":"ec2a561ac16d4e2ab8c9daed94474d4a"}

conversion error with invalid policy

$ cat a.json
{"a":"123"}

$ CF_TRACE=true cf aasp testnode a.json

......

REQUEST: [2019-08-15T05:02:20-05:00]
PUT /v1/apps/bf4d3aa7-a5b9-42ea-87d2-a323f06c0861/policy HTTP/1.1
Host: autoscaler.bosh-lite.com
Authorization: [PRIVATE DATA HIDDEN]
Content-Type: application/json

{"a":"123"}

RESPONSE: [2019-08-15T05:02:20-05:00] Elapsed: 173ms
HTTP/1.1 400 Bad Request
Connection: close
Content-Length: 279
Content-Type: application/json
Date: Thu, 15 Aug 2019 10:02:20 GMT
X-Vcap-Request-Id: 743de125-62b9-4c32-6bd3-74602a4ff10b

[{"context":"(root)","description":"Must validate at least one schema (anyOf)"},{"context":"(root)","description":"scaling_rules is required"},{"context":"(root)","description":"instance_min_count is required"},{"context":"(root)","description":"instance_max_count is required"}]
panic: interface conversion: interface {} is []interface {}, not map[string]interface {}

goroutine 1 [running]:
cli/api.parseErrResponse(0xc420015200, 0x117, 0x600, 0x117, 0x600)
	/Users/liuying/Bluemix/dev/git-openautoscaler/cdlliuy/app-autoscaler-cli-plugin/src/cli/api/apihelper.go:106 +0x71b
cli/api.(*APIHelper).CreatePolicy(0xc420143fe0, 0x7bf2a0, 0xc42013bda0, 0x0, 0x0)
	/Users/liuying/Bluemix/dev/git-openautoscaler/cdlliuy/app-autoscaler-cli-plugin/src/cli/api/apihelper.go:251 +0x529
cli/commands.CreatePolicy(0x7f12a708f030, 0xc420128090, 0x7ffff9dde707, 0x8, 0x7ffff9dde710, 0x6, 0xc420078e00, 0xc420127c00)
	/Users/liuying/Bluemix/dev/git-openautoscaler/cdlliuy/app-autoscaler-cli-plugin/src/cli/commands/attach_policy.go:58 +0x3ab
cli/commands.AttachPolicyCommand.Execute(0x7ffff9dde707, 0x8, 0x7ffff9dde710, 0x6, 0xc42011f6e0, 0x0, 0x3, 0x758e01, 0x7f12a708f0c8)
	/Users/liuying/Bluemix/dev/git-openautoscaler/cdlliuy/app-autoscaler-cli-plugin/src/cli/commands/attach_policy.go:23 +0x61
cli/commands.(*AttachPolicyCommand).Execute(0xa36b28, 0xc42011f6e0, 0x0, 0x3, 0xa36b28, 0x1)
	<autogenerated>:1 +0x86
github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc4200708a0, 0xc42000e0c0, 0x3, 0x3, 0xc420128090, 0x8338ff, 0xa, 0x1, 0x1)
	/Users/liuying/Bluemix/dev/git-openautoscaler/cdlliuy/app-autoscaler-cli-plugin/src/github.com/jessevdk/go-flags/parser.go:316 +0x893
main.(*AutoScaler).Run(0xa53068, 0xa01cc0, 0xc420128090, 0xc42000e0c0, 0x3, 0x3)
	/Users/liuying/Bluemix/dev/git-openautoscaler/cdlliuy/app-autoscaler-cli-plugin/src/cli/main.go:112 +0x103
code.cloudfoundry.org/cli/plugin.Start(0x9fb540, 0xa53068)
	/Users/liuying/Bluemix/dev/git-openautoscaler/cdlliuy/app-autoscaler-cli-plugin/src/code.cloudfoundry.org/cli/plugin/plugin_shim.go:34 +0x28d
main.main()
	/Users/liuying/Bluemix/dev/git-openautoscaler/cdlliuy/app-autoscaler-cli-plugin/src/cli/main.go:103 +0x47

Occasionally after setting the autoscaler-api it fails saying its not set.

From the debug scripts on the autoscaler-release test runs.
=============== DEBUG ===============
cf app autoscaler-1-node-custom-metric-bf814303c6306008:
Showing health and status for app autoscaler-1-node-custom-metric-bf814303c6306008 in org upgrade-test-TESTS-1-ORG-aac70604b6b46490 / space upgrade-test-TESTS-1-SPACE-04cb91e40219b923 as upgrade-test-TESTS-1-USER-e3085155214c2ba7...

name: autoscaler-1-node-custom-metric-bf814303c6306008
requested state: started
routes: autoscaler-1-node-custom-metric-bf814303c6306008.autoscaler.app-runtime-interfaces.ci.cloudfoundry.org
last uploaded: Tue 15 Nov 09:20:42 GMT 2022
stack: cflinuxfs3
buildpacks:
name version detect output buildpack name
nodejs_buildpack 1.8.1 nodejs nodejs

type: web
sidecars:
instances: 1/1
memory usage: 128M
state since cpu memory disk logging details
#0 running 2022-11-15T09:21:01Z 0.5%!M(MISSING) of 128M 166.6M of 200M 0/s of unlimited

cf autoscaling-api https://upgrade-test.autoscaler.app-runtime-interfaces.ci.cloudfoundry.org:
Setting AutoScaler api endpoint to https://upgrade-test.autoscaler.app-runtime-interfaces.ci.cloudfoundry.org...
OK

cf autoscaling-policy autoscaler-1-node-custom-metric-bf814303c6306008:
FAILED

Error: No AutoScaler api endpoint set. Use 'cf autoscaling-api' to set an endpoint.

cf autoscaling-history autoscaler-1-node-custom-metric-bf814303c6306008:
FAILED

Error: No AutoScaler api endpoint set. Use 'cf autoscaling-api' to set an endpoint.

cf autoscaling-metrics autoscaler-1-node-custom-metric-bf814303c6306008 memoryused:
FAILED

Error: No AutoScaler api endpoint set. Use 'cf autoscaling-api' to set an endpoint.

cf autoscaling-metrics autoscaler-1-node-custom-metric-bf814303c6306008 memoryutil:
FAILED

Error: No AutoScaler api endpoint set. Use 'cf autoscaling-api' to set an endpoint.

cf autoscaling-metrics autoscaler-1-node-custom-metric-bf814303c6306008 responsetime:
FAILED

Error: No AutoScaler api endpoint set. Use 'cf autoscaling-api' to set an endpoint.

cf autoscaling-metrics autoscaler-1-node-custom-metric-bf814303c6306008 throughput:
FAILED

Error: No AutoScaler api endpoint set. Use 'cf autoscaling-api' to set an endpoint.

cf autoscaling-metrics autoscaler-1-node-custom-metric-bf814303c6306008 cpu:
FAILED

Error: No AutoScaler api endpoint set. Use 'cf autoscaling-api' to set an endpoint.

cf autoscaling-metrics autoscaler-1-node-custom-metric-bf814303c6306008 test_metric:
FAILED

Error: No AutoScaler api endpoint set. Use 'cf autoscaling-api' to set an endpoint.

Allow for using HTTPS_PROXY

I am behind a proxy trying to use this and the autoscale cli does not seem to honor my HTTPS_PROXY or https_proxy settings as the CF CLI does. Is there a way to set the HTTPS_PROXY or could you add the support for it?

What I need to be able to do:

export https_proxy="http://MY_PROXY"
cf autoscaling-apps

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.