snoozebot

module
v0.0.0-...-9fd48d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2025 License: Apache-2.0

README

Snoozebot

Snoozebot is a Go-based system for automatically managing cloud resources to save costs by monitoring system activity and hibernating idle instances.

Architecture

Snoozebot consists of two main components:

  1. Embedded Monitoring Library: A lightweight Go module that can be embedded in a host application to monitor system resources and detect idle states.

  2. Remote Agent: A standalone service that manages cloud resources across multiple instances, making decisions about when to hibernate instances and handling the cloud provider interactions.

This architecture allows for:

  • Full system shutdown (not just hibernation)
  • Centralized management of multiple instances
  • Separation of monitoring logic from cloud provider interaction
  • Easy integration into host applications

Features

  • Lightweight Monitoring: Tracks CPU, memory, network, disk, user input, and GPU activity
  • Configurable Thresholds: Customizable resource usage thresholds for idle detection
  • Extensible: Support for custom resource monitoring metrics
  • Cloud-Provider Agnostic: Plugin system for different cloud providers
  • Process Isolation: Cloud provider plugins run as separate processes for stability and security
  • Cross-Platform: Works on Linux, macOS, and Windows
  • Embeddable: Can be used as a library in other Go applications
  • Secure Plugin System: Plugins use TLS encryption, signature verification, and API key authentication
  • Role-Based Access Control: Fine-grained permission control for plugin operations
  • Versioned Plugin API: Semantic versioning with compatibility checking for stable plugin interfaces
  • Notification System: Flexible notification framework with Slack integration

Embedding in Host Applications

Snoozebot's monitoring library can be embedded in a host application:

// Create and configure the monitor
monitor := monitor.NewMonitor().
    WithThreshold(monitor.CPU, 15.0).
    WithThreshold(monitor.Memory, 25.0).
    WithNapTime(30 * time.Minute).
    WithAgentURL("http://snooze-agent.example.com:8080")

// Add custom resource monitors
monitor.AddResourceMonitor("custom_app_metric", func() (float64, error) {
    return getApplicationMetric(), nil
})

// Handle idle state changes
monitor.OnIdleStateChange(func(isIdle bool, duration time.Duration) {
    if isIdle {
        log.Printf("System idle for %s", duration)
    } else {
        log.Printf("System active")
    }
})

// Start the monitor
monitor.Start(ctx)

See the examples directory for more details.

Cloud Provider Support

Snoozebot supports the following cloud providers through plugins:

  • AWS (Amazon Web Services)
  • GCP (Google Cloud Platform) - Planned
  • Azure (Microsoft Azure Cloud)

Agent API

The Snoozebot agent provides a REST API for instance registration and management:

  • /api/instances/register - Register an instance with the agent
  • /api/instances/unregister - Unregister an instance
  • /api/instances/idle - Send idle notifications
  • /api/instances/heartbeat - Send heartbeats
  • /api/instances/state - Send state changes
  • /api/instances - List instances

Building from Source

Prerequisites:

  • Go 1.18 or newer
git clone https://github.com/scottfridman/snoozebot.git
cd snoozebot

# Build the embedded example
go build -o bin/embedded ./examples/embedded

# Build the agent
go build -o bin/snooze-agent ./agent/cmd

# Build plugins
go build -o bin/plugins/aws ./plugins/aws
go build -o bin/plugins/azure ./plugins/azure

Documentation

License

Apache License 2.0

Directories

Path Synopsis
agent
api
cmd command
cmd
ifacecheck command
securitymon command
securitysetup command
snooze command
snoozed command
snoozesign command
versioncheck command
examples
embedded command
pkg
plugin/auth/credentials
Package credentials provides standardized credential handling for cloud providers
Package credentials provides standardized credential handling for cloud providers
plugin/version
Package version provides versioning utilities for the Snoozebot plugin system
Package version provides versioning utilities for the Snoozebot plugin system
email_test command
slack_test command
test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL