HUB
Sign inSign up
clearwatch logo

ritejmule2610/clearwatch

By ritejmule2610

•Updated 24 days ago

Self-hosted server & database monitoring with live dashboard and alerts. Single small container.

Image
Monitoring & observability
1

202

ritejmule2610/clearwatch repository overview

⁠Clearwatch

Self-hosted monitoring for your servers and databases, in one small container.

Image size Pulls Platform

⁠What is Clearwatch?

Clearwatch is a small monitoring tool that you run yourself. You start one container and it:

  1. Measures your machine (CPU, memory, disk, network, load, busiest processes) and, if you want, your PostgreSQL and MySQL databases (connections, size, speed, locks, slow queries, replication lag).
  2. Remembers the last 24 hours in a small file inside the container, so you can see what happened an hour ago, not only right now.
  3. Shows it on a live dark-mode dashboard at http://your-server:8080/.
  4. Tells you on Telegram, Slack, Discord or any webhook when something is wrong (disk almost full, database down, CPU stuck high) and again when it is fixed.

It is one program with no database to install, no agent to roll out and no cloud account. It uses about 19 MB of RAM and well under 1 % of a CPU core.

⁠Is it for me?
Clearwatch fits if you...Look elsewhere if you...
run one or a few servers or VMs and want to know when something breaksneed to monitor hundreds of machines from one place
want a dashboard and alerts in five minutes, not a weekendneed months of history (Clearwatch keeps 24 h by default)
want to watch a PostgreSQL or MySQL database's healthneed to monitor the contents of your data (business metrics)
prefer a tiny tool you can read and trustneed Windows or ARM hosts (linux/amd64 only for now)

⁠How it works

 /proc, /sys ──┐
 PostgreSQL ───┼─> collectors ─> SQLite file (24 h) ─> dashboard, JSON API, Prometheus
 MySQL ────────┘        │
                        └──────> alert engine ──> Telegram / Slack / Discord / webhook
  • Collectors read the host's /proc and /sys (you mount them into the container, read-only) every 10 s, and ask each database for its statistics every 30 s.
  • Storage is an embedded SQLite file in /data. Old data is deleted automatically.
  • Alerts are evaluated on the same stored data you see on the dashboard. An alert fires only after the problem lasts 3 minutes (so short spikes are ignored), repeats every 30 minutes while it continues, and sends a Resolved message when it clears.
  • A broken database or a failing collector never stops Clearwatch. It shows as Down with the reason and is retried every cycle.

⁠Get started in 5 steps

You need a Linux server with Docker installed.

⁠Step 1. Start it
docker run -d --name clearwatch --restart unless-stopped \
  -p 127.0.0.1:8080:8080 \
  -v clearwatch-data:/data \
  -v /proc:/host/proc:ro \
  -v /sys:/host/sys:ro \
  -e CLEARWATCH_INSTANCE_NAME=my-server \
  ritejmule2610/clearwatch:latest

127.0.0.1: keeps the dashboard private to the server itself until you add a password (step 3). CLEARWATCH_INSTANCE_NAME is the name shown on the dashboard and in alerts.

⁠Step 2. Check that it works
docker ps                                                        # status should say "healthy" after ~30 s
curl http://127.0.0.1:8080/healthz                               # prints OK
docker exec clearwatch /clearwatch version

Open http://127.0.0.1:8080/⁠. Charts start filling after one or two collection intervals (about 20 s). On a remote server, reach it from your laptop with ssh -L 8080:127.0.0.1:8080 user@server, then open http://localhost:8080/⁠.

⁠Step 3. Protect it

Remove the container (docker rm -f clearwatch; your data stays in the volume) and start it again with a login and an API key added:

docker run -d --name clearwatch --restart unless-stopped \
  -p 127.0.0.1:8080:8080 \
  -v clearwatch-data:/data -v /proc:/host/proc:ro -v /sys:/host/sys:ro \
  -e CLEARWATCH_INSTANCE_NAME=my-server \
  -e CLEARWATCH_AUTH_USER=admin \
  -e CLEARWATCH_AUTH_PASS='use-a-long-password' \
  -e CLEARWATCH_API_KEY="$(openssl rand -hex 24)" \
  ritejmule2610/clearwatch:latest

The dashboard now asks for the username and password. Scripts can use curl -H "Authorization: Bearer <key>". /healthz stays open so Docker and load balancers can still check it. To make it reachable from other machines, put a TLS reverse proxy (Caddy or nginx) in front of port 8080. Do not publish a password-protected port over plain HTTP.

⁠Step 4. Turn on alerts

Add one or more of these -e options to the docker run command, then recreate the container:

-e CLEARWATCH_TELEGRAM_BOT_TOKEN='123456:ABC...' -e CLEARWATCH_TELEGRAM_CHAT_ID='-1001234567890'
-e CLEARWATCH_WEBHOOK_URL='https://hooks.slack.com/services/T000/B000/XXXX'

Then send a test message to every channel you configured:

docker exec clearwatch /clearwatch test-alert

If the message arrives, alerts work. Default thresholds: CPU 90 %, memory 90 %, disk 85 %.

⁠Step 5. (Optional) Monitor a database

Create a read-only user for Clearwatch, then pass its connection string.

PostgreSQL 10+

CREATE ROLE clearwatch LOGIN PASSWORD 'a-long-random-password';
GRANT pg_monitor TO clearwatch;                 -- statistics only, no table data
GRANT CONNECT ON DATABASE app TO clearwatch;
ALTER ROLE clearwatch SET default_transaction_read_only = on;
-- optional, for "Top queries" (also needs shared_preload_libraries = 'pg_stat_statements'):
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
-e CLEARWATCH_POSTGRES_DSN='postgres://clearwatch:[email protected]:5432/app?sslmode=require'

MySQL 5.7 / 8.x

CREATE USER 'clearwatch'@'10.0.0.%' IDENTIFIED BY 'a-long-random-password' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT ON *.* TO 'clearwatch'@'10.0.0.%';
GRANT SELECT ON performance_schema.* TO 'clearwatch'@'10.0.0.%';   -- Top queries
GRANT SELECT ON app.* TO 'clearwatch'@'10.0.0.%';                   -- table sizes only
-e CLEARWATCH_MYSQL_DSN='mysql://clearwatch:[email protected]:3306/app'

The dashboard gains a database card within one interval (30 s). Notes:

  • Inside a container, localhost means the container itself. Put Clearwatch on the database's Docker network, or use the database's hostname or host.docker.internal.
  • Every statistics query runs in a read-only transaction with timeouts. Passwords in connection strings are never logged.
  • For several databases, or per-database options, use an optional YAML file (CLEARWATCH_CONFIG).

⁠Docker Compose

services:
  clearwatch:
    image: ritejmule2610/clearwatch:latest
    restart: unless-stopped
    ports: ["127.0.0.1:8080:8080"]
    volumes:
      - clearwatch-data:/data
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
    environment:
      CLEARWATCH_INSTANCE_NAME: my-server
      CLEARWATCH_AUTH_USER: admin
      CLEARWATCH_AUTH_PASS: change-me-please
    cap_drop: [ALL]
    security_opt: ["no-new-privileges:true"]

volumes:
  clearwatch-data:

⁠What you can monitor

  • Host: CPU (total and per core), memory and swap, load, disk usage and I/O, network, uptime, top processes by CPU and memory.
  • PostgreSQL / MySQL: connections against the limit, database size, throughput, cache hit ratio, lock waits, longest query and transaction, replication lag, per-table size and write rates, top queries.

⁠Alerts

RuleDefaultFires when
High CPU usage90 %total CPU is at or above the threshold
High memory usage90 %RAM used (excluding reclaimable cache)
Disk almost full85 %any monitored filesystem
Database connections near the limit80 %connections / max_connections
Database replication lag30 sa replica falls behind
Database unreachableona database cannot be reached

⁠Configuration

Everything has a default. Set options with -e NAME=value; a YAML file is optional.

VariableDefaultMeaning
CLEARWATCH_INSTANCE_NAMEhost nameName shown in the dashboard and alerts. Set it: in Docker the host name is the container ID
CLEARWATCH_INTERVAL10sHost collection interval
CLEARWATCH_RETENTION_RAW24hHow long samples are kept
CLEARWATCH_AUTH_USER / _PASSunsetHTTP Basic auth (password 8+ characters)
CLEARWATCH_API_KEYunsetBearer key for scripts (16+ characters)
CLEARWATCH_POSTGRES_DSN / CLEARWATCH_MYSQL_DSNunsetDatabase to monitor (one per engine; more in YAML)
CLEARWATCH_DB_INTERVAL30sDatabase collection interval
CLEARWATCH_TELEGRAM_BOT_TOKEN / _CHAT_IDunsetTelegram alerts
CLEARWATCH_WEBHOOK_URLunsetJSON webhook (Slack, Discord, custom)
CLEARWATCH_ALERT_CPU_PERCENT, _MEMORY_PERCENT, _DISK_PERCENT90, 90, 85Thresholds (0 disables a rule)
CLEARWATCH_ALERT_DURATION / _COOLDOWN3m / 30mHow long a problem must last before alerting / repeat interval
CLEARWATCH_COLLECTOR_<NAME>_ENABLEDtrueTurn one collector off, e.g. NETWORK
CLEARWATCH_DISK_PATHS/dataFilesystems to monitor

⁠API

EndpointDescription
GET /Dashboard
GET /healthzHealth check (always public)
GET /metricsClearwatch's own health, Prometheus format
GET /api/v1/latestNewest value of every series
GET /api/v1/query?name=…&range=1hTime series (from/to, step, label.<key>=…)
GET /api/v1/alertsPending and firing alerts
GET /api/v1/collectorsStatus and last error of each collector

⁠Troubleshooting

SymptomLikely cause and fix
Charts stay emptyWait 20-30 s. Check docker logs clearwatch and /api/v1/collectors
Container shows unhealthydocker logs clearwatch. Usually /data is not writable (see below)
Database card says DownWrong host (localhost inside a container), wrong password, or no network route. The reason is shown on the card
No "Top queries" on PostgreSQLpg_stat_statements is not loaded (shared_preload_libraries)
Test alert does not arriveCheck the token, chat ID or URL. docker logs clearwatch shows the delivery error with secrets removed
Host numbers look like a container's/proc and /sys are not mounted. Add the two -v options from step 1

⁠Security

  • Turn on authentication, or keep the 127.0.0.1: prefix, before exposing the port. Use TLS in front.
  • The image is distroless and static, runs as a non-root user (uid 65532), has no shell and needs no capabilities. Mount /proc and /sys read-only.
  • Credentials, tokens, webhook URLs and database passwords are never logged and are scrubbed from error messages. The dashboard uses a strict Content-Security-Policy with no external requests.

⁠Size and resource use

Measured with default settings on a small VM:

Download (compressed)6.4 MB
On disk (unpacked)about 16 MB
Program13 MB static binary on a distroless base
Memoryabout 19 MB RSS
CPUabout 0.6 % of one core
Dataabout 26 bytes per sample, roughly 13 MB per day for a typical host

⁠Good to know

  • Host data comes from the host's /proc and /sys mounted into the container. Network shows the container's own interface; use --network host to see the host's network cards.
  • Disk usage is the filesystem behind /data by default. To see every host filesystem add -v /:/host/root:ro -e CLEARWATCH_DISK_PATHS= -e CLEARWATCH_DISK_HOST_ROOT=/host/root.
  • With a bind mount for /data, make it writable by uid 65532 (chown 65532 /your/dir).
  • Table row counts are the database's estimates, not count(*).
  • Single node, linux/amd64. History is the raw retention window (24 h by default); long-term rollups are not included yet.
  • Clearwatch monitors the health of your host and databases, not the business data inside them.

⁠Tags

TagMeaning
latestNewest build of the main branch
sha-<commit>One exact build. Pin to one of these for repeatable deployments

Every build is tested in CI before it is published: unit tests with the race detector, lint, integration tests against real PostgreSQL 16 and MySQL 8.0, and a smoke test of the final image (healthy, all collectors running, authentication enforced, databases reporting).

Tag summary
Recent tags
Content type
Image
Digest
sha256:3bf5c04e3…
Size
6.4 MB
Last updated
24 days ago
docker pull ritejmule2610/clearwatch:latest