MONA

MONA: monitoring and analytics for any device

MONA

  • //MCP
  • //Self-hosted
  • //Monitor anything
  • //One-command deploy

Mona is a monitoring and analytics system that scrapes any device and detects anomalies

Monitor

Analyze

Isolation Forest for anomaly detection, FastAPI for the backend, React for the frontend, Terraform, Kubernetes (kind) and Docker for infra

// Features

Metrics in, anomalies out

// 01

Anomaly detection

Isolation Forest on delta features. A score threshold, plus a rule that ignores combined anomalies while CPU and RAM stay under 80%, keeps false positives down.

anomaly

Last 30–500 points, retrained before every detection (every 30 s by default). The model is not stored.

// 02

One-command deploy

Terraform and Helm bring up a kind cluster. Init containers hold the API and workers until Postgres is ready, and probes report liveness and readiness.

$make allLinux, macOS
>.\deploy.ps1 -allWindows
// 03

Role-based access

Cookie sessions backed by Redis: a cryptographically secure 32-byte token in an HttpOnly cookie, valid for 12 hours.

GETPOSTPUTDELETEadminallowedallowedallowedalloweduseralloweddenieddenieddenied

401 no session / 403 role not allowed

// 04

Observability stack

Prometheus scrapes your devices and the cluster. Grafana and the built-in React dashboards show it, Loki and Promtail collect pod logs, Alertmanager sends pod alerts.

metrics

Prometheus

dashboards

GrafanaReact + Recharts

logs

LokiPromtail

alerts

Alertmanager

The Docker Compose setup runs without Grafana, Loki and Alertmanager

// Setup

Deployment

MONA runs in two ways. Both give you the same API, Celery workers and web UI. They differ in the monitoring stack around them.

Requirements & steps

  1. 01Install Docker Desktop, kind, helm and Terraform
  2. 02Run node exporter on every device you want to monitor (port 9100)
  3. 03Clone the repository
  4. 04Copy terraform/terraform.tfvars.example to terraform/terraform.tfvars and fill in the required accounts and passwords
  5. 05Deploy with the script for your OS
Clone repository
git clone https://github.com/gwill1337/MONA.git
cd MONA
Windows (PowerShell)
.\deploy.ps1 -all # or .\deploy.ps1 -deploy
Linux and macOS
make all

After changing code

Images are built locally as mona-*:local and loaded into the kind cluster on every apply. Run build first, then deploy.

// Architecture

From device to dashboard

A metric travels from the machine to the screen. PostgreSQL is the hub: everything either writes to it or reads from it.

  1. // source

    Devices

    Any machine you want to watch runs node-exporter. Add it in values.yaml, or on the fly from the admin panel.

    port
    9100
    add via
    values.yaml or admin panel
    api
    POST and DELETE /api/v1/devices
  2. // scrape

    Prometheus

    Scrapes the devices. Its target list comes from a dedicated FastAPI endpoint, so both ways of adding devices end up in one list.

    targets
    /api/prometheus/targets
    auth
    none, on purpose
    instances
    devices, plus the cluster (Kubernetes only)
  3. // collect

    Celery workers

    Collect the scraped metrics and write them to PostgreSQL. ML runs as Celery tasks too, so the API stays responsive.

    broker
    Redis
    tasks
    metrics collection, ML training and detection
    status
    /api/v1/task-status/{task_id}
  4. // store

    PostgreSQL

    The hub. Metrics go in, anomalies are written back, and everything else reads from here. Runs as a StatefulSet.

    tables
    devices, metrics, anomalies, trained_models, users, api_keys
    api_keys
    belongs to the MCP server
    startup
    API and Celery pods wait for it via init containers
  5. // detect

    Isolation Forest

    A Celery task reads recent metrics from PostgreSQL, scores them with scikit-learn and writes any anomalies back.

    features
    metrics and their deltas
    contamination
    0.05
    score threshold
    -0.05
    combined anomalies
    ignored while CPU and RAM are under 80%
    auto
    latest 30–500 points, every 30 s by default
    manual
    your time range, model saved in PostgreSQL
  6. // serve

    FastAPI

    Returns data from PostgreSQL whenever an endpoint is called. The REST API sits behind cookie sessions.

    session
    32-byte token, HttpOnly cookie, 12 h
    roles
    user: GET only. admin: all methods
    redis
    sessions, rate limiter, task status
    probes
    /health/live and /health/ready
  7. // show

    React UI

    Polls the API on an interval and assembles the dashboards from the responses.

    pages
    dashboard, userboard, admin panel
    charts
    Recharts
  8. // ai tools

    MCP server

    Gives AI agents access to MONA. It sits outside the chain: most tools query PostgreSQL directly, a few go through Celery and Redis or the backend's HTTP API.

    postgresql, directly
    9 tools: devices, metrics, anomalies and models, via SQLAlchemy
    celery and redis
    2 tools: train_anomaly_model, get_task_status
    fastapi, over http
    2 tools: get_mona_health, get_prometheus_targets
    prompts
    diagnose_mona, investigate_anomaly
    resources
    mona://docs/overview and mona://docs/metrics, static text bundled in the code
    api_keys
    a table in PostgreSQL, used by the MCP server

runs on kind, Terraform and Helm, or Docker Compose without Grafana, Loki and Alertmanager