Skip to content

digin1/NodePrism

Repository files navigation

NodePrism

NodePrism

Open-source server monitoring for KVM, OpenVZ, Virtuozzo, Docker, LXC, and cPanel
Self-hosted alternative to Datadog/New Relic. Monitor servers, containers, databases, web servers, and mail servers with Prometheus, Grafana, intelligent alerting, and ML anomaly detection.

FeaturesQuick StartArchitectureDocsContributing

License Node.js pnpm TypeScript Tests


Features

Monitoring & Metrics

  • Real-time System Monitoring — CPU, memory, disk, network, and load average with live WebSocket updates
  • Multi-platform Containers — OpenVZ, KVM/libvirt, Virtuozzo, Docker, and LXC container management with storage pool and network traffic tracking
  • LVM/Disk Monitoring — Volume group tracking, partition free space, and disk pressure handling
  • Uptime Monitoring — HTTP/HTTPS, TCP, ICMP (ping), and DNS checks with response time tracking and keyword matching
  • Log Aggregation — Centralized log storage and querying via Loki + Promtail

Alerting & Notifications

  • Intelligent Alerting — PromQL-based alert rules with dual thresholds (warning + critical), hysteresis, and multi-stage evaluation
  • 6 Notification Channels — Slack (with interactive buttons), Telegram, Email (SMTP), Discord, Webhooks, and PagerDuty
  • Slack Interactions — Acknowledge, silence, or create incidents directly from Slack notification buttons
  • Alert Reconciliation — Auto-resolves stale alerts missed by AlertManager
  • Maintenance Windows — Suppress alerts during scheduled maintenance

Intelligence

  • Anomaly Detection — ML-based scoring using K-means clustering with automatic model retraining and configurable sensitivity per server
  • Forecasting — Linear regression-based disk and resource usage trend prediction with 30-day projections
  • Daily Infrastructure Reports — Automated Slack/Telegram summaries with VM counts, stopped containers, disk usage, and mail server stats

Operations

  • Incident Management — Create, track, and resolve incidents with status workflow (Investigating → Identified → Monitoring → Resolved) and timeline updates
  • Custom Dashboards — Build and share dashboards with PromQL-powered panels
  • 14 Pre-built Grafana Dashboards — System overview, API metrics, containers, server details, MySQL, PostgreSQL, MongoDB, Nginx, Apache, LiteSpeed, Exim, cPanel, network traffic, and anomaly detection
  • Audit Logging — Tracks all admin actions (server changes, alert rules, user roles, incident updates)
  • Automated Housekeeping — Configurable retention policies with disk pressure-aware cleanup and PostgreSQL VACUUM
  • Database Backups — Automated pg_dump with gzip compression, configurable schedule and retention

Security

  • JWT Authentication — Role-based access control (Admin/User) with configurable token expiry
  • Reverse Proxy — Nginx with rate limiting, security headers (X-Frame-Options, CSP, XSS protection), and gzip compression
  • SSL/TLS Ready — Let's Encrypt ACME support with certificate configuration
  • Slack Signature Verification — HMAC-SHA256 request validation for webhook security

Quick Start

Prerequisites

  • Ubuntu/Debian Linux (tested on Ubuntu 22.04/24.04, Debian 12)
  • 2+ CPU cores, 4GB+ RAM recommended

One-Line Deploy

curl -sL https://raw.githubusercontent.com/digin1/NodePrism/main/deploy.sh | sudo bash

This installs Docker, Node.js 20, pnpm, PM2, clones the repo, configures .env (auto-detects server IP, generates JWT secret), starts all infrastructure containers, builds and launches the app with PM2.

Manual Installation

# Clone the repository
git clone https://github.com/digin1/NodePrism.git
cd NodePrism

# Copy env file and configure
cp .env.example .env
# Edit .env — set SERVER_IP to your server's public IP

# Initialize Prometheus config files
bash infrastructure/docker/init-prometheus.sh

# Symlink .env for Docker Compose
ln -sf "$(pwd)/.env" infrastructure/docker/.env

# Install dependencies
pnpm install

# Start infrastructure services (PostgreSQL, Redis, Prometheus, etc.)
pnpm docker:up

# Build and start the application with PM2
pnpm run build && pnpm run start:pm2

Access

Service URL Credentials
Web UI http://<server-ip>:3000 Register on first visit
Grafana http://<server-ip>:3000/grafana/ admin / admin
Prometheus http://<server-ip>:3000/prometheus/
AlertManager http://<server-ip>:3000/alertmanager/
API http://<server-ip>:4000
Documentation Online docs

Grafana, Prometheus, and AlertManager are proxied through the Web UI on port 3000 — session-authenticated and accessible from a single origin.

Adding Remote Servers

Install the NodePrism agent on any server you want to monitor:

curl -sL http://<nodeprism-ip>:3000/agent-install.sh | sudo bash

The agent auto-registers with the manager and begins shipping metrics, container stats, and logs.

Supported agent/exporter types:

Agent Port What it monitors
Node Exporter 9100 CPU, memory, disk, network, load
App Agent 9101 Custom application metrics
MySQL Exporter 9104 MySQL/MariaDB databases
Nginx Exporter 9113 Nginx web server
Apache Exporter 9117 Apache web server
PostgreSQL Exporter 9187 PostgreSQL databases
MongoDB Exporter 9216 MongoDB databases
Redis Exporter Redis instances
Libvirt Exporter KVM/libvirt virtual machines
LiteSpeed Exporter LiteSpeed web server
Exim Exporter Exim mail server
cPanel Exporter cPanel/WHM hosting panels
Promtail 9080 Log shipping to Loki

Architecture

NodePrism Architecture

Data Flow

NodePrism Data Flow

  • Metrics — Prometheus scrapes exporters on remote servers via file-based service discovery (target files generated by Config Sync)
  • Agents — Remote agents POST to /api/agents/register, then send heartbeats every 30s
  • Alerts — Prometheus fires rules → AlertManager → webhook to API → notifications (Slack/Telegram/Email/Discord/Webhook/PagerDuty) + Socket.IO events
  • Anomaly Detection — Queries Prometheus for 4-hour windows, trains K-means models (Redis), scores every 10s
  • Logs — Promtail ships logs to Loki, queryable through Grafana
  • Proxy — Grafana, Prometheus, AlertManager bind to 127.0.0.1 only, proxied through Next.js :3000 with session auth

Services (PM2-managed)

Service Port Role
Web UI :3000 Next.js dashboard, proxies monitoring tools
API :4000 REST API, Socket.IO, webhook handlers, Prisma ORM
Config Sync :4002 Generates Prometheus targets from DB, syncs status back
Anomaly Detector :4003 ML pipeline — trains K-means models, scores metrics
Agent :9101 Runs on each server, exposes /metrics, sends heartbeats

Project Structure

NodePrism/
├── packages/
│   ├── web/                  # Next.js 14 — Management UI
│   ├── api/                  # Express — REST API + Socket.IO + Prisma
│   ├── config-sync/          # Prometheus target & status sync worker
│   ├── anomaly-detector/     # K-means clustering anomaly detection
│   ├── agent-app/            # Remote server monitoring agent
│   └── shared/               # Shared TypeScript types & Zod schemas
│
├── infrastructure/
│   └── docker/               # Docker Compose + service configs
│       ├── prometheus/       # Prometheus config, alert rules, targets
│       ├── grafana/          # Datasources + 14 pre-built dashboards
│       ├── alertmanager/     # Alert routing config
│       ├── loki/             # Log aggregation config
│       └── nginx/            # Reverse proxy with rate limiting & security
│
├── docs-site/                # Docusaurus documentation site
├── scripts/                  # Setup, cert generation, agent download scripts
├── deploy.sh                 # One-line deployment script
└── ecosystem.config.js       # PM2 production process config

Tech Stack

Layer Technologies
Frontend Next.js 14, React 18, TanStack Query, Tailwind CSS, Recharts, Socket.IO Client
Backend Node.js, Express, Socket.IO, Prisma ORM, Zod
Database PostgreSQL 15, Redis 7
Monitoring Prometheus, Grafana, Loki, AlertManager, Pushgateway
ML simple-statistics, ml-kmeans (anomaly detection & forecasting)
Infrastructure Docker Compose, PM2, Nginx, Turborepo, pnpm workspaces
Language TypeScript (strict mode)

Production (PM2)

NodePrism runs 5 services managed by PM2 with auto-restart, memory limits, and systemd boot persistence:

Service Memory Limit Purpose
nodeprism-api 500 MB REST API + WebSocket gateway
nodeprism-web 500 MB Next.js frontend
nodeprism-config-sync 300 MB Prometheus target sync
nodeprism-anomaly-detector 768 MB ML anomaly pipeline
nodeprism-agent 200 MB Local agent (manager node)
pnpm run build && pnpm run start:pm2   # Build and start all services
pnpm run status:pm2                     # Check service status
pnpm run logs:pm2                       # Tail all logs
pnpm run stop:pm2                       # Stop all services
pnpm run restart:pm2                    # Restart all services

Configuration

Copy .env.example to .env and configure. Key settings:

Variable Default Description
SERVER_IP Your server's public IP (required)
JWT_SECRET Random string for token signing (required)
DB_PASSWORD nodeprism123 PostgreSQL password
GRAFANA_PASSWORD admin123 Grafana admin password
DAILY_REPORT_TIME 08:00 When to send daily reports
BACKUP_SCHEDULE_HOURS 24 Database backup interval
BACKUP_RETENTION_COUNT 7 Number of backups to keep

See .env.example for all 60+ configuration options.

Development

# Development mode (hot reload)
pnpm run dev

# Run tests (725 tests across 36 suites)
pnpm test

# Run tests with coverage
pnpm test:coverage

# Lint all packages
pnpm lint

# Format code
pnpm format

Docker Commands

pnpm docker:up      # Start all infrastructure services
pnpm docker:down    # Stop all services
pnpm docker:logs    # View logs

Documentation

Full documentation is available online and locally:

Topics covered: architecture, API reference, database schema, deployment, monitoring & alerting setup, and agent configuration.

Contributing

Contributions are welcome! Please:

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

Disclaimer

This software is provided "as is" and at your own risk. The authors and contributors are not responsible for any data loss, system downtime, security breaches, or any other damages resulting from the use of this software. You are solely responsible for maintaining backups, evaluating suitability for your environment, and ensuring proper security configurations. Use in production is at your own discretion and risk.

License

This project is licensed under the MIT License — see the LICENSE file for details.

About

Open-source server monitoring for KVM, OpenVZ, Virtuozzo, Docker, LXC, and cPanel. Prometheus + Grafana dashboards, intelligent alerting, ML anomaly detection. Self-hosted Datadog/Netdata alternative.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages