Private Databases
Monitor PostgreSQL, MySQL, Redis and MongoDB — by connecting to them directly, or through the Zharp agent when they aren't reachable from the internet.
All four engines sit behind one entry in the type picker, Database monitor. Its first field, Connection, decides how the database is checked:
| Connection | How it works | Use it when |
|---|---|---|
| Public | Zharp's checkers connect to the database on every check and run a query. | The database accepts connections from the internet. |
| Private | The Zharp agent, on a server next to the database, reports on it. Zharp never connects to the database. | The database is behind a firewall or on a private network. |
Public: Zharp connects directly
- 1Pick the type
On the Monitors page click New, choose Database monitor under Monitor type, and leave Connection on Public.
- 2Paste a connection string
Connection string takes the full URI, credentials included. Its scheme decides the engine:
postgres://orpostgresql://,mysql://ormariadb://,mongodb://ormongodb+srv://,redis://orrediss://.postgresql://monitor:secret@db.example.com:5432/production
Prefer separate fields? Click Enter details instead and fill in Database type, Host, Database name, Username and Password. Database name is required for PostgreSQL and MySQL; Redis takes a password only. MongoDB also has Auth database, the database the user is defined in —
adminwhen left empty, which is where Atlas and most installations keep their users. - 3Adjust the connection settings (optional)
Under Advanced settings → Connection settings:
Setting Default What it does Port The engine's default 5432, 3306, 27017 or 6379 when left empty. Health check query SELECT 1(PostgreSQL, MySQL),PING(Redis)Run on every check. A query that errors marks the monitor down. Connection timeout 10 seconds 5, 10, 20, 30 or 60 seconds. Query timeout 30 seconds 10, 30, 60 or 120 seconds. Use SSL/TLS Required (Preferred for Redis) See the table below. Expected row count At least 1 Any, At least 1, Exactly 1 or None (empty result). PostgreSQL and MySQL only. - 4Create it
Click Create monitor. The first check is due straight away.
SSL/TLS options
The setting means the same for all four engines:
| Option | What the check does |
|---|---|
| Required | Encrypted; the certificate is not verified. A server that doesn't speak TLS fails the check. |
| Preferred | Tries an encrypted connection first. If the server doesn't support TLS, it connects again without it and the check carries on. A wrong password or a refused connection is not retried. |
| Verify certificate | Encrypted, and the certificate must chain to a trusted authority and match the host name. Otherwise the check fails. |
| Disabled | No TLS — except PostgreSQL and MySQL hosts on rds.amazonaws.com or containing .db., which still connect encrypted without verification. |
- Redis: a
rediss://connection string always connects over TLS, whatever the dropdown says. Withredis://or Enter details instead, the dropdown decides. A Redis server without TLS needs Preferred or Disabled; with Required the check fails and its message says so. New Redis monitors start on Preferred, and Redis monitors saved earlier with the old Required default were moved to Preferred when Redis began honouring this setting. A user name in the connection string (redis://monitor:secret@host) logs in as that ACL user. - MongoDB: with Disabled, the connection string decides —
mongodb+srv://URIs connect over TLS, as MongoDB always does for them. When Preferred falls back, half the connection timeout is spent on the encrypted attempt.
Queries for Redis and MongoDB
- Redis: a command as you'd type it in
redis-cli, for exampleINFO replication. Without one, the check is aPING. - MongoDB: a command document, written as JSON or as
db.runCommand({ ... })/db.adminCommand({ ... }), for exampledb.adminCommand({ "ping": 1 }).
A public MongoDB check connects with the connection string as you entered it. With Enter details instead, it builds one from the fields: Username and Password are sent and checked against Auth database, and Database name is the database the check reads.
A public database monitor must point at an address on the internet. Zharp refuses loopback (localhost, 127.x.x.x, ::1), link-local (169.254.x.x, fe80::) and private ranges (10.x, 172.16–31.x, 192.168.x, 100.64–127.x, fc00::/7) — when you save, and again on every check, after resolving the host name. Use a private monitor for a database on a private network. See Private Networks.
Private: through the Zharp agent
A private monitor reads what the Zharp agent reports. The agent connects to the database locally and sends its numbers to Zharp over HTTPS, so the database never has to accept a connection from outside, and its password never leaves the server.
- 1Install the agent on a server that can reach the database
Usually the database's own server. At install the agent looks for PostgreSQL, MySQL, Redis and MongoDB. Redis without a password is collected straight away; the others are listed on the host under Integrations → Zharp Agent as Needs setup.
- 2Give the agent a monitoring user
Open the host and click Set up next to the database. It shows the commands below with a password already filled in — see the monitoring user each engine needs. The database moves to Collecting within a minute.
- 3Create the monitor
Click New, choose Database monitor, set Connection to Private, and pick the database in Agent connection. Each one is listed by engine and server — for example PostgreSQL on db-01 — with its address added when that isn't
localhost. The engine comes from the database you pick.A database only appears here once the agent has reported on it. If the list says No connections available, finish the setup on the server first.
- A private monitor has no Connection settings section (port, query, timeouts, SSL, row count): the agent decides how it connects, so the form hides them.
- The agent can watch a database on another machine it can reach:
--hostand--portfor PostgreSQL and MySQL,--endpoint host:portfor Redis and MongoDB.
# a database on another machine the agent can reach sudo zharp-collector add postgres --host 10.0.0.12 --port 5432 --password 'choose-a-password' --db app sudo zharp-collector add mongo --endpoint 10.0.0.20:27017 --password 'choose-a-password'
Several databases of one engine
One agent can report on any number of PostgreSQL, MySQL, Redis or MongoDB servers. The first of an engine is added as above. Each further one needs --name, made of letters, digits, - or _:
# the first PostgreSQL on this agent needs no name; every further one gets its own sudo zharp-collector add postgres --name orders --host 10.0.0.12 --password 'choose-a-password' --db orders sudo zharp-collector add postgres --name billing --host 10.0.0.13 --password 'another-password' --db billing
- Each named database is listed separately — on the host as PostgreSQL (orders), and in Agent connection as PostgreSQL "orders" on db-01 — and gets monitors of its own.
- Running
addagain without--namekeeps the first database's settings and only updates its password; the command reminds you to use--namefor another database. Running it again with a name that exists does the same for that database. - Agents set up before names existed keep reporting their one database per engine, unchanged.
The monitoring user each engine needs
These are the commands the dashboard gives you under Set up. The dashboard fills in a random password made in your browser; Zharp doesn't store it. On Windows, run the zharp-collector line in an elevated PowerShell without sudo.
PostgreSQL
-- as a superuser in psql CREATE USER zharp_monitor WITH PASSWORD 'choose-a-password'; GRANT pg_monitor TO zharp_monitor;
sudo zharp-collector add postgres --password 'choose-a-password'
MySQL
-- as root in mysql CREATE USER 'zharp_monitor'@'localhost' IDENTIFIED BY 'choose-a-password'; GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'zharp_monitor'@'localhost'; FLUSH PRIVILEGES;
sudo zharp-collector add mysql --password 'choose-a-password'
MongoDB
// as an admin in mongosh
use admin
db.createUser({ user: "zharp_monitor", pwd: "choose-a-password", roles: [{ role: "clusterMonitor", db: "admin" }] })sudo zharp-collector add mongo --password 'choose-a-password'
Redis
# only when Redis has a password (requirepass); without one the agent collects it by itself sudo zharp-collector add redis --password '<redis password>'
What a private monitor checks
The agent reports every 30 seconds. On each check, the monitor reads the latest report and compares it with fixed limits — they can't be changed from the dashboard today.
| Engine | Goes down when | Message |
|---|---|---|
| PostgreSQL | Connections in use pass 90% of max_connections | High connection usage: 93.5% |
| MySQL | Connected threads pass 90% of max_connections | High connection usage: 91.2% |
| MySQL | MySQL refused a connection because max_connections was reached, within the last check frequency plus 30 seconds | MySQL refused 3 connections: max_connections (151) reached |
| Redis | Memory used passes 90% of maxmemory (only when maxmemory is set) | High memory usage: 92.4% |
| Redis | More than 1,000 connected clients | High connection count: 1042 |
| MongoDB | More than 1,000 current connections | High connection count: 1200 |
| MongoDB | More than 5,000 operations per second | High operations/sec: 6150.4 |
When a private monitor goes down
Before any limit is compared, the monitor checks that the report is there and recent:
| Situation | Status and message |
|---|---|
| Just created, no report yet | Pending — Waiting for the agent's first report on PostgreSQL. No incident is opened. This lasts up to three times (check frequency + 30 seconds) from creation. |
| Still no report after that | Down — The agent hasn't reported on PostgreSQL — check it's set up on the server |
| The agent can't connect to the database | Down — The agent can't connect to PostgreSQL on localhost:5432 |
| The database stopped reporting, the agent didn't | Down — PostgreSQL on db-01 stopped reporting 95s ago while the agent is still running — PostgreSQL may be down |
| The agent itself stopped reporting | Down — The agent on db-01 hasn't reported for 240s — the server or the agent may be down |
A report counts as recent for the monitor's Check frequency plus 30 seconds. With the default of 3 minutes, a database that goes quiet is reported down within about three and a half minutes of its last report.
Because the agent only connects out, a private monitor also catches the server itself going away: when the agent stops reporting, the monitor goes down with the “agent hasn't reported” message.