{"id":20751374,"url":"https://github.com/superfly/fly-autoscaler","last_synced_at":"2025-04-28T13:26:15.563Z","repository":{"id":223754579,"uuid":"758235713","full_name":"superfly/fly-autoscaler","owner":"superfly","description":"A metrics-based autoscaler for Fly.io","archived":false,"fork":false,"pushed_at":"2024-06-28T19:15:26.000Z","size":71,"stargazers_count":20,"open_issues_count":9,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-06-29T15:18:01.661Z","etag":null,"topics":["autoscaler","flyio","go"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/superfly.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-15T22:16:26.000Z","updated_at":"2024-06-28T19:14:52.000Z","dependencies_parsed_at":"2024-06-21T13:08:58.711Z","dependency_job_id":null,"html_url":"https://github.com/superfly/fly-autoscaler","commit_stats":null,"previous_names":["superfly/fly-autoscaler"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superfly%2Ffly-autoscaler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superfly%2Ffly-autoscaler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superfly%2Ffly-autoscaler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superfly%2Ffly-autoscaler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/superfly","download_url":"https://codeload.github.com/superfly/fly-autoscaler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225018090,"owners_count":17407889,"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":["autoscaler","flyio","go"],"created_at":"2024-11-17T08:33:11.539Z","updated_at":"2024-11-17T08:33:12.081Z","avatar_url":"https://github.com/superfly.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Fly Autoscaler\n==============\n\nThe project is a metrics-based autoscaler for Fly.io. The autoscaler supports\npolling for metrics from a Prometheus instance and then computing the number of\nmachines based on those metrics.\n\n## How it works\n\nThe Fly Autoscaler works by performing a reconciliation loop on a regular\ninterval. By default, it runs every 15 seconds.\n\n1. Collect metrics from external systems (e.g. Prometheus)\n\n2. Compute the target number of machines based on a user-provided expression.\n\n3. Fetch a list of all Fly Machines for your application.\n\n4. If the target number of machines is less than the number of `started`\n   machines, use the Fly Machines API to start new machines.\n\n\n```\n                                     ┌────────────────────┐\nfly-autoscaler ──────────┐           │                    │\n│ ┌────────────────────┐ │    ┌──────│     Prometheus     │\n│ │                    │ │    │      │                    │\n│ │  Metric Collector  │◀┼────┘      └────────────────────┘\n│ │                    │ │                                 \n│ └──────┬─────────────┘ │                                 \n│        │     △         │                                 \n│        ▽     │         │                                 \n│ ┌────────────┴───────┐ │                                 \n│ │                    │ │                                 \n│ │     Reconciler     │◀┼────┐                            \n│ │                    │ │    │      ┌────────────────────┐\n│ └────────────────────┘ │    │      │                    │\n└────────────────────────┘    └─────▶│  Fly Machines API  │\n                                     │                    │\n                                     └────────────────────┘\n```\n\n### Expressions\n\nThe autoscaler uses the [Expr][] language to define the target number of\nmachines. See the [Expr Language Definition][] for syntax and a full list of\nbuilt-in functions. The expression can utilize any named metrics that you\ncollect and it should always return a number.\n\nFor example, if you poll for queue depth and each machine can handle 10 queue\nitems at a time, you can compute the number of machines as:\n\n```expr\nceil(queue_depth / 10)\n```\n\nThe autoscaler can only start machines so it will never exceed the number of \nmachines available for a Fly app.\n\n[Expr]: https://expr-lang.org/\n[Expr Language Definition]: https://expr-lang.org/docs/language-definition\n\n\n## Usage\n\n### Create an app for your autoscaler\n\nFirst, create an app for your autoscaler:\n\n```sh\n$ fly apps create my-autoscaler\n```\n\nThen create a `fly.toml` for the deployment. Update the `TARGET_APP_NAME` with\nthe name of the app that you want to scale and update `MY_ORG` to the\norganization where your Prometheus metrics live.\n\n```toml\napp = \"my-autoscaler\"\n\n[build]\nimage = \"flyio/fly-autoscaler:0.2\"\n\n[env]\nFAS_APP_NAME = \"TARGET_APP_NAME\"\nFAS_STARTED_MACHINE_COUNT = \"ceil(queue_depth / 10)\"\nFAS_PROMETHEUS_ADDRESS = \"https://api.fly.io/prometheus/MY_ORG\"\nFAS_PROMETHEUS_METRIC_NAME = \"queue_depth\"\nFAS_PROMETHEUS_QUERY = \"sum(queue_depth)\"\n\n[metrics]\nport = 9090\npath = \"/metrics\"\n```\n\n\n### Create a deploy token\n\nNext, set up a new deploy token for the application you want to scale:\n\n```sh\n$ fly tokens create deploy -a TARGET_APP_NAME\n```\n\nSet the token as a secret on your application:\n\n```\n$ fly secrets set FAS_API_TOKEN=\"FlyV1 ...\"\n```\n\n\n### Create a read-only token\n\nCreate a token for reading your Prometheus data:\n\n```sh\n$ fly tokens create readonly\n```\n\nSet the token as a secret on your application:\n\n```\n$ fly secrets set FAS_PROMETHEUS_TOKEN=\"FlyV1 ...\"\n```\n\n### Deploy the server\n\nFinally, deploy your autoscaler application:\n\n```sh\n$ fly deploy\n```\n\nThis should create a new machine and start it with the `fly-autoscaler` server\nrunning.\n\n\n### Testing your metrics \u0026 expression\n\nYou can perform a one-time run of metrics collection \u0026 expression evaluation for\ntesting or debugging purposes by using the `eval` command. This command does not\nperform any scaling of Fly Machines. It will only print the evaluated expression\nbased on current metrics numbers.\n\n```sh\n$ fly-autoscaler eval\n```\n\nYou can change the evaluated expression by setting an environment variable:\n\n```sh\n$ FAS_STARTED_MACHINE_COUNT=queue_depth fly-autoscaler eval\n```\n\n## Configuration\n\nYou can also configure `fly-autoscaler` with a YAML config file if you don't\nwant to use environment variables or if you want to configure more than one\nmetric collector.\n\nPlease see the reference [fly-autoscaler.yml][] for more details.\n\n[fly-autoscaler.yml]: ./etc/fly-autoscaler.yml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperfly%2Ffly-autoscaler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuperfly%2Ffly-autoscaler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperfly%2Ffly-autoscaler/lists"}