{"id":13776255,"url":"https://github.com/tsuru/tsuru-autoscale","last_synced_at":"2025-04-26T02:32:13.084Z","repository":{"id":57523099,"uuid":"31142882","full_name":"tsuru/tsuru-autoscale","owner":"tsuru","description":"auto scale as a service ","archived":true,"fork":false,"pushed_at":"2019-02-28T13:15:33.000Z","size":942,"stargazers_count":32,"open_issues_count":9,"forks_count":7,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-14T09:13:39.675Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tsuru.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-21T22:05:37.000Z","updated_at":"2024-09-12T18:34:21.000Z","dependencies_parsed_at":"2022-08-30T01:40:40.878Z","dependency_job_id":null,"html_url":"https://github.com/tsuru/tsuru-autoscale","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsuru%2Ftsuru-autoscale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsuru%2Ftsuru-autoscale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsuru%2Ftsuru-autoscale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsuru%2Ftsuru-autoscale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tsuru","download_url":"https://codeload.github.com/tsuru/tsuru-autoscale/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250922127,"owners_count":21508279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:00:20.758Z","updated_at":"2025-04-26T02:32:12.599Z","avatar_url":"https://github.com/tsuru.png","language":"Go","funding_links":[],"categories":["Extensions"],"sub_categories":["Services"],"readme":"# tsuru-autoscale\n\n[![Build Status](https://travis-ci.org/tsuru/tsuru-autoscale.png?branch=master)](https://travis-ci.org/tsuru/tsuru-autoscale)\n[![Go Report Card](https://goreportcard.com/badge/github.com/tsuru/tsuru-autoscale)](https://goreportcard.com/report/github.com/tsuru/tsuru-autoscale)\n[![codecov](https://codecov.io/gh/tsuru/tsuru-autoscale/branch/master/graph/badge.svg)](https://codecov.io/gh/tsuru/tsuru-autoscale)\n\n## Features\n\n* HTTP api to manage auto scale configuration\n* integration with [tsuru](https://tsuru.io)\n* Wizard that makes easy configure an auto scale for [tsuru](https://tsuru.io)\napplications\n* Support HTTP based data sources\n* Support HTTP based actions\n* Support alarm scripts in javascript\n\n## Concepts\n\nThe `tsuru-autoscale` is based on three elements: `data sources`, `actions` and `alarms`.\n\n### Data sources\n\nData source is a http endpoint that provide the data to an alarm. Is based on the\ndata source data that the alarm will execute an action.\n\n### Actions\n\nAction is a http endpoint that is called when the alarm expression result is `true`.\n\n### Alarms\n\nAlarm is composed by data sources, actions and by an expression. When the expression result is `true` the actions will be executed.\n\n### Wizard\n\nWizard is an easy way to use autoscale with `tsuru`. Wizard creates the alarms\nfor scale up and scale down, based on simple inputs like: ``\n\n## Install as tsuru application\n\n### Create tsuru app using Go platform\n\n```\ntsuru app-create autoscale go\n```\n\n### Configuring MongoDB\n\nWe should use environment variables to configure the database:\n\n```\ntsuru env-set \"MONGODB_URL=mongodb://172.17.0.1:27017/tsuru_autoscale\" -a autoscale\n```\n\n### Deploy the applications\n\n```\ntsuru env-set GO_PKG_PATH=github.com/tsuru/tsuru-autoscale -a autoscale\n```\n\n```\ntsuru app-deploy . -a autoscale\n```\n\n## API Reference\n\n### list data sources\n\n```\ncurl \u003cautoscale-url\u003e/datasource\n```\n\n### add data source\n\n```\ncurl -XPOST -d '{}' -H \"Content-Type: application/json\" \u003cautoscale-url\u003e/datasource\n```\n\n### remove a data source\n\n```\ncurl -XDELETE \u003cautoscale-url\u003e/datasource/{name}\n```\n\n### list actions\n\n```\ncurl \u003cautoscale-url\u003e/action\n```\n\n### add an action\n\n```\ncurl -XPOST -d '{}' -H \"Content-Type: applicaiton/json\" \u003cautoscale-url\u003e/action\n```\n\n### remove an action\n\n```\ncurl -XDELETE \u003cautoscale-url\u003e/action/{name}\n```\n\n### list alarms\n\n```\ncurl \u003cautoscale-url\u003e/alarm\n```\n\n### add an alarm\n\n```\ncurl -XPOST -d '{}' -H \"Content-Type: application/json\" \u003cautoscale-url\u003e/alarm\n```\n\n### remove an alarm\n\n```\ncurl -XDELETE \u003cautoscale-url\u003e/alarm/{name}\n```\n\n## Configuring Wizard to works with tsuru\n\nTo `wizard` works fine with `tsuru` it is necessary to configure some data sources\nand the actions to scale up and scale down.\n\n### Add the scale up action\n\n```\ncurl -XPOST -d '{\"name\": \"scale_up\", \"url\": \"http://\u003ctsuru_url\u003e/apps/{app}/units\", \"method\": \"PUT\", \"body\": \"units={step}\u0026process={process}\", \"headers\": {\"Authorization\": \"bearer \u003ctsuru-token\u003e\", \"Content-Type\": \"application/x-www-form-urlencoded\"}}' -H \"Content-Type: application/json\" \u003cautoscale-url\u003e/action\n```\n\n### Add the scale down action\n\n```\ncurl -XPOST -d '{\"name\": \"scale_down\", \"url\": \"http://\u003ctsuru_url\u003e/apps/{app}/units?units={step}\u0026process={process}\", \"method\": \"DELETE\", \"headers\": {\"Authorization\": \"bearer \u003ctsuru-token\u003e\", \"Content-Type\": \"application/x-www-form-urlencoded\"}}' -H \"Content-Type: application/json\" \u003cautoscale-url\u003e/action\n```\n\n### Add data source to get the number of units\n\n```\ncurl -XPOST -d '{\"name\": \"units\", \"url\": \"http://\u003ctsuru_url\u003e/apps/{app}\", \"method\": \"GET\", \"headers\" : {\"Authorization\": \"bearer \u003ctsuru_token\u003e\"}}' -H \"Content-Type: application/json\" \u003cautoscale-url\u003e/datasource\n```\n\n### Add data source to get cpu data from ElasticSearch\n\nOnly configure it if you are using ElasticSearch as tsuru metrics backend.\n\n```bash\ncurl -XPOST -d '{\"name\": \"cpu\", \"url\": \"http://\u003celasticsearch_url\u003e/\u003celasticsearch_index\u003e/cpu_max/_search\", \"method\": \"POST\", \"body\" : \"{\\\"size\\\":0, \\\"query\\\": {\\\"filtered\\\": {\\\"filter\\\": {\\\"bool\\\": {\\\"must\\\": [{\\\"range\\\": {\\\"value\\\": {\\\"lt\\\": 500}}},{ \\\"term\\\": {\\\"app.raw\\\": \\\"{app}\\\"}}, {\\\"term\\\": {\\\"process.raw\\\": \\\"{process}\\\"}}]}}}}, \\\"aggs\\\": {\\\"range\\\": {\\\"date_range\\\": {\\\"field\\\": \\\"@timestamp\\\", \\\"ranges\\\": [{\\\"from\\\": \\\"now-5m/m\\\", \\\"to\\\": \\\"now\\\"}]}, \\\"aggs\\\": {\\\"date\\\": {\\\"date_histogram\\\": {\\\"field\\\": \\\"@timestamp\\\", \\\"interval\\\": \\\"1m\\\"}, \\\"aggs\\\": {\\\"max\\\": {\\\"max\\\": {\\\"field\\\": \\\"value\\\"}}, \\\"avg\\\": {\\\"avg\\\": {\\\"field\\\": \\\"value\\\"}}}}}}}}\", \"public\": true}' -H \"Content-Type: application/json\" \u003cautoscale-url\u003e/datasource\n```\n\n### Add data source to get cpu data from Prometheus\n\nOnly configure it if you are using Prometheus as tsuru metrics backend.\n\n```bash\ncurl -XPOST -d '{\"name\": \"cpu\", \"url\": \"\u003cprometheus_url\u003e/api/v1/query?query=max(irate(container_cpu_system_seconds_total{container_label_tsuru_process_name=\\\"{process}\\\",container_label_tsuru_app_name=\\\"{app}\\\"}[1m]))*100\", \"public\": true}' -H \"Content-Type: application/json\" \u003cautoscale-url\u003e/datasource\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsuru%2Ftsuru-autoscale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsuru%2Ftsuru-autoscale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsuru%2Ftsuru-autoscale/lists"}