Code Monkey home page Code Monkey logo

hetzner-rescaler's Introduction

Hetzner rescaler

Release Docker Image Size (tag) GitHub go.mod Go version GitHub Workflow Status

Lightweight CLI tool to programmatically rescale your Hetzner virtual server daily to optimize your budget spending, scaling to a cheaper machine when you don't need or need few resources, and scaling to a more performant one when you know the load will be higher.

Usage

First, you need to generate an Hetzner API Token.

Next you need to create your configuration file or export the required environment variables for the tool.
The config command helps you generate a valid configuration, warning you if there are any logic errors and validating your input.

hetzner-rescaler config

Keep in mind if env vars are defined, they will take priority.
After setting the configuration, you can start the tool by running

hetzner-rescaler start

Use with environmental variables

Export these env vars to override or completely bypass the generated configuration:

Variable Description
HCLOUD_TOKEN A valid Hetzner API Token
SERVER_ID The ID of the target server
BASE_SERVER_NAME The code of the cheap server type
TOP_SERVER_NAME The code of the high performance server type
HOUR_START 24h format, colon separated hour when the server should be upgraded
HOUR_STOP 24h format, colon separated hour when the server should be downgraded
TZ If defined, change the timezone of the timer

Use with Docker

Pull the image from dockerhub

docker pull jonamat/hetzner-rescaler

Opt A: Create a config file inside the container & start immediately beta

docker run -ti jonamat/hetzner-rescaler hetzner-rescaler plug

Opt B: Mounting a configuration file

docker run -v ~/.hetzner-rescaler.yaml:/.hetzner-rescaler.yaml jonamat/hetzner-rescaler

Opt C: Passing config as env vars

docker run \
-e HCLOUD_TOKEN=abc123 \
-e SERVER_ID=4567 \
-e BASE_SERVER_NAME=cpx11 \
-e TOP_SERVER_NAME=cpx21 \
-e HOUR_START=09:00 \
-e HOUR_STOP=20:00 \
jonamat/hetzner-rescaler

You can also pass a partial configuration file and define the missing vars as env vars (useful eg to hide the API key)

Use with compose/swarm stacks

version: '3.7'

services:
  hetzner-rescaler:
    image: jonamat/hetzner-rescaler

    // Provide the env vars
    environment:
      HCLOUD_TOKEN: abc123
      SERVER_ID: 4567
      BASE_SERVER_NAME: cpx11
      TOP_SERVER_NAME: cpx21
      HOUR_START: "09:00"
      HOUR_STOP: "20:00"
    
    // ...or mount the config file
    volumes:
      - /var/hetzner/config-file.yaml:/.hetzner-rescaler.yaml

The configuration file

The default path for the config file is ~/.hetzner-rescaler.yaml.
You can provide (and create) a custom config path passing the --config /custom/path/config.yml flag.

Config yaml file example

hcloud_token: abc123
server_id: 15393230
base_server_name: cx11
top_server_name: cx21
hour_start: "09:00"
hour_stop: "20:00"

Commands

Usage:
  hetzner-rescaler [command]

Available Commands:
  config      Create the configuration file
  help        Help about any command
  plug        Configure and start immediately
  start       Start rescale timers
  try         Try a complete rescale cycle

Flags:
      --config string   config file (default is $HOME/.hetzner-rescaler.yaml)
  -h, --help            help for hetzner-rescaler

Use "hetzner-rescaler [command] --help" for more information about a command.

Use cases

This tool was developed for a my specific use case: I use an Hetzner server for remote development, using the Remote SSH extension to simplify my cross-device development workflow. This machine also serve some personal services, which require very little resources but cannot be stopped for a long time.
It could be useful for all servers running applications related to a company's opening hours, such as booking, delivery or management software.

License

MIT

hetzner-rescaler's People

Contributors

jonamat avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

hetzner-rescaler's Issues

Need for an external server?

Hi there,

We're planning on using this for one of our internal projects, but I couldn't make up from the description if you need to run this on an external server. I'm guessing it is, based on the code I read, but I just wanted to make sure.

Thanks!

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.