Sign inSign up

gjames8/nanostatus

By gjames8

โ€ขUpdated 2 months ago

Lightweight (4.1 MB!) single container status monitoring page.

Image
Web servers
Monitoring & observability
0

2.3K

gjames8/nanostatus repository overview

Docker Image CI GitHub repo size Docker Image Size (tag) Docker Pulls

โ NanoStatus

Finally got a cursor subscription so wanted to build something cool. NanoStatus is a lightweight, single-container monitoring dashboard built with Go and React. Monitor your services' uptime, response times, and health in real-time with a beautiful, modern interface. I personally made this for my PiZero, UptimeKuma was a little too heavy so wanted to make something a little lighter.

โ Sample

Alt text

โ โœจ Features

  • ๐Ÿš€ Single Binary Deployment - Everything embedded in one Go binary
  • ๐Ÿ“Š Real-time Monitoring - Server-Sent Events (SSE) for instant updates
  • ๐ŸŽจ Modern UI - Sleek dark theme with glassmorphism effects and smooth animations
  • ๐Ÿ“ˆ Response Time Charts - Historical data with multiple time frames (1h, 12h, 1w, 1y)
  • ๐Ÿ” Service Management - Add, edit, pause, and delete monitors
  • ๐Ÿ“ฑ Fully Responsive - Works beautifully on desktop, tablet, and mobile
  • ๐Ÿ’พ SQLite Database - Lightweight persistence with automatic cleanup
  • โšก Efficient Updates - Only sends data when values actually change
  • ๐ŸŽฏ Customizable Intervals - Set individual check intervals per service
  • ๐Ÿงน Auto Cleanup - Automatically removes check history older than 1 year

โ ๐Ÿš€ Quick Start

  1. Build the Docker image:

    docker build -t nanostatus .
    
  2. Run the container:

    docker run -p 8080:8080 -v "$(pwd)/data:/data" nanostatus
    

    The application will be available at http://localhost:8080

    Note: The -v "$(pwd)/data:/data" flag persists the database across container restarts.

  3. Access the dashboard: Open http://localhost:8080 in your browser

โ Local Development
โ Prerequisites
โ Running Locally
  1. Build the frontend:

    cd src
    bun install
    bun run build.ts --outdir=../dist
    cd ..
    
  2. Run the Go server:

    go run main.go
    

    Or build and run:

    go build -o nanostatus main.go
    ./nanostatus
    
  3. Access the application: Open http://localhost:8080โ  in your browser

โ Using Makefile
make build        # Build both frontend and backend
make run          # Build and run the application
make dev-frontend # Run frontend dev server (with hot reload)
make dev-backend  # Run Go server (requires built frontend)
make clean        # Clean build artifacts

โ ๐Ÿ“– How It Works

โ Architecture
  • Backend: Go HTTP server with embedded frontend static files
  • Frontend: React with TypeScript, Tailwind CSS, and Framer Motion
  • Database: SQLite with GORM ORM
  • Real-time Updates: Server-Sent Events (SSE) for efficient streaming
  • Background Jobs:
    • Automatic service health checks based on individual intervals
    • Daily cleanup of check history older than 1 year (runs at midnight)
โ Monitoring
  • Services are checked via actual HTTP requests
  • Response times are measured and stored in the database
  • Uptime is calculated from the last 24 hours of check history
  • Stats are only calculated and broadcast when values change
  • Updates are streamed to clients via SSE (no polling needed)
โ Data Management
  • Check history is stored in SQLite for historical analysis
  • Automatic cleanup runs daily at 12:00 AM to remove data older than 1 year
  • Database uses WAL mode for better concurrency
  • All data persists in /data volume when using Docker

โ ๐Ÿ”Œ API Endpoints

โ REST API
  • GET /api/monitors - List all monitors
  • POST /api/monitors/create - Create a new monitor
  • GET /api/stats - Get overall statistics (only unpaused services)
  • GET /api/response-time?id=<id>&range=<range> - Get response time history
    • range options: 1h, 12h, 24h, 1w, 1y (default: 24h)
  • GET /api/monitor?id=<id> - Get specific monitor details
  • PUT /api/monitor?id=<id> - Update a monitor or toggle pause state
  • DELETE /api/monitor?id=<id> - Delete a monitor
โ Server-Sent Events (SSE)
  • GET /api/events - Real-time event stream
    • Event types: monitor_update, monitor_added, monitor_deleted, stats_update
    • Automatically reconnects on connection loss
    • Keepalive messages every 30 seconds

โ โš™๏ธ Configuration

โ Environment Variables
  • PORT - Server port (default: 8080)
  • DB_PATH - Database file path
    • Default: ./nanostatus.db (local) or /data/nanostatus.db (Docker)
โ Service Configuration

When creating a monitor, you can configure:

  • Name: Display name for the service
  • URL: Full URL to monitor (e.g., https://example.com)
  • Icon: Optional emoji icon
  • Check Interval: How often to check (10-3600 seconds, default: 60)
  • Third-party Service: Flag for external services

โ ๐ŸŽฏ Features in Detail

โ Service Management
  • Add Services: Create new monitors with custom check intervals
  • Edit Services: Update name, URL, icon, and check interval
  • Pause/Resume: Temporarily disable monitoring for specific services
  • Delete Services: Remove monitors and their history
โ Real-time Updates
  • SSE Streaming: All updates pushed instantly to connected clients
  • Change Detection: Stats only calculated and sent when values change
  • Debouncing: Rapid monitor updates are batched for efficiency
  • No Polling: Frontend receives updates via SSE, eliminating HTTP polling
โ Response Time History
  • Multiple Time Frames: View data for 1 hour, 12 hours, 1 week, or 1 year
  • Interactive Charts: Beautiful area charts with gradient fills
  • Time-based Formatting: Labels adapt to the selected time range
โ Statistics
  • Overall Uptime: Average uptime across all unpaused services
  • Service Counts: Number of services online/offline (unpaused only)
  • Average Response Time: Calculated from last 24 hours of check history
  • Real-time Updates: Stats update automatically when monitors change

โ ๐Ÿ—๏ธ Project Structure

.
โ”œโ”€โ”€ main.go              # Main server entry point and routing
โ”œโ”€โ”€ models.go            # Data models and structures
โ”œโ”€โ”€ database.go          # Database initialization and seeding
โ”œโ”€โ”€ checker.go           # Service health checking logic
โ”œโ”€โ”€ stats.go             # Statistics calculation
โ”œโ”€โ”€ sse.go               # Server-Sent Events broadcasting
โ”œโ”€โ”€ handlers.go          # HTTP API endpoint handlers
โ”œโ”€โ”€ cleanup.go           # Background cleanup jobs
โ”œโ”€โ”€ go.mod               # Go dependencies
โ”œโ”€โ”€ go.sum               # Go dependency checksums
โ”œโ”€โ”€ Dockerfile           # Standard multi-stage Docker build (distroless)
โ”œโ”€โ”€ Dockerfile.minimal   # Minimal Docker build with UPX compression (scratch)
โ”œโ”€โ”€ Makefile             # Build automation
โ”œโ”€โ”€ dist/                # Frontend build output (generated)
โ”œโ”€โ”€ nanostatus.db        # SQLite database (generated)
โ”œโ”€โ”€ src/                 # Frontend source code
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ App.tsx      # Main React component
โ”‚   โ”‚   โ”œโ”€โ”€ components/  # React components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Header.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ StatsGrid.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ServicesGrid.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ServiceCard.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ MonitorDetails.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ AddServiceDialog.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ EditServiceDialog.tsx
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ui/      # shadcn/ui components
โ”‚   โ”‚   โ”œโ”€โ”€ types/       # TypeScript type definitions
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ””โ”€โ”€ package.json
โ””โ”€โ”€ README.md

โ ๐Ÿ”ง Development

โ Building
# Build frontend
cd src
bun install
bun run build.ts --outdir=../dist

# Build backend
go build -o nanostatus main.go
โ Docker Build

The Dockerfile uses a multi-stage build:

  1. Frontend Builder: Builds React app with Bun
  2. Backend Builder: Compiles Go binary with embedded frontend
  3. Final Stage: Minimal distroless image (no shell, no package manager)

Result: Ultra-small, secure container (~16MB)

โ ๐Ÿ“ License

See LICENSE file for details.

โ ๐Ÿ™ Acknowledgments

Built with:

Tag summary

Content type

Image

Digest

sha256:cfb0ee69eโ€ฆ

Size

4.4 MB

Last updated

2 months ago

docker pull gjames8/nanostatus