DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor Your TiDB Distributed Database with Vigilmon

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
Enter fullscreen mode Exit fullscreen mode

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();
  }
});
Enter fullscreen mode Exit fullscreen mode

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)})
Enter fullscreen mode Exit fullscreen mode

Add to Vigilmon

  1. Log in at vigilmon.online
  2. Click + Add Monitor
  3. URL: https://your-app.com/health
  4. Check interval: 1 minute
  5. 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 });
  }
});
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)