agentleFS
vicleung01vicleung01/openocta-db-ops-skills/mysql-batch-health-check/SKILL.md

mysql-batch-health-check

Skill9 starsChanged 6 months agoApache-2.0View on GitHub

Batch health inspection for multiple MySQL/TiDB instances. Checks connections, disk usage, replication status, slow query trends, and memory for all instances. Outputs a prioritized anomaly report with TOP N issues and actionable recommendations. Reduces full inspection from half a day to 10 minutes.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check 6 health dimensions per instance: connections, disk, replication, slow queries, QPS, memory

    line 21
  2. Distinctive:

    After infrastructure changes (network, storage, config)

    line 31
  3. Distinctive:

    Run on one instance at a time.

    line 51
  4. Distinctive:

    When user asks for details on a specific anomalous instance:

    line 242

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

MySQL Batch Health Check (Multi-Instance Inspection)

Overview

DBAs managing large fleets (50-600+ instances) face an impossible task: manual health checks take hours and cover only a handful of critical instances, while problems fester on the unchecked ones. This skill performs systematic batch inspection across all instances — connections, disk, replication, slow queries, memory — and outputs a prioritized report sorted by urgency.

Real-world result: 600+ instances inspected in 10 minutes (vs. half a day manually) — 30x improvement. Critical issues are surfaced immediately with actionable recommendations.

Key capabilities:

  • Check 6 health dimensions per instance: connections, disk, replication, slow queries, QPS, memory
  • Score each instance on a health index (0-100)
  • Sort by severity: critical → warning → healthy
  • Output TOP N anomalous instances with root cause hints
  • Track trends (compare with previous check if data available)

When to Use

Apply this skill when:

  • Morning health check / daily standup preparation
  • After infrastructure changes (network, storage, config)
  • Pre-holiday or pre-event capacity check
  • User asks "how are my databases doing?"
  • Periodic compliance inspection
  • Onboarding new instances into fleet

Required MCP Server

This skill requires access to multiple database instances. Two deployment patterns:

Pattern A: Centralized CMDB + Proxy

A CMDB service provides the instance list, and each instance is accessible via a query proxy:

ToolPurpose
db_queryRun health check SQL on each instance
db_get_statusGet status variables per instance
db_get_variableGet configuration per instance

Pattern B: Single Instance Check

Run on one instance at a time. User specifies which instance to check:

User: "Check health of db-prod-01, db-prod-02, db-prod-03"
→ AI runs checks on each, aggregates results

Required MySQL Privileges (per instance)

  • SELECT on information_schema.*, performance_schema.*
  • PROCESS — View all connections
  • REPLICATION CLIENT — Check replication status

Health Check Dimensions

Dimension 1: Connection Health

-- Current and max connections
SHOW GLOBAL STATUS LIKE 'Threads_connected';
SHOW GLOBAL STATUS LIKE 'Max_used_connections';
SHOW GLOBAL STATUS LIKE 'Threads_running';
SHOW VARIABLES LIKE 'max_connections';

-- Connection usage rate
-- healthy: < 70%, warning: 70-85%, critical: > 85%

Dimension 2: Disk / Storage Health

-- Table sizes (top 10 by total size)
SELECT
  TABLE_SCHEMA AS db_name,
  ROUND(SUM(DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024 / 1024, 2) AS total_gb,
  ROUND(SUM(DATA_LENGTH) / 1024 / 1024 / 1024, 2) AS data_gb,
  ROUND(SUM(INDEX_LENGTH) / 1024 / 1024 / 1024, 2) AS index_gb
FROM information_schema.TABLES
WHERE TABLE_SCHEMA NOT IN ('mysql', 'information_schema', 'performance_schema', 'sys')
GROUP BY TABLE_SCHEMA
ORDER BY total_gb DESC
LIMIT 10;

-- Disk usage can also be obtained from monitoring system
-- if available via db_query or external API

Dimension 3: Replication Health

-- Run on each replica
SHOW SLAVE STATUS\G

-- Key metrics:
--   Seconds_Behind_Master: {lag}
--   Slave_IO_Running: Yes/No
--   Slave_SQL_Running: Yes/No
--   Last_Error: {error}

Dimension 4: Slow Query Trends

-- Slow query count and trend
SHOW GLOBAL STATUS LIKE 'Slow_queries';
SHOW VARIABLES LIKE 'long_query_time';

-- Recent slow queries count (last hour, if performance_schema available)
SELECT COUNT(*) AS slow_count_last_hour
FROM performance_schema.events_statements_summary_by_digest
WHERE SUM_TIMER_WAIT / COUNT_STAR > {long_query_time} * 1000000000000;

Dimension 5: Query Throughput (QPS)

-- Queries per second
SHOW GLOBAL STATUS LIKE 'Questions';
SHOW GLOBAL STATUS LIKE 'Uptime';

-- QPS = Questions / Uptime
-- Compare with baseline (previous check) for trend

Dimension 6: Memory / Buffer Pool

-- InnoDB buffer pool usage
SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_pages_total';
SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_pages_free';
SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_read_requests';
SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_reads';

-- Buffer pool hit rate
-- hit_rate = read_requests / (read_requests + reads) × 100%
-- healthy: > 99%, warning: 95-99%, critical: < 95%

Scoring System

Each dimension contributes to an overall health score (0-100):

DimensionWeightScoring
Connections20%100 - (usage% × 0.5)
Disk25%100 - (usage% × 0.8)
Replication20%0 if lag > 600, 100 if 0, linear otherwise
Slow Queries15%100 - (growth% × 0.3), capped at 0
QPS10%Based on deviation from baseline
Buffer Pool10%hit_rate%

Overall Health Score = Σ(dimension_score × weight)

ScoreStatusAction
90-100✅ HealthyNo action
70-89🟡 AttentionReview TOP issues
50-69🔴 WarningImmediate investigation
< 50🔴 CriticalEmergency intervention

Diagnostic Workflow

Step 1: Collect Instance List

If multi-instance:

-- From CMDB or instance registry
-- Or user provides the list

Step 2: Run Health Checks

For each instance, collect all 6 dimensions. Execute in parallel where possible.

Step 3: Score and Sort

Calculate health score per instance, sort ascending (worst first).

Step 4: Output Report

Present TOP N anomalous instances with details and recommendations.

Output Templates

Batch Report

🏥 MySQL Fleet Health Report
════════════════════════════
📋 Summary
  Total Instances: {total}
  ✅ Healthy: {count} ({pct}%)
  🟡 Attention: {count} ({pct}%)
  🔴 Warning: {count} ({pct}%)
  🔴 Critical: {count} ({pct}%)
  Scan Duration: {duration}

🔴 TOP {N} Anomalous Instances (sorted by urgency)
──────────────────────────────────────────────────

  1. {instance_id} · Health Score: {score}/100 🔴
  ┌────────────────────────────────────────────────┐
  │ Disk:     {usage}% 🔴 (daily growth {rate},     │
  │           estimated {days} days to full)         │
  │ Connections: {current}/{max} ({pct}%) 🟡         │
  │ Replication: {lag}s behind 🟡                    │
  │ Slow Queries: {count} (+{growth}% vs yesterday)  │
  │ Buffer Pool: {hit_rate}% hit rate                 │
  │                                                │
  │ ⚡ Priority Actions:                            │
  │ 1. [Immediate] Clear audit_log (>{size}GB)     │
  │ 2. [This Week] Adjust binlog retention 14d→7d  │
  │ 3. [Plan] Request disk expansion to 500GB      │
  └────────────────────────────────────────────────┘

  2. {instance_id} · Health Score: {score}/100 🟡
     Connections: 287/300 (95.7%) 🔴
     → Check connection pool leak in application
  ...

📊 Fleet Overview
  | # | Instance | Score | Disk% | Conn% | Repl Lag | Slow Q | Status |
  |---|----------|-------|-------|-------|----------|--------|--------|
  | 1 | {id}     | 42    | 92%🔴 | 78%   | 0s       | +340%  | 🔴     |
  | 2 | {id}     | 68    | 71%   | 96%🔴 | 0s       | normal | 🟡     |
  | 3 | {id}     | 73    | 65%   | 82%🟡 | 234s🟡   | normal | 🟡     |
  | ... (remaining healthy instances omitted) ...

Single Instance Detail

When user asks for details on a specific anomalous instance:

🔍 Instance Detail: {instance_id}
════════════════════════════════════

💾 Disk Analysis
  Total: {total}GB | Used: {used}GB ({pct}%)
  Daily Growth: {rate}GB/day (↑12% vs last week)
  Estimated Full: {date} ({days} days)

  TOP 5 Space Consumers:
  | Database | Data (GB) | Index (GB) | Total (GB) |
  |----------|-----------|------------|------------|
  | audit_log_db | 120.5  | 2.1        | 122.6      |
  | trade_db     | 85.3   | 12.7       | 98.0       |
  | ...

🔗 Connection Analysis
  Current: 287/300 (95.7%) 🔴
  Peak Today: 298 (99.3%)
  TOP 5 Users:
  | User | Connections | Host Pattern |
  |------|------------|-------------|
  | app_user | 245 | 10.0.1.% |
  | ... |

  ⚠️ Connection pool near exhaustion. Likely cause:
     application connection leak. Recommend restarting
     affected app pods and checking pool config.

📋 Recommendations
  1. [Immediate] Clear audit_log data > 90 days → free ~54GB
  2. [Today] Check app_user connection leak on 10.0.1.x
  3. [This Week] Binlog retention 14d → 7d → free ~12GB
  4. [Plan] Disk expansion to 500GB

Example Usage

User: "Check all instances health"

AI:

🏥 Fleet Health Report (600+ instances, 10 min scan)

✅ Healthy: ~550 instances
🟡 Attention: ~45 instances
🔴 Critical: 5 instances — investigating TOP 5 now

🔴 TOP 5 Anomalous:
  1. inst-21 · Disk 92.3% (4 days to full)
     → Action: Clear audit_log, free 54GB
  2. inst-35 · Connections 287/300 (pool near exhaustion)
     → Action: Check app connection leak
  3. inst-48 · Replication lag 234s (growing)
     → Action: Check master long queries
  4. inst-12 · Slow queries +340% vs yesterday
     → Action: Diagnose slow queries
  5. inst-67 · Memory 89% (near OOM)
     → Action: Check buffer pool, large queries

Recommend: Handle #1 (disk) and #3 (replication) first.

User: "Give me details on #1"

AI: (shows Single Instance Detail report with disk breakdown)

Best Practices

Fleet Health Check Schedule

FrequencyScopePurpose
Every 30 minConnection + replication on critical instancesEarly warning
DailyFull 6-dimension check on all instancesMorning standup
WeeklyTrend analysis + capacity forecastPlanning
MonthlySchema review + index auditMaintenance

Alert Thresholds (Recommended)

MetricWarningCritical
Disk usage80%90%
Connection usage80%90%
Replication lag60s300s
Slow query growth+50%+200%
Buffer pool hit rate< 99%< 95%
QPS deviation±30%±50%

Quick Reference

CheckQuery
ConnectionsSHOW STATUS LIKE 'Threads_connected' + SHOW VARIABLES LIKE 'max_connections'
DiskSELECT ... FROM information_schema.TABLES GROUP BY TABLE_SCHEMA
ReplicationSHOW SLAVE STATUS
Slow queriesSHOW STATUS LIKE 'Slow_queries'
QPSSHOW STATUS LIKE 'Questions' / SHOW STATUS LIKE 'Uptime'
Buffer poolSHOW STATUS LIKE 'Innodb_buffer_pool%'
Health scoreCalculated from above dimensions

Use this skill for systematic multi-instance health inspection — catch problems before they become incidents.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.