Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

35 Commits

Folders and files

Repository files navigation

SentryNode

Production-grade, distributed server monitoring and telemetry infrastructure with lightweight Go agents, real-time metrics, interactive web terminals, Loki log streaming, and Next.js frontend console.

Go TypeScript Next.js Express Drizzle ORM Prometheus Grafana Loki Redis License: MIT


Table of Contents

  1. Overview
  2. System Architecture
  3. Key Features
  4. Tech Stack
  5. Getting Started
  6. Running the Platform
  7. Project Structure
  8. Available Scripts
  9. Testing
  10. Deployment & Agent Installation
  11. Configuration Reference
  12. Contributing
  13. License

Overview

SentryNode is a complete, full-stack infrastructure observability platform designed for DevOps and Site Reliability Engineering teams managing multi-server fleets. It bridges the gap between low-level kernel telemetry and human-friendly web operations by combining:

  • An ultra-fast, single-binary Go telemetry daemon running across Linux, macOS, and Windows nodes.
  • A central orchestration backend powered by Node.js, Express, TypeScript, and Drizzle ORM.
  • A Next.js web application featuring interactive dashboards, live LogQL stream viewers, real-time resource gauges, cron task runners, and browser-embedded xterm.js terminals.

System Architecture

flowchart TD
    subgraph Managed Nodes ["Managed Nodes / Remote Servers"]
        Agent1["SentryNode Agent<br/>(Linux/WSL)"]
        Agent2["SentryNode Agent<br/>(Windows/Darwin)"]
    end

    subgraph Observability ["Observability Infrastructure"]
        Prometheus["Prometheus (9090)<br/>• Pulls :8081 /metrics<br/>• Evaluates alert_rules.yml"]
        Loki["Grafana Loki (3100)<br/>• Ingests log streams"]
    end

    subgraph Orchestration ["SentryNode Backend (Port 8080)"]
        API["Express REST API (/api/v1)"]
        WSRelay["WebSocket Terminal & Stream Relay (/ws)"]
        AlertSync["Prometheus Alert Sync Loop"]
        DB[("PostgreSQL / SQLite<br/>(Drizzle ORM)")]
    end

    subgraph UserInterface ["SentryNode Web Console (Port 3000)"]
        Dashboard["Fleet Overview & Metrics"]
        TerminalUI["xterm.js Remote Terminal"]
        LogViewer["Live Loki Log Explorer"]
        TaskRunner["Remote Cron Task Dispatcher"]
    end

    Agent1 -- "Heartbeat & Registration" --> API
    Agent1 -- "Push Logs" --> API
    Agent1 -- "Interactive PTY Session" <--> WSRelay
    Agent2 -- "Push Logs" --> API
    
    API -- "Proxy Push (/api/v1/logs/push)" --> Loki
    Prometheus -- "HTTP Service Discovery" --> API
    Prometheus -- "Scrape Telemetry" --> Agent1
    AlertSync -- "Poll Active Alerts" --> Prometheus
    AlertSync --> DB
    API --> DB

    UserInterface <--> API
    TerminalUI <--> WSRelay
Loading

Key Features

  • 📊 Real-Time Host Telemetry: Live collection of CPU (per-core and aggregated), Memory, Disk I/O, Network throughput, 1/5/15-minute Load averages, and OS/hardware metadata.
  • 🐳 Docker Container Inspection: Live container discovery, CPU/memory stats, network I/O, restart counts, and container lifecycle events.
  • 🪵 Log Streaming & Loki Pipeline: Multi-file watcher, regex parser, batch accumulator, and automatic forwarding to Grafana Loki.
  • 💻 Browser-Based Remote Web Terminal: Interactive bidirectional shell terminal (xterm.js + PTY) over secure WebSockets directly into remote servers without opening SSH ports.
  • ⏰ Distributed Task Scheduling: Web-triggered and cron-scheduled script execution on remote hosts with command whitelisting and real-time execution logs.
  • 🚨 Automated Alerting & Notifications: Prometheus alert rule evaluation (alert_rules.yml) with automated status synchronization and persistent notification history.
  • ⚡ Redis Telemetry Cache & Rate Limiting: High-performance agent heartbeat/telemetry caching with zero-latency responses and distributed cluster-wide rate limiting (rate-limit-redis).
  • 🔐 Zero-Trust Agent Enrollment: Secure token-based registration flow with temporary enrollment tokens and permanent cryptographic credential generation.

Tech Stack

Component Technologies
Go Agent Go 1.25, gopsutil, gorilla/websocket, robfig/cron/v3, creack/pty, prometheus/client_golang
Backend API Node.js, Express, TypeScript, Drizzle ORM, ioredis, rate-limit-redis, Better-Auth, PostgreSQL (pg), ws, Pino, Swagger (swagger-ui-express)
Frontend UI Next.js 16 (App Router), React 19, Tailwind CSS v4, Radix UI / Shadcn, TanStack Query v5, Recharts, @xterm/xterm, Lucide Icons
Observability & Cache Prometheus v2.50, Grafana Loki 3.0, Redis 7.2
Tooling & CI Vitest, ESLint, Prettier, Husky, TypeScript, pnpm

Getting Started

Prerequisites

  • Go: 1.22+ (Go 1.24+ recommended)
  • Node.js: 20.x or 22.x LTS
  • Package Manager: pnpm 9+
  • Docker & Docker Compose: For running Prometheus and Loki services

Installation

  1. Clone the repository:

    git clone https://github.com/mahesh2-lab/Sentrynode.git
    cd Sentrynode
  2. Install Backend dependencies:

    cd backend
    pnpm install
    cd ..
  3. Install Frontend dependencies:

    cd frontend
    pnpm install
    cd ..

Environment Configuration

Backend Configuration (backend/.env)

Copy the template from backend/.env.example:

cp backend/.env.example backend/.env

Key environment variables:

# Server Configuration
NODE_ENV=development
PORT=8080
API_PREFIX=/api/v1

# Database Configuration (PostgreSQL or SQLite)
DATABASE_URL=postgres://postgres:postgres@localhost:5432/monitoring_db

# Security & Secrets
JWT_SECRET=your-secret-jwt-key-min-32-chars-long!
BETTER_AUTH_SECRET=your-better-auth-secret-min-32-chars!
BETTER_AUTH_URL=http://localhost:8080
FRONTEND_URL=http://localhost:3000
CORS_ORIGIN=http://localhost:3000,http://localhost:5173

# Prometheus Target Discovery Host
PROMETHEUS_AGENT_HOST=host.docker.internal

Frontend Configuration (frontend/.env)

NEXT_PUBLIC_AUTH_URL=http://localhost:8080

Running the Platform

1. Start Observability Stack (Prometheus & Loki)

Launch Prometheus and Loki in the background using Docker Compose:

cd configs
docker compose up -d
cd ..
  • Prometheus UI: http://localhost:9090
  • Loki Push Endpoint: http://localhost:3100

2. Start Backend API Server

Run database migrations and start the development server:

cd backend
pnpm db:migrate
pnpm dev

The Backend API will be available at http://localhost:8080.

  • Swagger Documentation: http://localhost:8080/docs
  • Health Check: http://localhost:8080/health
  • Prometheus Targets: http://localhost:8080/api/v1/prometheus/targets

3. Start Frontend Web Console

In a new terminal, start the Next.js frontend:

cd frontend
pnpm dev

Open http://localhost:3000 in your browser.


4. Run or Install the SentryNode Agent

Option A: Run Agent from Source

cd agent
go run ./cmd/agent

Option B: Authenticate Agent with Enrollment Token

Generate an enrollment token in the web console under /setup or /settings, then start the agent:

cd agent
go run ./cmd/agent --auth-token "YOUR_ENROLLMENT_TOKEN"

Project Structure

.
├── agent/                         # Go Telemetry Monitoring Agent
│   ├── cmd/agent/main.go          # Agent daemon entrypoint
│   ├── internal/
│   │   ├── collector/             # CPU, Memory, Disk, Network, Host, Docker metrics
│   │   ├── config/                # YAML configuration & JSON credentials loader
│   │   ├── events/                # System & container event telemetry
│   │   ├── executor/              # Cron task scheduler & command executor
│   │   ├── exporter/              # Standalone Prometheus HTTP exporter (:8081)
│   │   ├── lock/                  # Cross-platform single instance file lock
│   │   ├── logs/                  # File watcher, parser & Loki log shipper
│   │   ├── terminal/              # Interactive PTY web terminal session manager
│   │   └── transport/             # HTTP client, WebSocket client, retry policies
│   ├── go.mod                     # Go module definition (sentrynode-agent)
│   └── install.sh                 # Linux shell installation script
│
├── backend/                       # Node.js / Express / TypeScript Backend
│   ├── src/
│   │   ├── app.ts                 # Express application factory & middleware setup
│   │   ├── index.ts               # HTTP & WebSocket server bootstrap
│   │   ├── auth.ts                # Better-Auth authentication configuration
│   │   ├── config/                # Environment, JWT, DB, and Swagger configs
│   │   ├── db/                    # Drizzle ORM schemas, migrations, relations
│   │   ├── middleware/            # Hybrid auth, RBAC, rate-limiting, error handlers
│   │   └── modules/               # Domain modules (agents, alerts, logs, metrics, etc.)
│   ├── tests/                     # Vitest unit & integration test suites
│   └── package.json               # Backend package manifest (sentrynode-backend)
│
├── frontend/                      # Next.js 16 Web Dashboard & Console
│   ├── app/                       # App Router routes (servers, metrics, logs, terminal, etc.)
│   ├── src/
│   │   ├── components/            # Reusable UI cards, tables, gauges, xterm terminal
│   │   ├── hooks/                 # Data-fetching hooks (React Query, Prometheus, Loki)
│   │   └── lib/                   # Utility functions & auth clients
│   └── package.json               # Frontend package manifest (sentrynode-frontend)
│
├── configs/                       # Infrastructure & Deployment Assets
│   ├── docker-compose.yml         # Prometheus & Loki stack
│   ├── prometheus.yml             # Prometheus scrape configuration
│   ├── alert_rules.yml            # Prometheus alerting rules
│   ├── config.yaml                # Default agent configuration template
│   ├── Dockerfile.agent           # Multi-stage Dockerfile for Go Agent
│   ├── Dockerfile.backend         # Dockerfile for Backend API
│   ├── build.ps1 / build.sh       # Multi-arch agent cross-compilation scripts
│   └── deploy-wsl.ps1             # Local WSL deployment helper
│
└── BACKEND_DOCUMENTATION.md       # Detailed architectural and API documentation

Available Scripts

Backend (/backend)

Command Description
pnpm dev Start backend in development mode with live reload (tsx watch)
pnpm build Bundle backend for production with tsup
pnpm start Run compiled production build from dist/index.js
pnpm db:migrate Apply pending database schema migrations
pnpm db:generate Generate Drizzle migrations from schema definitions
pnpm db:studio Open Drizzle Studio visual database inspector
pnpm test Run backend unit and integration tests with vitest
pnpm lint Lint codebase with ESLint
pnpm typecheck Run TypeScript type checking without emitting files

Frontend (/frontend)

Command Description
pnpm dev Start Next.js development server on http://localhost:3000
pnpm build Create optimized production Next.js build
pnpm start Start production Next.js server
pnpm test Run frontend component and hook tests with vitest
pnpm typecheck Validate TypeScript types across frontend
pnpm lint Run Next.js ESLint verification

Agent (/agent)

Command Description
go run ./cmd/agent Run agent directly from source
go test ./... Run unit tests across all internal packages
go build -o ../bin/sentrynode ./cmd/agent Build native executable

Testing

Run Backend Tests

cd backend
pnpm test

Run Frontend Tests

cd frontend
pnpm test

Run Go Agent Tests

cd agent
go test -v ./...

Deployment & Agent Installation

Linux / WSL One-Line Installer

The backend serves an automated installer script that configures the agent binary, directory structure, environment variables, and systemd daemon:

curl -sSL http://<YOUR_BACKEND_HOST>:8080/install.sh | sudo bash -s -- --auth-token "<YOUR_ENROLLMENT_TOKEN>"

Start and manage the service on the target machine:

# Check status
sudo systemctl status sentrynode

# View live logs
sudo journalctl -u sentrynode -f

Cross-Platform Binary Compilation

Compile lightweight, statically linked binaries for all target architectures using the provided build scripts:

Linux / macOS:

chmod +x configs/build.sh
./configs/build.sh

Windows (PowerShell):

.\configs\build.ps1

Generated outputs in bin/:

  • agent-linux-amd64
  • agent-linux-arm64
  • agent-windows-amd64.exe
  • agent-darwin-amd64
  • agent-darwin-arm64

Docker Deployment

To run the full stack with Docker:

# Build & run services
docker compose -f configs/docker-compose.yml up -d

Configuration Reference

Backend Environment Variables

Variable Default Description
PORT 8080 HTTP and WebSocket listening port
NODE_ENV development Environment mode (development, production, test)
DATABASE_URL — Connection string for PostgreSQL or SQLite
JWT_SECRET — Cryptographic secret for signing access tokens
BETTER_AUTH_SECRET — Cryptographic secret for Better-Auth session tokens
CORS_ORIGIN http://localhost:3000 Allowed origins for cross-origin requests
PROMETHEUS_AGENT_HOST host.docker.internal Hostname used by Prometheus to reach node exporters
REDIS_URL redis://localhost:6379 Connection string for Redis cache & rate limiter
ENABLE_REDIS true Enable or disable Redis caching and distributed rate limiting

Contributing

  1. Fork the repository on GitHub.
  2. Create a branch for your feature or bugfix (git checkout -b feat/my-new-feature).
  3. Commit changes following the Conventional Commits convention (git commit -m "feat(agent): add gpu telemetry").
  4. Push to your fork (git push origin feat/my-new-feature).
  5. Open a Pull Request with a description of your changes and test coverage.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages