How to Monitor Your TiDB Distributed Database with Vigilmon
TiDB is an open-source distributed SQL database compatible with MySQL. It's designed for horizontal scaling, high availability, and HTAP (Hybrid Transactional and Analytical Processing) workloads. Teams migrating from MySQL to TiDB get the familiar SQL interface with distributed database power — but monitoring a distributed database has unique challenges.
TiDB Health Check Endpoints
TiDB Server exposes health endpoints:
curl http://localhost:10080/status
# {"connections":0,"version":"8.x.x","git_hash":"..."}
curl http://localhost:10080/health
# 200 OK when healthy
Application Health Route
Node.js with mysql2:
const mysql = require("mysql2/promise");
const pool = mysql.createPool({
host: process.env.TIDB_HOST,
port: 4000,
user: process.env.TIDB_USER,
password: process.env.TIDB_PASSWORD,
database: process.env.TIDB_DATABASE,
ssl: { rejectUnauthorized: true },
connectionLimit: 10,
});
app.get("/health", async (req, res) => {
let connection;
try {
connection = await pool.getConnection();
await connection.execute("SELECT 1");
res.json({ status: "ok", database: "tidb" });
} catch (error) {
res.status(503).json({ status: "error", message: error.message });
} finally {
if (connection) connection.release();
}
});
Python:
import pymysql
from fastapi.responses import JSONResponse
def get_tidb_connection():
return pymysql.connect(
host=settings.TIDB_HOST,
port=4000,
user=settings.TIDB_USER,
password=settings.TIDB_PASSWORD,
database=settings.TIDB_DATABASE,
ssl={"ssl_verify_cert": True},
)
@app.get("/health")
async def health_check():
try:
conn = get_tidb_connection()
with conn.cursor() as cursor:
cursor.execute("SELECT 1")
conn.close()
return {"status": "ok", "database": "tidb"}
except Exception as e:
return JSONResponse(status_code=503, content={"status": "error", "message": str(e)})
Add to Vigilmon
- Log in at vigilmon.online
- Click + Add Monitor
- URL:
https://your-app.com/health - Check interval: 1 minute
- Expected status: 200
For direct TiDB server monitoring (if accessible):
- URL:
http://tidb.your-cluster.com:10080/health
TiDB Serverless (TiDB Cloud)
const connection = await mysql.createConnection({
host: "gateway01.ap-southeast-1.prod.aws.tidbcloud.com",
port: 4000,
user: "your-user.root",
password: process.env.TIDB_CLOUD_PASSWORD,
database: "mydb",
ssl: { minVersion: "TLSv1.2" },
});
app.get("/health", async (req, res) => {
try {
await connection.execute("SELECT 1");
res.json({ status: "ok", database: "tidb-serverless" });
} catch (err) {
res.status(503).json({ status: "error", message: err.message });
}
});
Docker Compose for Local Development
version: "3.8"
services:
tidb:
image: pingcap/tidb:latest
ports:
- "4000:4000" # MySQL protocol
- "10080:10080" # Status port
command:
- --store=mocktikv
- --log-level=warn
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:10080/health"]
interval: 30s
timeout: 10s
retries: 5
Key Monitoring Points
| Component | Check | How |
|---|---|---|
| TiDB Server | Reachable + accepting SQL |
/health endpoint |
| Application layer | App to TiDB connection | App /health route |
| TiDB Cloud | API availability | App health check |
Alert Configuration
- Immediate alert on first failure (distributed DB failures cascade)
- Multi-region checks from Vigilmon's global nodes
- Recovery alert to confirm cluster is back
TiDB brings distributed database power to the MySQL ecosystem. Pair it with Vigilmon external monitoring to ensure your SQL layer is always reachable.
Vigilmon — free uptime monitoring for TiDB, MySQL, and any database-backed application.
Top comments (0)