Skip to content

About

spot-instance-advisor is command line tool to get the cheapest group of spot instanceTypes.

Resources

Stars

1 star

Watchers

0 watching

Forks

 
 

Repository files navigation

Spot Instance Advisor

Go Version License Go Modules

A command-line tool for analyzing Alibaba Cloud Spot instance prices and availability. This tool helps you find the most cost-effective Spot instances based on historical price data and availability patterns.

Features

  • 🔍 Instance Filtering: Filter instances by CPU, memory, and instance family
  • 📊 Price Analysis: Analyze historical Spot prices with customizable time windows
  • 💰 Cost Optimization: Find instances with the best price-to-performance ratios
  • 📈 Availability Insights: Get insights into instance availability patterns
  • 🎯 Multiple Output Formats: Support for both human-readable tables and JSON output
  • ⚡ Fast & Efficient: Optimized for quick analysis of large instance catalogs

Quick Start

Prerequisites

  • Go 1.25.2 or later
  • Alibaba Cloud account with ECS API access

Installation

# Clone the repository
git clone <repository-url>
cd spot-instance-advisor

# Build the binary (outputs to dist/spot-instance-advisor-OS-ARCH)
make build

# Or build directly with Go (not recommended for releases)
go build -o dist/spot-instance-advisor-$(go env GOOS)-$(go env GOARCH) .

Basic Usage

# Basic usage with table output
./spot-instance-advisor \
  --accessKeyId YOUR_ACCESS_KEY_ID \
  --accessKeySecret YOUR_ACCESS_KEY_SECRET \
  --region cn-hangzhou

# JSON output for programmatic use
./spot-instance-advisor \
  --accessKeyId YOUR_ACCESS_KEY_ID \
  --accessKeySecret YOUR_ACCESS_KEY_SECRET \
  --region cn-hangzhou \
  --json

Command Line Options

Authentication

  • --accessKeyId: Your Alibaba Cloud Access Key ID
  • --accessKeySecret: Your Alibaba Cloud Access Key Secret
  • --region: Target region (default: cn-hangzhou)

Instance Filtering

  • --mincpu: Minimum CPU cores (default: 1)
  • --maxcpu: Maximum CPU cores (default: 32)
  • --minmem: Minimum memory in GB (default: 2)
  • --maxmem: Maximum memory in GB (default: 64)
  • --family: Instance family filter (e.g., ecs.n1,ecs.n2)
  • --instanceType: Specific instance types (comma-separated, e.g., ecs.n1.small,ecs.n2.large). Takes precedence over family parameter.
  • --arch: CPU architecture filter: x86_64 or arm64

Analysis Parameters

  • --cutoff: Discount threshold (default: 2)
  • --limit: Maximum number of results (default: 20)
  • --resolution: Price history analysis window in days (default: 7)

Output Format

  • --json: Output results in JSON format

Development

Project Structure

spot-instance-advisor/
├── main.go          # Main application entry point
├── meta.go          # Metadata and instance management
├── sort.go          # Price analysis and sorting logic
├── go.mod           # Go module dependencies
├── go.sum           # Dependency checksums
├── Makefile         # Build automation
└── README.md        # This file

Building and Testing

# Install dependencies
make deps

# Run tests
make test

# Build the application
make build

# Build for Linux
make build-linux

# Run with coverage
make test-coverage

# Clean build artifacts
make clean

# Update dependencies
make deps-update

Dependencies

This project uses modern Go modules for dependency management:

  • github.com/aliyun/alibaba-cloud-sdk-go: Alibaba Cloud SDK for Go
  • github.com/fatih/color: Terminal color output
  • github.com/sirupsen/logrus: Structured logging

JSON Output Format

When using the --json flag, the tool outputs structured JSON data:

[
  {
    "instanceTypeId": "ecs.n1.small",
    "zoneId": "cn-hangzhou-a",
    "pricePerCore": 0.1234,
    "discount": 2.5,
    "possibility": 0.8,
    "cpuCoreCount": 1,
    "memorySize": 2.0,
    "instanceFamily": "ecs.n1",
    "arch": "x86_64"
  }
]

JSON Field Descriptions

  • instanceTypeId: Instance type identifier
  • zoneId: Availability zone identifier
  • pricePerCore: Price per CPU core
  • discount: Discount multiplier compared to on-demand pricing
  • possibility: Price stability indicator
  • cpuCoreCount: Number of CPU cores
  • memorySize: Memory size in GB
  • instanceFamily: Instance family identifier
  • arch: CPU architecture (x86_64 or arm64)

Examples

Find Small Instances with Good Discounts

./spot-instance-advisor \
  --accessKeyId YOUR_KEY \
  --accessKeySecret YOUR_SECRET \
  --mincpu 1 \
  --maxcpu 4 \
  --minmem 2 \
  --maxmem 8 \
  --cutoff 3 \
  --json

Analyze Specific Instance Family

./spot-instance-advisor \
  --accessKeyId YOUR_KEY \
  --accessKeySecret YOUR_SECRET \
  --family ecs.n1,ecs.n2 \
  --arch x86_64 \
  --limit 10 \
  --json

Analyze Specific Instance Types

./spot-instance-advisor \
  --accessKeyId YOUR_KEY \
  --accessKeySecret YOUR_SECRET \
  --instanceType ecs.n1.small,ecs.n2.large \
  --arch x86_64 \
  --limit 10 \
  --json

Note: When using --instanceType:

  • The specified instance types take precedence over --family parameter
  • Supports comma-separated multiple instance types
  • All other filters (CPU, memory, architecture) will be skipped, directly using the specified instance types
  • Invalid or non-existent instance types will be skipped

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.

Acknowledgments

  • Alibaba Cloud for providing the ECS API
  • The Go community for excellent tooling and libraries

About

spot-instance-advisor is command line tool to get the cheapest group of spot instanceTypes.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages