Workstation Logo
ਉਤਪਾਦ
AI ਲੈਬਜ਼OpenAI ਏਜੰਟClaude ਏਜੰਟGrok BotWorkstation CRM (WSL CRM)ਮਾਰਕੀਟਿੰਗਸਾਰੇ ਉਤਪਾਦ
AI ਹੱਲ
AI ਵਰਕਸਟੇਸ਼ਨAI SME Packagesਪ੍ਰਾਈਵੇਟ AIGPU ਕਲੱਸਟਰਐਜ AIਐਂਟਰਪ੍ਰਾਈਜ਼ AI ਲੈਬਉਦਯੋਗ ਅਨੁਸਾਰ AI
ਸੇਵਾਵਾਂ
Platform ModernisationDigital EngineeringData Foundations & AIAutonomous OperationsAI ਸਲਾਹDevOps ਆਟੋਮੇਸ਼ਨਸਾਈਬਰ ਸੁਰੱਖਿਆਸਾਫਟਵੇਅਰ ਵਿਕਾਸਏਜੰਟ ਨਿਰਮਾਣMLOps ਸੈੱਟਅੱਪ
ਸਾਡੇ ਬਾਰੇ
ਸਾਂਝੇਦਾਰਗਾਹਕ ਕਹਾਣੀਆਂ
ਲੇਖ
ਦਸਤਾਵੇਜ਼
WSL ProxyRing Promoter
ਬਲੌਗ
ਸਾਡੇ ਨਾਲ ਸੰਪਰਕ ਕਰੋLogin
Workstation

AI workstations, AI Multi Agentic Software, GPU infrastructure, and intelligent agent solutions for modern businesses.

ਯੂਕੇ ਦਫ਼ਤਰ: 77-79 Marlowes, Hemel Hempstead HP1 1LF - Directions - Take Junction 20 off M25 Outer London
Company No: 11641870
Mon - Fri: 9:00 AM - 6:00 PM GMT
+44 7515 356 146

ਬੈਲਜੀਅਮ ਦਫ਼ਤਰ: Workstation SRL, Rue Vanderkindere 34, 1180 Uccle, Brussels
BE 0751.518.683
Mon - Fri: 9:00 AM - 6:00 PM CET
+32 492 45 67 46

ਭਾਰਤ ਦਫ਼ਤਰ: #159 Sector 9, Pocket 1, DDA Flats, 110077 Dwarka, New Delhi
+91 98881 98841

ਉਤਪਾਦ

ਸਾਰੇ ਉਤਪਾਦWSL ProxyRing PromoterAI ਲੈਬਜ਼OpenAI ਏਜੰਟClaude ਏਜੰਟGrok BotWorkstation CRM (WSL CRM)

AI ਹੱਲ

AI ਹੱਲAI ਵਰਕਸਟੇਸ਼ਨਪ੍ਰਾਈਵੇਟ AIGPU ਕਲੱਸਟਰਐਂਟਰਪ੍ਰਾਈਜ਼ AI ਲੈਬਸੇਵਾਵਾਂ

ਸਰੋਤ

ਲੇਖਦਸਤਾਵੇਜ਼ਬਲੌਗSearchਸਾਈਟ ਮੈਪ

ਕੰਪਨੀ

ਸਾਡੇ ਬਾਰੇਸਾਂਝੇਦਾਰਸਾਡੇ ਨਾਲ ਸੰਪਰਕ ਕਰੋ

© 2026 Workstation AI. ਸਾਰੇ ਹੱਕ ਰਾਖਵੇਂ ਹਨ

ਗੋਪਨੀਯਤਾ ਨੀਤੀਕੂਕੀ ਨੀਤੀਸਾਈਟ ਮੈਪ

Loading blog...

Home / Blog
AIDatabaseDevOpsBackend

AI-ਪਾਵਰਡ ਡਾਟਾਬੇਸ ਟ੍ਰਬਲਸ਼ੂਟਿੰਗ: ਇੰਟੈਲੀਜੈਂਟ ਮਾਨੀਟਰਿੰਗ, ਅਨੋਮਾਲੀ ਡਿਟੈਕਸ਼ਨ, ਅਤੇ ਆਟੋ-ਰੀਮੀਡੀਏਸ਼ਨ

AI-ਪਾਵਰਡ ਡਾਟਾਬੇਸ ਨਿਗਰਾਨੀ, ਵਿਗਾੜ ਖੋਜ, ਅਤੇ ਆਟੋ-ਰੀਮੀਡੀਏਸ਼ਨ

Balinder Walia12 ਅਪ੍ਰੈਲ 202635 min read

ਆਧੁਨਿਕ ਉਤਪਾਦਨ ਡੇਟਾਬੇਸ ਲੱਖਾਂ ਮੀਟ੍ਰਿਕਸ ਪ੍ਰਤੀ ਮਿੰਟ ਪੈਦਾ ਕਰਦੇ ਹਨ — ਪੁੱਛਗਿੱਛ ਲੇਟੈਂਸੀ, ਲੌਕ ਕੰਟੈਂਸ਼ਨ, ਰਿਪਲੀਕੇਸ਼ਨ ਲੈਗ, ਬਫਰ ਪੂਲ ਹਿੱਟ ਰੇਸ਼ੋ, ਅਤੇ ਕਨੈਕਸ਼ਨ ਪੂਲ ਥਕਾਵਟ। ਪਰੰਪਰਾਗਤ ਥ੍ਰੈਸ਼ਹੋਲਡ-ਅਧਾਰਿਤ ਚੇਤਾਵਨੀ ਟੀਮਾਂ ਨੂੰ ਝੂਠੇ ਸਕਾਰਾਤਮਕ ਵਿੱਚ ਡੁੱਬਦੀ ਹੈ ਜਦੋਂ ਕਿ ਵਿਨਾਸ਼ਕਾਰੀ ਅਸਫਲਤਾਵਾਂ ਤੋਂ ਪਹਿਲਾਂ ਸੂਖਮ ਗਿਰਾਵਟ ਦੇ ਪੈਟਰਨ ਗੁੰਮ ਹੁੰਦੇ ਹਨ। AI ਅਤੇ ਮਸ਼ੀਨ ਲਰਨਿੰਗ ਬੁਨਿਆਦੀ ਤੌਰ 'ਤੇ ਇਸ ਸਮੀਕਰਨ ਨੂੰ ਆਮ ਵਿਵਹਾਰ ਨੂੰ ਸਿੱਖ ਕੇ, ਵਿਗਾੜਾਂ ਦਾ ਪਤਾ ਲਗਾ ਕੇ, ਉਹਨਾਂ ਦੇ ਕੈਸਕੇਡ ਤੋਂ ਪਹਿਲਾਂ, ਸਵਾਲਾਂ ਨੂੰ ਆਪਣੇ ਆਪ ਅਨੁਕੂਲ ਬਣਾ ਕੇ, ਅਤੇ ਮਨੁੱਖੀ ਦਖਲ ਤੋਂ ਬਿਨਾਂ ਉਪਚਾਰ ਨੂੰ ਲਾਗੂ ਕਰਕੇ ਇਸ ਸਮੀਕਰਨ ਨੂੰ ਬਦਲਦੇ ਹਨ। ਇਹ ਗਾਈਡ MySQL, PostgreSQL, MongoDB, Redis, ਅਤੇ Couchbase ਵਿੱਚ AI-ਸੰਚਾਲਿਤ ਡਾਟਾਬੇਸ ਸਮੱਸਿਆ ਨਿਪਟਾਰਾ ਦੇ ਪੂਰੇ ਸਪੈਕਟ੍ਰਮ ਨੂੰ ਕਵਰ ਕਰਦੀ ਹੈ।

ਏਆਈ ਡੇਟਾਬੇਸ ਨਿਗਰਾਨੀ ਪਾਈਪਲਾਈਨ

ਖਾਸ ਤਕਨੀਕਾਂ ਵਿੱਚ ਗੋਤਾਖੋਰੀ ਕਰਨ ਤੋਂ ਪਹਿਲਾਂ, ਇੱਕ AI-ਸੰਚਾਲਿਤ ਡੇਟਾਬੇਸ ਨਿਗਰਾਨੀ ਪ੍ਰਣਾਲੀ ਦੇ ਸਿਰੇ ਤੋਂ ਅੰਤ ਤੱਕ ਆਰਕੀਟੈਕਚਰ ਨੂੰ ਸਮਝਣਾ ਮਹੱਤਵਪੂਰਨ ਹੈ। ਪਾਈਪਲਾਈਨ ਹਰੇਕ ਡੇਟਾਬੇਸ ਇੰਜਣ ਤੋਂ ਕੱਚੇ ਮੈਟ੍ਰਿਕਸ ਨੂੰ ਇਕੱਠਾ ਕਰਦੀ ਹੈ, ਉਹਨਾਂ ਨੂੰ ਇੱਕ ਸਮਾਂ-ਸੀਰੀਜ਼ ਡੇਟਾਬੇਸ ਵਿੱਚ ਸਟੋਰ ਕਰਦੀ ਹੈ, ਉਹਨਾਂ ਨੂੰ ਵਿਗਾੜ ਖੋਜ ਲਈ ML ਮਾਡਲਾਂ ਦੁਆਰਾ ਫੀਡ ਕਰਦੀ ਹੈ, ਇੱਕ ਸੂਝਵਾਨ ਚੇਤਾਵਨੀ ਮੈਨੇਜਰ ਦੁਆਰਾ ਚੇਤਾਵਨੀਆਂ ਨੂੰ ਰੂਟ ਕਰਦੀ ਹੈ, ਅਤੇ ਜਦੋਂ ਭਰੋਸੇ ਦੇ ਥ੍ਰੈਸ਼ਹੋਲਡ ਨੂੰ ਪੂਰਾ ਕੀਤਾ ਜਾਂਦਾ ਹੈ ਤਾਂ ਸਵੈ-ਉਪਚਾਰ ਕਾਰਵਾਈਆਂ ਨੂੰ ਚਾਲੂ ਕਰਦਾ ਹੈ।

AI ਡਾਟਾਬੇਸ ਨਿਗਰਾਨੀ ਪਾਈਪਲਾਈਨਡਾਟਾਬੇਸ ਮੈਟ੍ਰਿਕਸMySQL / PGਮੋਂਗੋ / ਰੇਡਿਸਕਾਉਚਬੇਸਨਿਰਯਾਤਕਟਾਈਮ-ਸੀਰੀਜ਼ ਡੀ.ਬੀਪ੍ਰੋਮੀਥੀਅਸ /ਵਿਕਟੋਰੀਆ ਮੈਟ੍ਰਿਕਸ15-ਦਿਨ ਦੀ ਧਾਰਨਾML ਮਾਡਲਅਨੌਮਲੀ ਡਿਟੈਕਸ਼ਨਨਬੀ / LSTMਆਈਸੋਲੇਸ਼ਨ ਜੰਗਲਵਿਸ਼ਵਾਸ ਸਕੋਰਚੇਤਾਵਨੀ ਪ੍ਰਬੰਧਕਡੀਡਅੱਪ ਅਤੇ ਸਬੰਧਤਰਜੀਹੀ ਸਕੋਰਿੰਗਟੀਮਾਂ ਲਈ ਰੂਟਪੇਜਰਡਿਊਟੀ/ਓ.ਜੀਆਟੋ-ਰੀਮੀਡੀਏਸ਼ਨਸਵਾਲਾਂ ਨੂੰ ਮਾਰੋਸਕੇਲ ਸਰੋਤਫੇਲਓਵਰਸੇਵਾਵਾਂ ਨੂੰ ਮੁੜ ਚਾਲੂ ਕਰੋਫੀਡਬੈਕ ਲੂਪ → ਰੀਟ੍ਰੇਨ ਮਾਡਲਪ੍ਰਤੀ ਡਾਟਾਬੇਸ ਇੰਜਣ ਇਕੱਤਰ ਕੀਤੇ ਮੈਟ੍ਰਿਕਸMySQLਹੌਲੀ ਪੁੱਛਗਿੱਛInnoDB ਬਫਰ ਪੂਲਡੈੱਡਲਾਕ / ਲਾਕਰੀਪਲੀਕੇਸ਼ਨ ਲੈਗPostgreSQLਵੈਕਿਊਮ / ਬਲੋਟਸੂਚਕਾਂਕ ਦੀ ਵਰਤੋਂWAL ਪੀੜ੍ਹੀਕੁਨੈਕਸ਼ਨ ਪੂਲਮੋਂਗੋਡੀਬੀਪੁੱਛਗਿੱਛ ਪ੍ਰੋਫਾਈਲਰਸੂਚਕਾਂਕ ਸੁਝਾਅਤਿੱਖਾ ਸੰਤੁਲਨਵਾਇਰਡਟਾਈਗਰ ਕੈਸ਼Redisਮੈਮੋਰੀ ਫਰੈਗਮੈਂਟੇਸ਼ਨਮੁੱਖ ਪੈਟਰਨਹੌਟਸਪੌਟ ਖੋਜਬੇਦਖਲੀ ਦੀ ਦਰਕਾਉਚਬੇਸN1QL ਪ੍ਰਦਰਸ਼ਨਸੂਚਕਾਂਕ ਸਲਾਹਕਾਰਮੁੜ-ਸੰਤੁਲਨ ਓਪਸXDCR ਲੇਟੈਂਸੀਡਾਟਾ ਪ੍ਰਵਾਹ ਸੰਖੇਪਨਿਰਯਾਤਕ (mysqld_exporter, pg_exporter, mongodb_exporter, redis_exporter, couchbase_exporter)→ ਪ੍ਰੋਮੀਥੀਅਸ ਸਕ੍ਰੈਪ (15s ਅੰਤਰਾਲ) → ਵਿਕਟੋਰੀਆ ਮੈਟ੍ਰਿਕਸ (ਲੰਬੀ ਮਿਆਦ) → ਐਮਐਲ ਪਾਈਪਲਾਈਨ (ਬੈਚ + ਸਟ੍ਰੀਮਿੰਗ)→ Grafana ਡੈਸ਼ਬੋਰਡ + ਚੇਤਾਵਨੀ ਪ੍ਰਬੰਧਕ → PagerDuty / OpsGenie → ਆਟੋ-ਰੀਮੀਡੀਏਸ਼ਨ ਇੰਜਣ

ਡਾਟਾਬੇਸ ਨਿਗਰਾਨੀ ਅਤੇ ਨਿਰੀਖਣਯੋਗਤਾ ਲਈ AI/ML

ਪਰੰਪਰਾਗਤ ਡੇਟਾਬੇਸ ਨਿਗਰਾਨੀ ਸਥਿਰ ਥ੍ਰੈਸ਼ਹੋਲਡ 'ਤੇ ਨਿਰਭਰ ਕਰਦੀ ਹੈ: ਚੇਤਾਵਨੀ ਜਦੋਂ CPU 80 ਪ੍ਰਤੀਸ਼ਤ ਤੋਂ ਵੱਧ ਜਾਂਦੀ ਹੈ, ਜਦੋਂ ਪੁੱਛਗਿੱਛ ਲੇਟੈਂਸੀ 500 ਮਿਲੀਸਕਿੰਟ ਤੋਂ ਵੱਧ ਜਾਂਦੀ ਹੈ, ਜਾਂ ਜਦੋਂ ਕਨੈਕਸ਼ਨ ਦੀ ਗਿਣਤੀ 200 ਤੋਂ ਵੱਧ ਜਾਂਦੀ ਹੈ। ਇਹ ਪਹੁੰਚ ਗਤੀਸ਼ੀਲ ਉਤਪਾਦਨ ਵਾਤਾਵਰਣਾਂ ਵਿੱਚ ਵਿਨਾਸ਼ਕਾਰੀ ਤੌਰ 'ਤੇ ਅਸਫਲ ਹੋ ਜਾਂਦੀ ਹੈ ਜਿੱਥੇ ਆਮ ਤੌਰ 'ਤੇ ਦਿਨ ਦੇ ਦਿਨ, ਦਿਨ ਦੇ ਸਮੇਂ, ਸੀਜ਼ਨਲ ਪੈਟਰਨ ਅਤੇ ਦਿਨ ਦੇ ਸਮੇਂ ਦੇ ਅਨੁਸਾਰ ਬਦਲਦਾ ਹੈ। AI-ਸੰਚਾਲਿਤ ਨਿਰੀਖਣਯੋਗਤਾ ਇਹਨਾਂ ਕਠੋਰ ਥ੍ਰੈਸ਼ਹੋਲਡਾਂ ਨੂੰ ਸਿੱਖੀਆਂ ਬੇਸਲਾਈਨਾਂ ਨਾਲ ਬਦਲ ਦਿੰਦੀ ਹੈ ਜੋ ਲਗਾਤਾਰ ਅਨੁਕੂਲ ਹੁੰਦੀਆਂ ਹਨ।

ਸਹੀ ਮੈਟ੍ਰਿਕਸ ਨੂੰ ਇਕੱਠਾ ਕਰਨਾ

ਕਿਸੇ ਵੀ AI ਨਿਗਰਾਨੀ ਪ੍ਰਣਾਲੀ ਦੀ ਬੁਨਿਆਦ ਵਿਆਪਕ ਮੀਟ੍ਰਿਕ ਸੰਗ੍ਰਹਿ ਹੈ। ਹਰੇਕ ਡੇਟਾਬੇਸ ਇੰਜਣ ਵਿਲੱਖਣ ਮੈਟ੍ਰਿਕਸ ਦਾ ਪਰਦਾਫਾਸ਼ ਕਰਦਾ ਹੈ ਜੋ ਪ੍ਰਦਰਸ਼ਨ ਲਈ ਮਹੱਤਵਪੂਰਨ ਹਨ:

# prometheus_db_collector.py — Unified metric collector for multi-DB environments
import prometheus_client as prom
import mysql.connector
import psycopg2
import pymongo
import redis
from couchbase.cluster import Cluster
from couchbase.options import ClusterOptions
from couchbase.auth import PasswordAuthenticator
import time
import logging

logger = logging.getLogger(__name__)

# MySQL metrics
mysql_slow_queries = prom.Gauge('mysql_slow_queries_total', 'Total slow queries')
mysql_buffer_pool_hit = prom.Gauge('mysql_innodb_buffer_pool_hit_ratio', 'Buffer pool hit ratio')
mysql_deadlocks = prom.Counter('mysql_deadlocks_total', 'Total deadlocks detected')
mysql_repl_lag = prom.Gauge('mysql_replication_lag_seconds', 'Replication lag in seconds')
mysql_active_connections = prom.Gauge('mysql_active_connections', 'Current active connections')
mysql_threads_running = prom.Gauge('mysql_threads_running', 'Currently running threads')

# PostgreSQL metrics
pg_bloat_ratio = prom.Gauge('pg_table_bloat_ratio', 'Table bloat ratio', ['table_name'])
pg_vacuum_age = prom.Gauge('pg_vacuum_age_seconds', 'Seconds since last vacuum', ['table_name'])
pg_index_hit_ratio = prom.Gauge('pg_index_hit_ratio', 'Index hit ratio')
pg_wal_rate = prom.Gauge('pg_wal_bytes_per_second', 'WAL generation rate')
pg_active_locks = prom.Gauge('pg_active_locks', 'Number of active locks', ['lock_type'])

# MongoDB metrics
mongo_opcounters = prom.Gauge('mongo_opcounters', 'Operation counters', ['op_type'])
mongo_wiredtiger_cache = prom.Gauge('mongo_wiredtiger_cache_usage_pct', 'WiredTiger cache usage')
mongo_repl_lag = prom.Gauge('mongo_replication_lag_seconds', 'Replica set lag')

# Redis metrics
redis_memory_frag = prom.Gauge('redis_memory_fragmentation_ratio', 'Memory fragmentation ratio')
redis_evicted_keys = prom.Counter('redis_evicted_keys_total', 'Total evicted keys')
redis_keyspace_hitrate = prom.Gauge('redis_keyspace_hit_ratio', 'Keyspace hit ratio')


class UnifiedDBCollector:
    def __init__(self, config):
        self.config = config
        self.connections = {}

    def collect_mysql(self):
        conn = mysql.connector.connect(**self.config['mysql'])
        cursor = conn.cursor(dictionary=True)

        cursor.execute("SHOW GLOBAL STATUS LIKE 'Slow_queries'")
        row = cursor.fetchone()
        mysql_slow_queries.set(int(row['Value']))

        cursor.execute("""
            SELECT
                (1 - (Innodb_buffer_pool_reads / Innodb_buffer_pool_read_requests)) * 100
            AS hit_ratio FROM (
                SELECT
                    VARIABLE_VALUE AS Innodb_buffer_pool_reads
                FROM performance_schema.global_status
                WHERE VARIABLE_NAME = 'Innodb_buffer_pool_reads'
            ) a, (
                SELECT
                    VARIABLE_VALUE AS Innodb_buffer_pool_read_requests
                FROM performance_schema.global_status
                WHERE VARIABLE_NAME = 'Innodb_buffer_pool_read_requests'
            ) b
        """)
        result = cursor.fetchone()
        mysql_buffer_pool_hit.set(float(result['hit_ratio']))

        cursor.execute("SHOW GLOBAL STATUS LIKE 'Innodb_deadlocks'")
        row = cursor.fetchone()
        mysql_deadlocks.inc(int(row['Value']))

        cursor.execute("SHOW SLAVE STATUS")
        slave = cursor.fetchone()
        if slave and slave.get('Seconds_Behind_Master') is not None:
            mysql_repl_lag.set(float(slave['Seconds_Behind_Master']))

        cursor.execute("SHOW GLOBAL STATUS LIKE 'Threads_connected'")
        row = cursor.fetchone()
        mysql_active_connections.set(int(row['Value']))

        cursor.close()
        conn.close()

    def collect_postgresql(self):
        conn = psycopg2.connect(**self.config['postgresql'])
        cursor = conn.cursor()

        cursor.execute("""
            SELECT schemaname, tablename,
                   pg_total_relation_size(schemaname || '.' || tablename) as total_size,
                   pg_relation_size(schemaname || '.' || tablename) as table_size
            FROM pg_tables
            WHERE schemaname = 'public'
        """)
        for row in cursor.fetchall():
            if row[3] > 0:
                bloat = (row[2] - row[3]) / row[2]
                pg_bloat_ratio.labels(table_name=row[1]).set(bloat)

        cursor.execute("""
            SELECT relname, extract(epoch from now() - last_vacuum) as vacuum_age
            FROM pg_stat_user_tables
            WHERE last_vacuum IS NOT NULL
        """)
        for row in cursor.fetchall():
            pg_vacuum_age.labels(table_name=row[0]).set(row[1])

        cursor.execute("""
            SELECT sum(heap_blks_hit) / nullif(sum(heap_blks_hit) + sum(heap_blks_read), 0)
            FROM pg_statio_user_tables
        """)
        result = cursor.fetchone()
        if result[0]:
            pg_index_hit_ratio.set(float(result[0]))

        cursor.close()
        conn.close()

    def collect_mongodb(self):
        client = pymongo.MongoClient(self.config['mongodb']['uri'])
        status = client.admin.command('serverStatus')

        for op in ['insert', 'query', 'update', 'delete']:
            mongo_opcounters.labels(op_type=op).set(status['opcounters'][op])

        cache = status['wiredTiger']['cache']
        cache_used = cache['bytes currently in the cache']
        cache_max = cache['maximum bytes configured']
        mongo_wiredtiger_cache.set((cache_used / cache_max) * 100)

        client.close()

    def collect_redis(self):
        r = redis.Redis(**self.config['redis'])
        info = r.info()

        redis_memory_frag.set(info.get('mem_fragmentation_ratio', 0))
        redis_evicted_keys.inc(info.get('evicted_keys', 0))

        hits = info.get('keyspace_hits', 0)
        misses = info.get('keyspace_misses', 0)
        if hits + misses > 0:
            redis_keyspace_hitrate.set(hits / (hits + misses))

        r.close()

    def run(self, interval=15):
        prom.start_http_server(9100)
        logger.info('Metric collector started on :9100')
        while True:
            try:
                self.collect_mysql()
                self.collect_postgresql()
                self.collect_mongodb()
                self.collect_redis()
            except Exception as e:
                logger.error(f'Collection error: {e}')
            time.sleep(interval)

ਸਮਾਂ-ਸੀਰੀਜ਼ ਵਿਸ਼ਲੇਸ਼ਣ ਦੇ ਨਾਲ ਵਿਗਾੜ ਦਾ ਪਤਾ ਲਗਾਉਣਾ

ਡੇਟਾਬੇਸ ਮਾਨੀਟਰਿੰਗ ਵਿੱਚ AI ਦਾ ਮੁੱਖ ਮੁੱਲ ਪ੍ਰਸਤਾਵ ਵਿਗਾੜ ਦਾ ਪਤਾ ਲਗਾਉਣਾ ਹੈ - ਅਸਾਧਾਰਨ ਪੈਟਰਨਾਂ ਦੀ ਪਛਾਣ ਕਰਨਾ ਜੋ ਸਿੱਖੀਆਂ ਬੇਸਲਾਈਨਾਂ ਤੋਂ ਭਟਕਦੇ ਹਨ। ਤਿੰਨ ਪ੍ਰਾਇਮਰੀ ਐਲਗੋਰਿਦਮ ਇਸ ਸਪੇਸ 'ਤੇ ਹਾਵੀ ਹਨ: ਮੌਸਮੀ ਸੜਨ ਲਈ ਫੇਸਬੁੱਕ ਪੈਗੰਬਰ, ਗੁੰਝਲਦਾਰ ਅਸਥਾਈ ਪੈਟਰਨਾਂ ਲਈ LSTM ਨੈੱਟਵਰਕ, ਅਤੇ ਮਲਟੀਵੈਰੀਏਟ ਆਊਟਲੀਅਰ ਖੋਜ ਲਈ ਆਈਸੋਲੇਸ਼ਨ ਫੋਰੈਸਟ।

ਅਨੌਮਲੀ ਡਿਟੈਕਸ਼ਨ ਆਰਕੀਟੈਕਚਰਡਾਟਾਬੇਸ ਮੀਟ੍ਰਿਕ ਸਟ੍ਰੀਮਜ਼CPU ਵਰਤੋਂਮੈਮੋਰੀਕਨੈਕਸ਼ਨਪੁੱਛਗਿੱਛ ਲੇਟੈਂਸੀਲਾਕ ਉਡੀਕਰੀਪਲੀਕੇਸ਼ਨ ਲੈਗਡਿਸਕ I/OML ਮਾਡਲ ਲੇਅਰਨਬੀਮੌਸਮੀ ਸੜਨਰੁਝਾਨ + ਮੌਸਮੀਤਾਛੁੱਟੀਆਂ ਦੇ ਪ੍ਰਭਾਵLSTM ਨੈੱਟਵਰਕਕ੍ਰਮਵਾਰ ਪੈਟਰਨਲੰਬੀ-ਸੀਮਾ ਨਿਰਭਰਤਾਮਲਟੀਵਰੀਏਟ ਇੰਪੁੱਟਆਈਸੋਲੇਸ਼ਨ ਜੰਗਲਮਲਟੀਵਰੀਏਟ ਆਊਟਲੀਅਰਨਿਰੀਖਣ ਰਹਿਤ ਸਿੱਖਿਆਤੇਜ਼ ਸਕੋਰਿੰਗਸਧਾਰਣ ਬੇਸਲਾਈਨ ਬਨਾਮ ਖੋਜੀ ਗਈ ਵਿਗਾੜਸਧਾਰਨ ਬੇਸਲਾਈਨਅਸੰਗਤਤਾ ਦਾ ਪਤਾ ਲਗਾਇਆ ਗਿਆt=0t = 24 ਘੰਟੇt = 48 ਘੰਟੇਸਕੋਰ: 0.97ਸਿਹਤਮੰਦ (ਸਕੋਰ <0.5)ਚੇਤਾਵਨੀ (0.5 - 0.8)ਗੰਭੀਰ (ਸਕੋਰ > 0.8)

ਸਕਿਟ-ਲਰਨ ਅਤੇ ਪੈਗੰਬਰ ਦੇ ਨਾਲ ਅਸਮਾਨਤਾ ਖੋਜ ਨੂੰ ਲਾਗੂ ਕਰਨਾ

ਨਿਮਨਲਿਖਤ ਪਾਈਥਨ ਸਥਾਪਨ ਇੱਕ ਪ੍ਰੋਡਕਸ਼ਨ-ਰੈਡੀ ਅਨੋਮਾਲੀ ਡਿਟੈਕਟਰ ਪ੍ਰਦਰਸ਼ਿਤ ਕਰਦਾ ਹੈ ਜੋ ਸਮਾਂ-ਸੀਰੀਜ਼ ਪੂਰਵ-ਅਨੁਮਾਨ ਲਈ ਪੈਗੰਬਰ ਦੇ ਨਾਲ ਮਲਟੀਵੇਰੀਏਟ ਖੋਜ ਲਈ ਆਈਸੋਲੇਸ਼ਨ ਫੋਰੈਸਟ ਨੂੰ ਜੋੜਦਾ ਹੈ। ਇਹ ਦੋਹਰੀ ਪਹੁੰਚ ਅਚਾਨਕ ਸਪਾਈਕ ਅਤੇ ਹੌਲੀ-ਹੌਲੀ ਵਹਿਣ ਦੋਵਾਂ ਨੂੰ ਫੜਦੀ ਹੈ।

# anomaly_detector.py — Production anomaly detection for database metrics
import numpy as np
import pandas as pd
from sklearn.ensemble import IsolationForest
from sklearn.preprocessing import StandardScaler
from prophet import Prophet
from prometheus_api_client import PrometheusConnect
from datetime import datetime, timedelta
import warnings
import json
import logging

warnings.filterwarnings('ignore')
logger = logging.getLogger(__name__)


class DatabaseAnomalyDetector:
    def __init__(self, prometheus_url, contamination=0.05):
        self.prom = PrometheusConnect(url=prometheus_url, disable_ssl=True)
        self.scaler = StandardScaler()
        self.isolation_forest = IsolationForest(
            contamination=contamination,
            n_estimators=200,
            max_samples='auto',
            random_state=42,
            n_jobs=-1
        )
        self.prophet_models = {}
        self.baseline_stats = {}

    def fetch_metrics(self, query, hours=168):
        """Fetch metric data from Prometheus for the given time window."""
        end_time = datetime.now()
        start_time = end_time - timedelta(hours=hours)
        result = self.prom.custom_query_range(
            query=query,
            start_time=start_time,
            end_time=end_time,
            step='60s'
        )
        if not result:
            return pd.DataFrame()

        timestamps, values = [], []
        for point in result[0]['values']:
            timestamps.append(datetime.fromtimestamp(float(point[0])))
            values.append(float(point[1]))

        return pd.DataFrame({'timestamp': timestamps, 'value': values})

    def train_isolation_forest(self, metrics_dict):
        """Train Isolation Forest on multiple metric dimensions."""
        frames = []
        for name, df in metrics_dict.items():
            if not df.empty:
                series = df.set_index('timestamp')['value'].rename(name)
                frames.append(series)

        if not frames:
            raise ValueError('No metric data available for training')

        combined = pd.concat(frames, axis=1).dropna()
        scaled = self.scaler.fit_transform(combined)
        self.isolation_forest.fit(scaled)

        self.baseline_stats = {
            col: {'mean': combined[col].mean(), 'std': combined[col].std()}
            for col in combined.columns
        }
        logger.info(f'Isolation Forest trained on {len(combined)} samples, {len(frames)} features')
        return combined

    def train_prophet(self, metric_name, df):
        """Train a Prophet model for seasonal time-series forecasting."""
        if df.empty:
            return
        prophet_df = df.rename(columns={'timestamp': 'ds', 'value': 'y'})
        model = Prophet(
            changepoint_prior_scale=0.05,
            seasonality_prior_scale=10,
            holidays_prior_scale=10,
            daily_seasonality=True,
            weekly_seasonality=True,
            yearly_seasonality=False,
            interval_width=0.95
        )
        model.fit(prophet_df)
        self.prophet_models[metric_name] = model
        logger.info(f'Prophet model trained for {metric_name}')

    def detect_anomalies_multivariate(self, current_metrics):
        """Detect anomalies using Isolation Forest across multiple metrics."""
        scaled = self.scaler.transform(current_metrics)
        predictions = self.isolation_forest.predict(scaled)
        scores = self.isolation_forest.decision_function(scaled)

        anomalies = []
        for i, (pred, score) in enumerate(zip(predictions, scores)):
            if pred == -1:
                anomaly_score = max(0, min(1, 0.5 - score))
                anomalies.append({
                    'index': i,
                    'score': round(anomaly_score, 4),
                    'severity': 'critical' if anomaly_score > 0.8 else 'warning',
                    'values': current_metrics.iloc[i].to_dict()
                })
        return anomalies

    def detect_anomalies_timeseries(self, metric_name, df):
        """Detect anomalies using Prophet forecast bounds."""
        model = self.prophet_models.get(metric_name)
        if not model or df.empty:
            return []

        prophet_df = df.rename(columns={'timestamp': 'ds', 'value': 'y'})
        forecast = model.predict(prophet_df[['ds']])
        merged = prophet_df.merge(forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']], on='ds')

        anomalies = []
        for _, row in merged.iterrows():
            if row['y'] < row['yhat_lower'] or row['y'] > row['yhat_upper']:
                deviation = abs(row['y'] - row['yhat'])
                band = row['yhat_upper'] - row['yhat_lower']
                severity_score = min(1.0, deviation / band) if band > 0 else 0.5
                anomalies.append({
                    'timestamp': str(row['ds']),
                    'actual': round(row['y'], 4),
                    'predicted': round(row['yhat'], 4),
                    'lower': round(row['yhat_lower'], 4),
                    'upper': round(row['yhat_upper'], 4),
                    'score': round(severity_score, 4),
                    'severity': 'critical' if severity_score > 0.8 else 'warning'
                })
        return anomalies

    def run_full_analysis(self, db_type='mysql'):
        """Run complete anomaly detection pipeline for a database type."""
        metric_queries = {
            'mysql': {
                'cpu': 'rate(process_cpu_seconds_total{job="mysql"}[5m])',
                'connections': 'mysql_global_status_threads_connected',
                'slow_queries': 'rate(mysql_global_status_slow_queries[5m])',
                'buffer_pool_hit': 'mysql_global_status_innodb_buffer_pool_hit_ratio',
                'repl_lag': 'mysql_slave_status_seconds_behind_master'
            },
            'postgresql': {
                'cpu': 'rate(process_cpu_seconds_total{job="postgres"}[5m])',
                'connections': 'pg_stat_activity_count',
                'cache_hit': 'pg_stat_database_blks_hit / (pg_stat_database_blks_hit + pg_stat_database_blks_read)',
                'deadlocks': 'rate(pg_stat_database_deadlocks[5m])',
                'wal_rate': 'rate(pg_wal_lsn_diff[5m])'
            }
        }

        queries = metric_queries.get(db_type, metric_queries['mysql'])
        metrics = {}
        for name, query in queries.items():
            metrics[name] = self.fetch_metrics(query)

        self.train_isolation_forest(metrics)
        for name, df in metrics.items():
            self.train_prophet(name, df)

        results = {'db_type': db_type, 'anomalies': [], 'summary': {}}
        for name, df in metrics.items():
            ts_anomalies = self.detect_anomalies_timeseries(name, df)
            if ts_anomalies:
                results['anomalies'].extend([
                    {**a, 'metric': name} for a in ts_anomalies
                ])

        results['summary'] = {
            'total_anomalies': len(results['anomalies']),
            'critical': sum(1 for a in results['anomalies'] if a['severity'] == 'critical'),
            'warning': sum(1 for a in results['anomalies'] if a['severity'] == 'warning')
        }
        return results


if __name__ == '__main__':
    detector = DatabaseAnomalyDetector('http://prometheus:9090')
    results = detector.run_full_analysis('mysql')
    print(json.dumps(results, indent=2))

ਭਵਿੱਖਬਾਣੀ ਚੇਤਾਵਨੀ ਬਨਾਮ ਥ੍ਰੈਸ਼ਹੋਲਡ-ਅਧਾਰਿਤ ਚੇਤਾਵਨੀ

ਰਵਾਇਤੀ ਥ੍ਰੈਸ਼ਹੋਲਡ-ਅਧਾਰਿਤ ਚੇਤਾਵਨੀ ਦੋ ਵਿਰੋਧੀ ਅਸਫਲਤਾ ਮੋਡਾਂ ਤੋਂ ਪੀੜਤ ਹੈ। ਥ੍ਰੈਸ਼ਹੋਲਡ ਬਹੁਤ ਤੰਗ ਸੈੱਟ ਕਰੋ ਅਤੇ ਤੁਸੀਂ ਆਮ ਲੋਡ ਭਿੰਨਤਾਵਾਂ ਦੇ ਦੌਰਾਨ ਝੂਠੇ ਸਕਾਰਾਤਮਕ ਵਿੱਚ ਡੁੱਬ ਜਾਂਦੇ ਹੋ। ਉਹਨਾਂ ਨੂੰ ਬਹੁਤ ਢਿੱਲੀ ਸੈੱਟ ਕਰੋ ਅਤੇ ਤੁਸੀਂ ਅਸਲ ਵਿਗਾੜ ਤੋਂ ਖੁੰਝ ਜਾਂਦੇ ਹੋ ਜਦੋਂ ਤੱਕ ਇਹ ਪੂਰੀ ਤਰ੍ਹਾਂ ਆਊਟੇਜ ਨਹੀਂ ਬਣ ਜਾਂਦਾ। ਪੂਰਵ-ਅਨੁਮਾਨੀ ਚੇਤਾਵਨੀ ਇਹ ਸਿੱਖਣ ਦੁਆਰਾ ਦੋਵਾਂ ਸਮੱਸਿਆਵਾਂ ਨੂੰ ਹੱਲ ਕਰਦੀ ਹੈ ਕਿ ਹਰੇਕ ਮੈਟ੍ਰਿਕ ਲਈ ਸਮੇਂ ਦੇ ਹਰੇਕ ਬਿੰਦੂ 'ਤੇ "ਆਮ" ਕਿਹੋ ਜਿਹਾ ਦਿਖਾਈ ਦਿੰਦਾ ਹੈ।

ਪਹਿਲੂਥ੍ਰੈਸ਼ਹੋਲਡ-ਆਧਾਰਿਤਭਵਿੱਖਬਾਣੀ (AI)
ਗਲਤ ਸਕਾਰਾਤਮਕ ਦਰ40–70%3–8%
ਆਊਟੇਜ ਤੋਂ ਪਹਿਲਾਂ ਲੀਡ ਟਾਈਮ0 ਮਿੰਟ (ਪ੍ਰਤੀਕਿਰਿਆਸ਼ੀਲ)15-45 ਮਿੰਟ (ਭਵਿੱਖਬਾਣੀ)
ਲੋਡ ਪੈਟਰਨ ਨੂੰ ਅਨੁਕੂਲਨਹੀਂ, ਦਸਤੀ ਟਿਊਨਿੰਗ ਦੀ ਲੋੜ ਹੈਹਾਂ, ਆਟੋਮੈਟਿਕ ਬੇਸਲਾਈਨ ਸਿਖਲਾਈ
ਬਹੁ-ਮੀਟ੍ਰਿਕ ਸਬੰਧਦਸਤੀ ਨਿਯਮ ਚੇਨਆਟੋਮੈਟਿਕ ਕਰਾਸ-ਮੈਟ੍ਰਿਕ ਵਿਸ਼ਲੇਸ਼ਣ
ਮੌਸਮੀ ਜਾਗਰੂਕਤਾਕੋਈ ਨਹੀਂਰੋਜ਼ਾਨਾ, ਹਫਤਾਵਾਰੀ, ਮਾਸਿਕ ਚੱਕਰ
ਸੈੱਟਅੱਪ ਜਟਿਲਤਾਘੱਟਮੱਧਮ (ਸ਼ੁਰੂਆਤੀ ਸਿਖਲਾਈ ਦੀ ਮਿਆਦ)
ਰੱਖ-ਰਖਾਅਉੱਚ (ਸਥਿਰ ਥ੍ਰੈਸ਼ਹੋਲਡ ਟਿਊਨਿੰਗ)ਘੱਟ (ਸਵੈ-ਅਨੁਕੂਲ ਮਾਡਲ)

ਕੁਦਰਤੀ ਭਾਸ਼ਾ ਡੇਟਾਬੇਸ ਸਵਾਲਾਂ ਅਤੇ ਅਨੁਕੂਲਤਾ ਲਈ LLM ਏਕੀਕਰਣ

GPT-4 ਅਤੇ ਕਲਾਉਡ ਵਰਗੇ ਵੱਡੇ ਭਾਸ਼ਾ ਮਾਡਲ ਬੁੱਧੀਮਾਨ ਡਾਟਾਬੇਸ ਸਹਾਇਕ ਵਜੋਂ ਕੰਮ ਕਰ ਸਕਦੇ ਹਨ, ਕੁਦਰਤੀ ਭਾਸ਼ਾ ਦੇ ਸਵਾਲਾਂ ਦਾ SQL ਵਿੱਚ ਅਨੁਵਾਦ ਕਰ ਸਕਦੇ ਹਨ, EXPLAIN ਯੋਜਨਾਵਾਂ ਦਾ ਵਿਸ਼ਲੇਸ਼ਣ ਕਰ ਸਕਦੇ ਹਨ, ਅਤੇ ਅਨੁਕੂਲਤਾ ਦਾ ਸੁਝਾਅ ਦੇ ਸਕਦੇ ਹਨ। ਇਹ ਸਮਰੱਥਾ ਬਦਲਦੀ ਹੈ ਕਿ ਕਿਵੇਂ DBAs ਅਤੇ ਡਿਵੈਲਪਰ ਡੇਟਾਬੇਸ ਨਾਲ ਇੰਟਰੈਕਟ ਕਰਦੇ ਹਨ - ਐਗਜ਼ੀਕਿਊਸ਼ਨ ਯੋਜਨਾਵਾਂ ਨੂੰ ਹੱਥੀਂ ਵੰਡਣ ਦੀ ਬਜਾਏ, ਉਹ ਸਧਾਰਨ ਅੰਗਰੇਜ਼ੀ ਵਿੱਚ ਸਮੱਸਿਆ ਦਾ ਵਰਣਨ ਕਰ ਸਕਦੇ ਹਨ ਅਤੇ ਕਾਰਵਾਈਯੋਗ ਸਿਫਾਰਸ਼ਾਂ ਪ੍ਰਾਪਤ ਕਰ ਸਕਦੇ ਹਨ।

LLM-ਪਾਵਰਡ ਕਿਊਰੀ ਓਪਟੀਮਾਈਜੇਸ਼ਨ ਪਾਈਪਲਾਈਨਹੌਲੀ ਪੁੱਛਗਿੱਛਆਰਡਰਾਂ ਤੋਂ * ਚੁਣੋ'ਤੇ ਉਪਭੋਗਤਾਵਾਂ ਨਾਲ ਜੁੜੋ...ਲੇਟੈਂਸੀ: 12.4 ਸਕਿੰਟਵਿਸ਼ਲੇਸ਼ਣ ਦੀ ਵਿਆਖਿਆ ਕਰੋਐਗਜ਼ੀਕਿਊਸ਼ਨ ਪਲਾਨ ਨੂੰ ਪਾਰਸ ਕਰੋਪੂਰੇ ਸਕੈਨ ਦੀ ਪਛਾਣ ਕਰੋਲਾਗਤ ਦਾ ਅੰਦਾਜ਼ਾLLM ਇੰਜਣGPT-4 / ਕਲੌਡਸਕੀਮਾ-ਜਾਣੂ ਸੰਦਰਭਇੰਡੈਕਸ ਮੈਟਾਡੇਟਾ + ਅੰਕੜੇਸੁਝਾਅਕੰਪੋਜ਼ਿਟ ਇੰਡੈਕਸ ਸ਼ਾਮਲ ਕਰੋਸਬਕਵੇਰੀ ਮੁੜ-ਲਿਖੋਭਾਗ ਸਾਰਣੀਅਨੁਕੂਲਿਤ ਪੁੱਛਗਿੱਛSQL ਦੁਬਾਰਾ ਲਿਖਿਆ ਗਿਆਲੇਟੈਂਸੀ: 0.3s (97% ਤੇਜ਼)ਫੀਡਬੈਕ ਲੂਪ → ਫਾਈਨ-ਟਿਊਨLLM ਓਪਟੀਮਾਈਜੇਸ਼ਨ ਪ੍ਰਕਿਰਿਆ ਦਾ ਵੇਰਵਾ1. ਕੈਪਚਰ ਕਰੋਹੌਲੀ ਪੁੱਛਗਿੱਛ ਲੌਗ ਪਾਰਸਰਲੇਟੈਂਸੀ > ਥ੍ਰੈਸ਼ਹੋਲਡ2. ਸੰਦਰਭ ਬਿਲਡਸਾਰਣੀ ਸਕੀਮਾ + ਸੂਚਕਾਂਕਅੰਕੜੇ + ਮੁੱਖਤਾ3. LLM ਵਿਸ਼ਲੇਸ਼ਣEXPLAIN ਦੇ ਨਾਲ ਪ੍ਰੋਂਪਟ ਕਰੋਬਹੁ-ਕਦਮ ਤਰਕ4. ਪ੍ਰਮਾਣਿਤ + ਲਾਗੂ ਕਰੋਸੈਂਡਬੌਕਸ ਐਗਜ਼ੀਕਿਊਸ਼ਨA/B ਲੇਟੈਂਸੀ ਦੀ ਤੁਲਨਾ ਕਰੋਡੀਬੀ ਓਪਟੀਮਾਈਜੇਸ਼ਨ ਲਈ ਪ੍ਰੋਂਪਟ ਇੰਜੀਨੀਅਰਿੰਗਸਿਸਟਮ: "ਤੁਸੀਂ ਇੱਕ ਮਾਹਰ DBA ਹੋ। ਵਿਆਖਿਆ ਯੋਜਨਾ ਦਾ ਵਿਸ਼ਲੇਸ਼ਣ ਕਰੋ..."ਉਪਭੋਗਤਾ: [ਸਕੀਮਾ DDL] + [ਆਉਟਪੁੱਟ ਸਪਸ਼ਟ ਕਰੋ] + [ਸਵਾਲ]ਜਵਾਬ: ਸੂਚਕਾਂਕ ਸੁਝਾਅ + ਦੁਬਾਰਾ ਲਿਖੀ ਪੁੱਛਗਿੱਛ + ਤਰਕਸੁਰੱਖਿਆ ਗਾਰਡਰੇਲਵਿਸ਼ਲੇਸ਼ਣ ਲਈ ਰੀਡ-ਓਨਲੀ ਮੋਡ (ਕੋਈ DDL ਐਗਜ਼ੀਕਿਊਸ਼ਨ ਨਹੀਂ)ਉਤਪਾਦਨ ਐਪਲੀਕੇਸ਼ਨ ਤੋਂ ਪਹਿਲਾਂ ਸੈਂਡਬੌਕਸ ਟੈਸਟਿੰਗਸਕੀਮਾ ਤਬਦੀਲੀਆਂ ਲਈ ਮਨੁੱਖੀ ਪ੍ਰਵਾਨਗੀ ਦੀ ਲੋੜ ਹੈ

ਇੱਕ LLM ਕਿਊਰੀ ਆਪਟੀਮਾਈਜ਼ਰ ਬਣਾਉਣਾ

ਨਿਮਨਲਿਖਤ ਪਾਈਥਨ ਲਾਗੂਕਰਨ ਇੱਕ LLM-ਸੰਚਾਲਿਤ ਪੁੱਛਗਿੱਛ ਅਨੁਕੂਲਨ ਸਹਾਇਕ ਬਣਾਉਂਦਾ ਹੈ ਜੋ EXPLAIN ਯੋਜਨਾਵਾਂ ਦਾ ਵਿਸ਼ਲੇਸ਼ਣ ਕਰਦਾ ਹੈ ਅਤੇ ਸੁਧਾਰਾਂ ਦਾ ਸੁਝਾਅ ਦਿੰਦਾ ਹੈ। ਇਹ OpenAI ਦੇ API ਨਾਲ ਏਕੀਕ੍ਰਿਤ ਹੈ ਅਤੇ ਇਸ ਵਿੱਚ ਸਕੀਮਾ-ਜਾਗਰੂਕ ਸੰਦਰਭ ਬਿਲਡਿੰਗ ਸ਼ਾਮਲ ਹੈ।

# llm_query_optimizer.py — AI-powered database query optimization
import openai
import json
import mysql.connector
import psycopg2
import logging
from dataclasses import dataclass
from typing import Optional

logger = logging.getLogger(__name__)


@dataclass
class QueryAnalysis:
    original_query: str
    explain_plan: dict
    schema_context: str
    suggestions: list
    optimized_query: Optional[str]
    estimated_improvement: str


class LLMQueryOptimizer:
    def __init__(self, api_key, db_config, db_type='mysql', model='gpt-4'):
        self.client = openai.OpenAI(api_key=api_key)
        self.db_config = db_config
        self.db_type = db_type
        self.model = model

    def get_explain_plan(self, query):
        """Execute EXPLAIN ANALYZE and return the plan."""
        if self.db_type == 'mysql':
            conn = mysql.connector.connect(**self.db_config)
            cursor = conn.cursor(dictionary=True)
            cursor.execute(f'EXPLAIN FORMAT=JSON {query}')
            plan = cursor.fetchone()
            cursor.close()
            conn.close()
            return json.loads(plan['EXPLAIN'])
        elif self.db_type == 'postgresql':
            conn = psycopg2.connect(**self.db_config)
            cursor = conn.cursor()
            cursor.execute(f'EXPLAIN (FORMAT JSON, ANALYZE, BUFFERS) {query}')
            plan = cursor.fetchone()[0]
            cursor.close()
            conn.close()
            return plan

    def get_schema_context(self, tables):
        """Extract schema DDL and statistics for context."""
        context_parts = []
        if self.db_type == 'mysql':
            conn = mysql.connector.connect(**self.db_config)
            cursor = conn.cursor()
            for table in tables:
                cursor.execute(f'SHOW CREATE TABLE {table}')
                row = cursor.fetchone()
                context_parts.append(f'-- Table: {table}\n{row[1]}')

                cursor.execute(f'SHOW INDEX FROM {table}')
                indexes = cursor.fetchall()
                idx_info = '\n'.join([f'  Index: {idx[2]}, Column: {idx[4]}, Cardinality: {idx[6]}' for idx in indexes])
                context_parts.append(f'-- Indexes for {table}:\n{idx_info}')

                cursor.execute(f"SELECT table_rows, data_length, index_length FROM information_schema.tables WHERE table_name = '{table}'")
                stats = cursor.fetchone()
                if stats:
                    context_parts.append(f'-- Stats: rows={stats[0]}, data_size={stats[1]}, index_size={stats[2]}')
            cursor.close()
            conn.close()

        return '\n\n'.join(context_parts)

    def analyze_query(self, query, tables):
        """Full LLM analysis of a slow query."""
        explain_plan = self.get_explain_plan(query)
        schema_context = self.get_schema_context(tables)

        prompt = f"""You are an expert database administrator specializing in {self.db_type} performance tuning.

Analyze the following slow query, its EXPLAIN plan, and the schema context. Provide:
1. Root cause of poor performance
2. Specific index recommendations (with CREATE INDEX statements)
3. Query rewrite suggestions (with the rewritten SQL)
4. Estimated performance improvement
5. Any schema changes that would help

## Original Query
```sql
{query}
```

## EXPLAIN Plan
```json
{json.dumps(explain_plan, indent=2)}
```

## Schema Context
```
{schema_context}
```

Respond in JSON format:
{{
  "root_cause": "...",
  "index_recommendations": ["CREATE INDEX ...", ...],
  "rewritten_query": "SELECT ...",
  "estimated_improvement": "Nx faster",
  "schema_changes": ["..."],
  "explanation": "..."
}}"""

        response = self.client.chat.completions.create(
            model=self.model,
            messages=[
                {'role': 'system', 'content': 'You are an expert DBA. Return valid JSON only.'},
                {'role': 'user', 'content': prompt}
            ],
            temperature=0.1,
            response_format={'type': 'json_object'}
        )

        result = json.loads(response.choices[0].message.content)

        return QueryAnalysis(
            original_query=query,
            explain_plan=explain_plan,
            schema_context=schema_context,
            suggestions=result.get('index_recommendations', []),
            optimized_query=result.get('rewritten_query'),
            estimated_improvement=result.get('estimated_improvement', 'Unknown')
        )

    def batch_optimize(self, slow_query_log_path, top_n=20):
        """Parse slow query log and optimize the top N most impactful queries."""
        queries = self._parse_slow_log(slow_query_log_path)
        sorted_queries = sorted(queries, key=lambda q: q['total_time'], reverse=True)[:top_n]

        results = []
        for q in sorted_queries:
            try:
                tables = self._extract_tables(q['query'])
                analysis = self.analyze_query(q['query'], tables)
                results.append({
                    'query': q['query'],
                    'frequency': q['count'],
                    'total_time': q['total_time'],
                    'analysis': analysis
                })
                logger.info(f'Optimized query (est. {analysis.estimated_improvement}): {q["query"][:80]}')
            except Exception as e:
                logger.error(f'Failed to analyze query: {e}')
        return results

    def _parse_slow_log(self, path):
        queries = {}
        current_query = []
        current_time = 0
        with open(path) as f:
            for line in f:
                if line.startswith('# Query_time:'):
                    parts = line.split()
                    current_time = float(parts[2])
                elif line.startswith('SET timestamp') or line.startswith('#'):
                    continue
                elif line.strip().endswith(';'):
                    current_query.append(line.strip())
                    full_query = ' '.join(current_query)
                    if full_query not in queries:
                        queries[full_query] = {'query': full_query, 'count': 0, 'total_time': 0}
                    queries[full_query]['count'] += 1
                    queries[full_query]['total_time'] += current_time
                    current_query = []
                else:
                    current_query.append(line.strip())
        return list(queries.values())

    def _extract_tables(self, query):
        import re
        tables = set()
        for match in re.finditer(r'(?:FROM|JOIN|INTO|UPDATE)\s+[`"]?(\w+)[`"]?', query, re.IGNORECASE):
            tables.add(match.group(1))
        return list(tables)


if __name__ == '__main__':
    import os
    optimizer = LLMQueryOptimizer(
        api_key=os.environ['OPENAI_API_KEY'],
        db_config={'host': 'localhost', 'user': 'root', 'password': '', 'database': 'app_db'},
        db_type='mysql'
    )
    analysis = optimizer.analyze_query(
        'SELECT * FROM orders o JOIN users u ON o.user_id = u.id WHERE o.status = "pending" AND o.created_at > "2026-01-01" ORDER BY o.created_at DESC LIMIT 100',
        ['orders', 'users']
    )
    print(json.dumps(analysis.__dict__, indent=2, default=str))

ਆਟੋ-ਰੀਮੀਡੀਏਸ਼ਨ ਵਰਕਫਲੋਜ਼

ਆਟੋ-ਰੀਮੀਡੀਏਸ਼ਨ ਉਹ ਹੈ ਜਿੱਥੇ AI-ਸੰਚਾਲਿਤ ਡਾਟਾਬੇਸ ਨਿਗਰਾਨੀ ਸਭ ਤੋਂ ਠੋਸ ROI ਪ੍ਰਦਾਨ ਕਰਦੀ ਹੈ। ਕਿਸੇ ਭਗੌੜੇ ਪੁੱਛਗਿੱਛ ਜਾਂ ਸਕੇਲ ਰੀਡ ਪ੍ਰਤੀਕ੍ਰਿਤੀਆਂ ਨੂੰ ਖਤਮ ਕਰਨ ਲਈ ਸਵੇਰੇ 3 ਵਜੇ ਇੱਕ DBA ਨੂੰ ਜਗਾਉਣ ਦੀ ਬਜਾਏ, ਸਿਸਟਮ ਇਸਨੂੰ ਪੂਰੇ ਆਡਿਟ ਟ੍ਰੇਲ ਅਤੇ ਭਰੋਸੇ ਨਾਲ ਸਕੋਰਿੰਗ ਨਾਲ ਆਪਣੇ ਆਪ ਸੰਭਾਲਦਾ ਹੈ।

# auto_remediation.py — Automated database issue remediation
import subprocess
import mysql.connector
import psycopg2
import pymongo
import redis
import logging
import json
from datetime import datetime
from enum import Enum

logger = logging.getLogger(__name__)


class Severity(Enum):
    LOW = 'low'
    MEDIUM = 'medium'
    HIGH = 'high'
    CRITICAL = 'critical'


class RemediationAction:
    def __init__(self, name, description, severity_threshold, confidence_threshold=0.9):
        self.name = name
        self.description = description
        self.severity_threshold = severity_threshold
        self.confidence_threshold = confidence_threshold


class AutoRemediator:
    def __init__(self, db_configs, notification_webhook=None):
        self.db_configs = db_configs
        self.webhook = notification_webhook
        self.action_log = []

    def _log_action(self, action, target, result, confidence):
        entry = {
            'timestamp': datetime.utcnow().isoformat(),
            'action': action,
            'target': target,
            'result': result,
            'confidence': confidence
        }
        self.action_log.append(entry)
        logger.info(f'Remediation: {json.dumps(entry)}')
        if self.webhook:
            self._notify(entry)

    def kill_long_running_queries(self, db_type='mysql', max_duration_seconds=300, confidence=0.95):
        """Kill queries exceeding duration threshold."""
        if confidence < 0.9:
            logger.warning(f'Low confidence ({confidence}), skipping kill action')
            return []

        killed = []
        if db_type == 'mysql':
            conn = mysql.connector.connect(**self.db_configs['mysql'])
            cursor = conn.cursor(dictionary=True)
            cursor.execute("""
                SELECT id, user, host, db, time, state, info
                FROM information_schema.processlist
                WHERE command != 'Sleep'
                  AND time > %s
                  AND user != 'system user'
                ORDER BY time DESC
            """, (max_duration_seconds,))

            for proc in cursor.fetchall():
                try:
                    cursor.execute(f'KILL {proc["id"]}')
                    killed.append(proc)
                    self._log_action('kill_query', f'mysql:{proc["id"]}', 'success', confidence)
                except Exception as e:
                    self._log_action('kill_query', f'mysql:{proc["id"]}', f'failed: {e}', confidence)

            cursor.close()
            conn.close()

        elif db_type == 'postgresql':
            conn = psycopg2.connect(**self.db_configs['postgresql'])
            cursor = conn.cursor()
            cursor.execute("""
                SELECT pid, usename, application_name, state,
                       extract(epoch from now() - query_start) as duration, query
                FROM pg_stat_activity
                WHERE state = 'active'
                  AND extract(epoch from now() - query_start) > %s
                  AND usename != 'postgres'
            """, (max_duration_seconds,))

            for row in cursor.fetchall():
                try:
                    cursor.execute('SELECT pg_terminate_backend(%s)', (row[0],))
                    conn.commit()
                    killed.append({'pid': row[0], 'user': row[1], 'duration': row[4]})
                    self._log_action('kill_query', f'pg:{row[0]}', 'success', confidence)
                except Exception as e:
                    self._log_action('kill_query', f'pg:{row[0]}', f'failed: {e}', confidence)

            cursor.close()
            conn.close()

        return killed

    def scale_read_replicas(self, platform='kubernetes', target_replicas=None, confidence=0.92):
        """Scale database read replicas based on load prediction."""
        if confidence < 0.85:
            logger.warning('Insufficient confidence for scaling action')
            return None

        if platform == 'kubernetes':
            cmd = f'kubectl scale statefulset mysql-read --replicas={target_replicas}'
            result = subprocess.run(cmd.split(), capture_output=True, text=True)
            self._log_action('scale_replicas', f'k8s:mysql-read:{target_replicas}', result.stdout.strip(), confidence)
            return result.stdout
        elif platform == 'aws':
            import boto3
            rds = boto3.client('rds')
            response = rds.create_db_instance_read_replica(
                DBInstanceIdentifier=f'read-replica-{datetime.now().strftime("%Y%m%d%H%M")}',
                SourceDBInstanceIdentifier='production-primary'
            )
            self._log_action('create_replica', 'aws:rds', response['DBInstance']['DBInstanceIdentifier'], confidence)
            return response

    def trigger_failover(self, db_type='mysql', confidence=0.98):
        """Initiate database failover when primary is unhealthy."""
        if confidence < 0.95:
            logger.critical(f'Failover requires confidence >= 0.95, got {confidence}. Escalating to human.')
            self._notify({'action': 'failover_escalation', 'confidence': confidence})
            return None

        self._log_action('failover_initiated', db_type, 'starting', confidence)

        if db_type == 'mysql':
            result = subprocess.run(
                ['mysqlsh', '--', 'dba', 'switchToSecondary'],
                capture_output=True, text=True
            )
            self._log_action('failover', 'mysql:innodb_cluster', result.stdout.strip(), confidence)
        elif db_type == 'postgresql':
            result = subprocess.run(
                ['patronictl', 'failover', '--force'],
                capture_output=True, text=True
            )
            self._log_action('failover', 'pg:patroni', result.stdout.strip(), confidence)

    def flush_redis_hotspot(self, pattern, confidence=0.9):
        """Identify and handle Redis key hotspots."""
        r = redis.Redis(**self.db_configs['redis'])
        cursor = 0
        hot_keys = []
        while True:
            cursor, keys = r.scan(cursor, match=pattern, count=1000)
            for key in keys:
                idle = r.object('idletime', key)
                if idle is not None and idle < 5:
                    hot_keys.append(key.decode())
            if cursor == 0:
                break

        if hot_keys:
            self._log_action('hotspot_detected', f'redis:{pattern}', f'{len(hot_keys)} hot keys', confidence)
        return hot_keys

    def run_pg_vacuum(self, table, confidence=0.92):
        """Force VACUUM ANALYZE on bloated PostgreSQL tables."""
        conn = psycopg2.connect(**self.db_configs['postgresql'])
        conn.autocommit = True
        cursor = conn.cursor()
        cursor.execute(f'VACUUM (VERBOSE, ANALYZE) {table}')
        self._log_action('vacuum', f'pg:{table}', 'completed', confidence)
        cursor.close()
        conn.close()

    def _notify(self, payload):
        import requests
        try:
            requests.post(self.webhook, json=payload, timeout=5)
        except Exception as e:
            logger.error(f'Notification failed: {e}')

MySQL-ਵਿਸ਼ੇਸ਼ AI ਸਮੱਸਿਆ ਨਿਪਟਾਰਾ

MySQL ਵਿਲੱਖਣ ਚੁਣੌਤੀਆਂ ਪੇਸ਼ ਕਰਦਾ ਹੈ ਜੋ AI ਵਿਸ਼ਲੇਸ਼ਣ ਤੋਂ ਬਹੁਤ ਲਾਭ ਉਠਾਉਂਦੇ ਹਨ। InnoDB ਬਫਰ ਪੂਲ ਪ੍ਰਬੰਧਨ, ਡੈੱਡਲਾਕ ਖੋਜ, ਹੌਲੀ ਪੁੱਛਗਿੱਛ ਪੈਟਰਨ ਪਛਾਣ, ਅਤੇ ਪ੍ਰਤੀਕ੍ਰਿਤੀ ਲੈਗ ਪੂਰਵ-ਅਨੁਮਾਨ ਹਰੇਕ ਲਈ MySQL-ਵਿਸ਼ੇਸ਼ ਮੈਟ੍ਰਿਕਸ 'ਤੇ ਸਿਖਲਾਈ ਪ੍ਰਾਪਤ ਵਿਸ਼ੇਸ਼ ML ਮਾਡਲਾਂ ਦੀ ਲੋੜ ਹੁੰਦੀ ਹੈ।

ML ਨਾਲ ਹੌਲੀ ਪੁੱਛਗਿੱਛ ਵਿਸ਼ਲੇਸ਼ਣ

ਹੌਲੀ ਪੁੱਛਗਿੱਛ ਲੌਗ ਦੀ ਹੱਥੀਂ ਸਮੀਖਿਆ ਕਰਨ ਦੀ ਬਜਾਏ, ਇੱਕ ML ਮਾਡਲ ਪ੍ਰਸ਼ਨਾਂ ਨੂੰ ਉਹਨਾਂ ਦੇ ਪ੍ਰਦਰਸ਼ਨ ਪ੍ਰਭਾਵ ਅਤੇ ਮੂਲ ਕਾਰਨ ਦੁਆਰਾ ਸ਼੍ਰੇਣੀਬੱਧ ਕਰਦਾ ਹੈ। ਆਮ ਪੈਟਰਨਾਂ ਵਿੱਚ ਲੁਪਤ ਸੂਚਕਾਂਕ, ਕਾਰਟੇਸ਼ੀਅਨ ਜੋੜ, ਸੂਚਕਾਂਕ ਕੀਤੇ ਕਾਲਮਾਂ 'ਤੇ ਫੰਕਸ਼ਨਾਂ ਦੇ ਨਾਲ ਸਬ-ਓਪਟੀਮਲ WHERE ਕਲਾਜ਼, ਅਤੇ ਚੌੜੀਆਂ ਟੇਬਲਾਂ 'ਤੇ SELECT * ਸ਼ਾਮਲ ਹੁੰਦੇ ਹਨ।

InnoDB ਬਫਰ ਪੂਲ ਓਪਟੀਮਾਈਜੇਸ਼ਨ

ਬਫਰ ਪੂਲ ਹਿੱਟ ਅਨੁਪਾਤ MySQL ਦਾ ਸਭ ਤੋਂ ਮਹੱਤਵਪੂਰਨ ਮੈਟ੍ਰਿਕ ਹੈ। AI ਮਾਡਲ ਵਰਕਲੋਡ ਪੈਟਰਨਾਂ ਅਤੇ ਬਫਰ ਪੂਲ ਦੀ ਪ੍ਰਭਾਵਸ਼ੀਲਤਾ ਵਿਚਕਾਰ ਸਬੰਧ ਸਿੱਖਦੇ ਹਨ, ਇਹ ਅੰਦਾਜ਼ਾ ਲਗਾਉਂਦੇ ਹਨ ਕਿ ਹਿੱਟ ਅਨੁਪਾਤ ਕਦੋਂ ਘਟੇਗਾ ਅਤੇ ਕਿਰਿਆਸ਼ੀਲ innodb_buffer_pool_size ਐਡਜਸਟਮੈਂਟਾਂ ਦੀ ਸਿਫ਼ਾਰਸ਼ ਕਰਦਾ ਹੈ। ਬਫਰ ਪੂਲ ਮੈਟ੍ਰਿਕਸ 'ਤੇ ਸਿਖਲਾਈ ਪ੍ਰਾਪਤ ਇੱਕ LSTM ਮਾਡਲ ਪੁੱਛਗਿੱਛ ਲੇਟੈਂਸੀ ਨੂੰ ਪ੍ਰਭਾਵਿਤ ਕਰਨ ਤੋਂ 30 ਮਿੰਟ ਪਹਿਲਾਂ ਕੈਸ਼ ਦਬਾਅ ਦਾ ਅੰਦਾਜ਼ਾ ਲਗਾ ਸਕਦਾ ਹੈ।

ਡੈੱਡਲਾਕ ਖੋਜ ਅਤੇ ਰੋਕਥਾਮ

AI ਆਵਰਤੀ ਪੈਟਰਨਾਂ ਦੀ ਪਛਾਣ ਕਰਨ ਲਈ InnoDB ਡੈੱਡਲਾਕ ਗ੍ਰਾਫਾਂ ਦਾ ਵਿਸ਼ਲੇਸ਼ਣ ਕਰਦਾ ਹੈ। ਡੈੱਡਲਾਕ ਹੋਣ ਤੋਂ ਬਾਅਦ ਸਿਰਫ਼ ਲੌਗਿੰਗ ਕਰਨ ਦੀ ਬਜਾਏ, ਸਿਸਟਮ ਇਹ ਸਿੱਖਦਾ ਹੈ ਕਿ ਕਿਹੜੇ ਟ੍ਰਾਂਜੈਕਸ਼ਨ ਕ੍ਰਮ ਡੈੱਡਲੌਕਸ ਵੱਲ ਲੈ ਜਾਂਦੇ ਹਨ ਅਤੇ ਓਪਰੇਸ਼ਨਾਂ ਨੂੰ ਮੁੜ ਕ੍ਰਮਬੱਧ ਕਰ ਸਕਦੇ ਹਨ ਜਾਂ ਅਲੱਗ-ਥਲੱਗ ਪੱਧਰਾਂ ਨੂੰ ਪਹਿਲਾਂ ਤੋਂ ਵਿਵਸਥਿਤ ਕਰ ਸਕਦੇ ਹਨ।

PostgreSQL-ਵਿਸ਼ੇਸ਼ AI ਸਮੱਸਿਆ ਨਿਪਟਾਰਾ

PostgreSQL ਦਾ MVCC ਆਰਕੀਟੈਕਚਰ ਟੇਬਲ ਬਲੋਟ, ਵੈਕਿਊਮ ਸਮਾਂ-ਸਾਰਣੀ, ਅਤੇ WAL ਪ੍ਰਬੰਧਨ ਦੇ ਆਲੇ-ਦੁਆਲੇ ਵਿਲੱਖਣ ਚੁਣੌਤੀਆਂ ਪੈਦਾ ਕਰਦਾ ਹੈ ਜੋ AI-ਸੰਚਾਲਿਤ ਵਿਸ਼ਲੇਸ਼ਣ ਤੋਂ ਲਾਭ ਪ੍ਰਾਪਤ ਕਰਦੇ ਹਨ।

ਵੈਕਿਊਮ ਵਿਸ਼ਲੇਸ਼ਣ ਅਤੇ ਬਲੋਟ ਖੋਜ

ਏਆਈ ਮਾਡਲ ਟ੍ਰਾਂਜੈਕਸ਼ਨ ਦਰਾਂ, ਡੈੱਡ ਟੂਪਲ ਇਕੱਤਰਤਾ, ਅਤੇ ਆਟੋਵੈਕਿਊਮ ਪ੍ਰਭਾਵਸ਼ੀਲਤਾ ਵਿਚਕਾਰ ਸਬੰਧ ਨੂੰ ਟਰੈਕ ਕਰਦੇ ਹਨ। ਹਰੇਕ ਟੇਬਲ ਲਈ ਬਲੋਟ ਵਿਕਾਸ ਦਰ ਨੂੰ ਸਿੱਖਣ ਦੁਆਰਾ, ਸਿਸਟਮ ਭਵਿੱਖਬਾਣੀ ਕਰਦਾ ਹੈ ਕਿ ਕਦੋਂ ਟੇਬਲ ਸਮੱਸਿਆ ਵਾਲੇ ਬਲੋਟ ਪੱਧਰਾਂ 'ਤੇ ਪਹੁੰਚਣਗੇ ਅਤੇ ਪ੍ਰਦਰਸ਼ਨ ਨੂੰ ਘਟਣ ਤੋਂ ਪਹਿਲਾਂ ਨਿਸ਼ਾਨਾ ਵੈਕਿਊਮ ਓਪਰੇਸ਼ਨਾਂ ਨੂੰ ਚਾਲੂ ਕਰਦਾ ਹੈ।

ਸੂਚਕਾਂਕ ਸਿਫ਼ਾਰਿਸ਼ਾਂ

pg_stat_user_indexes ਅਤੇ pg_stat_statements ਦਾ ਇਕੱਠੇ ਵਿਸ਼ਲੇਸ਼ਣ ਕਰਨਾ ਸੂਚਕਾਂਕ ਵਰਤੋਂ ਦੇ ਪੈਟਰਨਾਂ ਨੂੰ ਦਰਸਾਉਂਦਾ ਹੈ। AI ਡਿਸਕ ਸਪੇਸ ਦੀ ਖਪਤ ਕਰਨ ਵਾਲੇ ਅਣਵਰਤੇ ਸੂਚਕਾਂਕ ਦੀ ਪਛਾਣ ਕਰਦਾ ਹੈ ਅਤੇ ਪੁੱਛਗਿੱਛ ਪੈਟਰਨਾਂ ਦੇ ਆਧਾਰ 'ਤੇ ਨਵੇਂ ਸੂਚਕਾਂਕ ਦਾ ਸੁਝਾਅ ਦਿੰਦਾ ਹੈ-ਪੜ੍ਹਨ ਦੀ ਕਾਰਗੁਜ਼ਾਰੀ ਦੇ ਲਾਭ ਦੇ ਮੁਕਾਬਲੇ ਵਾਧੂ ਸੂਚਕਾਂਕ ਦੀ ਰਾਈਟ ਐਂਪਲੀਫਿਕੇਸ਼ਨ ਲਾਗਤ ਨੂੰ ਧਿਆਨ ਵਿੱਚ ਰੱਖਦੇ ਹੋਏ।

ਕਨੈਕਸ਼ਨ ਪੂਲ ਓਪਟੀਮਾਈਜੇਸ਼ਨ

PostgreSQL ਕਨੈਕਸ਼ਨਾਂ ਨੂੰ MySQL ਤੋਂ ਵੱਖਰੇ ਢੰਗ ਨਾਲ ਹੈਂਡਲ ਕਰਦਾ ਹੈ, ਹਰੇਕ ਕਨੈਕਸ਼ਨ ਨਾਲ ਕਾਫ਼ੀ ਜ਼ਿਆਦਾ ਮੈਮੋਰੀ ਖਪਤ ਹੁੰਦੀ ਹੈ। AI ਮਾਡਲ ਵੱਖ-ਵੱਖ ਵਰਕਲੋਡ ਪ੍ਰੋਫਾਈਲਾਂ (OLTP ਬਨਾਮ OLAP ਬਨਾਮ ਮਿਕਸਡ) ਲਈ ਅਨੁਕੂਲ ਪੂਲ ਆਕਾਰ ਨਿਰਧਾਰਤ ਕਰਨ ਲਈ PgBouncer ਵਿੱਚ ਕਨੈਕਸ਼ਨ ਪੂਲ ਉਪਯੋਗਤਾ ਪੈਟਰਨਾਂ ਦਾ ਵਿਸ਼ਲੇਸ਼ਣ ਕਰਦੇ ਹਨ, ਕਨੈਕਸ਼ਨ ਭੁੱਖਮਰੀ ਅਤੇ ਮੈਮੋਰੀ ਥਕਾਵਟ ਦੋਵਾਂ ਨੂੰ ਰੋਕਦੇ ਹਨ।

ਮੋਂਗੋਡੀਬੀ-ਵਿਸ਼ੇਸ਼ AI ਸਮੱਸਿਆ ਨਿਪਟਾਰਾ

ਮੋਂਗੋਡੀਬੀ ਦਾ ਦਸਤਾਵੇਜ਼ ਮਾਡਲ ਅਤੇ ਵਿਤਰਿਤ ਆਰਕੀਟੈਕਚਰ ਪ੍ਰਦਰਸ਼ਨ ਚੁਣੌਤੀਆਂ ਦਾ ਇੱਕ ਵੱਖਰਾ ਸਮੂਹ ਬਣਾਉਂਦੇ ਹਨ ਜਿਨ੍ਹਾਂ ਨੂੰ ਏਆਈ ਪ੍ਰਭਾਵਸ਼ਾਲੀ ਢੰਗ ਨਾਲ ਹੱਲ ਕਰ ਸਕਦਾ ਹੈ।

ਸੂਚਕਾਂਕ ਸੁਝਾਅ

MongoDB ਕਿਊਰੀ ਪ੍ਰੋਫਾਈਲਰ ਦਾ AI ਵਿਸ਼ਲੇਸ਼ਣ ਕਲੈਕਸ਼ਨ ਸਕੈਨ (COLLSCAN) ਕਰਨ ਵਾਲੇ ਸਵਾਲਾਂ ਦੀ ਪਛਾਣ ਕਰਦਾ ਹੈ ਅਤੇ ਪੁੱਛਗਿੱਛ ਫੀਲਡ ਸੰਜੋਗਾਂ ਦੇ ਆਧਾਰ 'ਤੇ ਮਿਸ਼ਰਿਤ ਸੂਚਕਾਂਕ ਦੀ ਸਿਫ਼ਾਰਸ਼ ਕਰਦਾ ਹੈ। ਮਾਡਲ ਸਰਵੋਤਮ ਸੂਚਕਾਂਕ ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ ਤਿਆਰ ਕਰਨ ਲਈ ਚੋਣ, ਫੀਲਡ ਆਰਡਰ, ਅਤੇ ਕਵਰ ਕੀਤੀ ਪੁੱਛਗਿੱਛ ਅਨੁਕੂਲਤਾ 'ਤੇ ਵਿਚਾਰ ਕਰਦਾ ਹੈ।

ਸ਼ੇਅਰਿੰਗ ਓਪਟੀਮਾਈਜੇਸ਼ਨ

ਸ਼ਾਰਡਡ ਕਲੱਸਟਰਾਂ ਲਈ, AI ਖੰਡ ਵੰਡ, ਮਾਈਗ੍ਰੇਸ਼ਨ ਦਰਾਂ, ਅਤੇ ਪੁੱਛਗਿੱਛ ਰੂਟਿੰਗ ਪੈਟਰਨਾਂ ਦੀ ਨਿਗਰਾਨੀ ਕਰਦਾ ਹੈ। ਜਦੋਂ ਇਹ ਅਸਮਾਨ ਸ਼ਾਰਡ ਉਪਯੋਗਤਾ (ਗਰਮ ਸ਼ਾਰਡ) ਦਾ ਪਤਾ ਲਗਾਉਂਦਾ ਹੈ, ਤਾਂ ਇਹ ਸ਼ਾਰਡ ਕੁੰਜੀ ਤਬਦੀਲੀਆਂ ਜਾਂ ਪੂਰਵ-ਵਿਭਾਜਨ ਦੀਆਂ ਰਣਨੀਤੀਆਂ ਦੀ ਸਿਫ਼ਾਰਸ਼ ਕਰਦਾ ਹੈ। ML ਮਾਡਲ ਪ੍ਰਦਰਸ਼ਨ ਪ੍ਰਭਾਵ ਪੈਣ ਤੋਂ ਪਹਿਲਾਂ ਡਾਟਾ ਵੰਡ ਨੂੰ ਕਿਰਿਆਸ਼ੀਲ ਤੌਰ 'ਤੇ ਸੰਤੁਲਿਤ ਕਰਨ ਲਈ ਵਿਕਾਸ ਦਰਾਂ ਦੀ ਭਵਿੱਖਬਾਣੀ ਕਰਦੇ ਹਨ।

ਵਾਇਰਡਟਾਈਗਰ ਕੈਸ਼ ਵਿਸ਼ਲੇਸ਼ਣ

ਵਾਇਰਡਟਾਈਗਰ ਕੈਸ਼ ਬੇਦਖਲੀ ਪੈਟਰਨ ਵਰਕਲੋਡ ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ ਨੂੰ ਪ੍ਰਗਟ ਕਰਦੇ ਹਨ। AI ਮਾਡਲ ਸਿੱਖਦੇ ਹਨ ਕਿ ਜਦੋਂ ਕੈਚ ਦਬਾਅ ਕਾਰਜਸ਼ੀਲ ਸੈੱਟ ਵਾਧੇ ਬਨਾਮ ਅਕੁਸ਼ਲ ਪਹੁੰਚ ਪੈਟਰਨਾਂ ਕਾਰਨ ਹੁੰਦਾ ਹੈ, ਜਾਂ ਤਾਂ ਕੈਸ਼ ਆਕਾਰ ਵਧਾਉਣ ਜਾਂ ਐਪਲੀਕੇਸ਼ਨ-ਪੱਧਰ ਦੀਆਂ ਤਬਦੀਲੀਆਂ ਜਿਵੇਂ ਕਿ ਪੁੱਛਗਿੱਛ ਬੈਚਿੰਗ ਦੀ ਸਿਫ਼ਾਰਸ਼ ਕਰਦੇ ਹਨ।

Redis-ਵਿਸ਼ੇਸ਼ AI ਸਮੱਸਿਆ ਨਿਪਟਾਰਾ

ਰੈਡਿਸ ਡਿਸਕ-ਅਧਾਰਿਤ ਡੇਟਾਬੇਸ ਨਾਲੋਂ ਵੱਖ-ਵੱਖ ਰੁਕਾਵਟਾਂ ਦੇ ਅਧੀਨ ਕੰਮ ਕਰਦਾ ਹੈ-ਮੈਮੋਰੀ ਮਹੱਤਵਪੂਰਨ ਸਰੋਤ ਹੈ, ਅਤੇ ਲੇਟੈਂਸੀ ਲੋੜਾਂ ਅਕਸਰ ਸਬ-ਮਿਲੀਸਕਿੰਟ ਹੁੰਦੀਆਂ ਹਨ।

ਮੈਮੋਰੀ ਵਿਸ਼ਲੇਸ਼ਣ

AI ਮੈਮੋਰੀ ਫਰੈਗਮੈਂਟੇਸ਼ਨ ਅਨੁਪਾਤ, ਮੁੱਖ ਆਕਾਰ ਵੰਡ, ਅਤੇ TTL ਪੈਟਰਨਾਂ ਨੂੰ ਟਰੈਕ ਕਰਦਾ ਹੈ। ਜਦੋਂ ਫਰੈਗਮੈਂਟੇਸ਼ਨ ਸਿਹਤਮੰਦ ਥ੍ਰੈਸ਼ਹੋਲਡ ਤੋਂ ਵੱਧ ਜਾਂਦੀ ਹੈ, ਤਾਂ ਸਿਸਟਮ ਇਹ ਨਿਰਧਾਰਤ ਕਰਦਾ ਹੈ ਕਿ ਕੀ ਇੱਕ ACTIVEDEFRAG ਐਡਜਸਟਮੈਂਟ ਜਾਂ ਇੱਕ ਨਿਯੰਤਰਿਤ ਰੀਸਟਾਰਟ ਬਿਹਤਰ ਉਪਚਾਰ ਹੈ। ML ਮਾਡਲ OOM ਕਿੱਲਾਂ ਨੂੰ ਰੋਕਣ ਲਈ ਮੈਮੋਰੀ ਦੇ ਵਾਧੇ ਦੇ ਟ੍ਰੈਜੈਕਟਰੀ ਦੀ ਭਵਿੱਖਬਾਣੀ ਕਰਦੇ ਹਨ।

ਕੁੰਜੀ ਪੈਟਰਨ ਖੋਜ ਅਤੇ ਹੌਟਸਪੌਟ ਪਛਾਣ

MONITOR ਨਮੂਨੇ ਅਤੇ OBJECT FREQ ਵਿਸ਼ਲੇਸ਼ਣ ਦੀ ਵਰਤੋਂ ਕਰਦੇ ਹੋਏ, AI ਉਹਨਾਂ ਗਰਮ ਕੁੰਜੀਆਂ ਦੀ ਪਛਾਣ ਕਰਦਾ ਹੈ ਜੋ ਕਲੱਸਟਰ ਸਲਾਟਾਂ ਵਿੱਚ ਅਸਮਾਨ ਲੋਡ ਵੰਡ ਦਾ ਕਾਰਨ ਬਣਦੇ ਹਨ। Redis ਕਲੱਸਟਰ ਤੈਨਾਤੀਆਂ ਲਈ, ਸਿਸਟਮ ਸਲਾਟ ਮਾਈਗ੍ਰੇਸ਼ਨ ਰੁਕਾਵਟਾਂ ਦਾ ਪਤਾ ਲਗਾਉਂਦਾ ਹੈ ਅਤੇ ਹੈਸ਼ ਸਲਾਟ ਵੰਡ ਨੂੰ ਬਿਹਤਰ ਬਣਾਉਣ ਲਈ ਮੁੱਖ ਨਾਮਕਰਨ ਤਬਦੀਲੀਆਂ ਦੀ ਸਿਫ਼ਾਰਸ਼ ਕਰਦਾ ਹੈ।

ਬੇਦਖਲੀ ਨੀਤੀ ਅਨੁਕੂਲਨ

ਵੱਖ-ਵੱਖ ਵਰਕਲੋਡ ਵੱਖ-ਵੱਖ ਬੇਦਖਲੀ ਨੀਤੀਆਂ (ਅਸਥਿਰ-lru, allkeys-lfu, volatile-ttl) ਤੋਂ ਲਾਭ ਪ੍ਰਾਪਤ ਕਰਦੇ ਹਨ। AI ਮੌਜੂਦਾ ਕੁੰਜੀ ਪਹੁੰਚ ਵੰਡ ਦੇ ਆਧਾਰ 'ਤੇ ਹਰੇਕ ਨੀਤੀ ਦੇ ਹਿੱਟ ਰੇਟ ਪ੍ਰਭਾਵ ਨੂੰ ਪੇਸ਼ ਕਰਦੇ ਹੋਏ, ਸਰਵੋਤਮ ਮੈਕਸਮੈਮਰੀ-ਨੀਤੀ ਦੀ ਸਿਫ਼ਾਰਸ਼ ਕਰਨ ਲਈ ਪਹੁੰਚ ਪੈਟਰਨਾਂ ਦਾ ਵਿਸ਼ਲੇਸ਼ਣ ਕਰਦਾ ਹੈ।

ਕਾਉਚਬੇਸ-ਵਿਸ਼ੇਸ਼ AI ਸਮੱਸਿਆ ਨਿਪਟਾਰਾ

ਕਾਊਚਬੇਸ ਦਸਤਾਵੇਜ਼ ਸਟੋਰ, ਕੁੰਜੀ-ਮੁੱਲ, ਅਤੇ SQL-ਵਰਗੀ (N1QL) ਪੁੱਛਗਿੱਛ ਸਮਰੱਥਾਵਾਂ ਨੂੰ ਜੋੜਦਾ ਹੈ, ਇੱਕ ਵਿਲੱਖਣ ਅਨੁਕੂਲਨ ਲੈਂਡਸਕੇਪ ਬਣਾਉਂਦਾ ਹੈ।

N1QL ਪੁੱਛਗਿੱਛ ਅਨੁਕੂਲਨ

AI N1QL ਪੁੱਛਗਿੱਛ ਪੈਟਰਨਾਂ ਦਾ ਵਿਸ਼ਲੇਸ਼ਣ ਕਰਦਾ ਹੈ ਅਤੇ GSI (ਗਲੋਬਲ ਸੈਕੰਡਰੀ ਇੰਡੈਕਸ) ਬਣਾਉਣ, ਕਵਰ ਕੀਤੇ ਸੂਚਕਾਂਕ ਰਣਨੀਤੀਆਂ, ਅਤੇ ਪੁੱਛਗਿੱਛ ਰੀਰਾਈਟਸ ਦੀ ਸਿਫ਼ਾਰਸ਼ ਕਰਨ ਲਈ ਆਉਟਪੁੱਟ ਦੀ ਵਿਆਖਿਆ ਕਰਦਾ ਹੈ। ਸਿਸਟਮ ਇਹ ਸਿੱਖਦਾ ਹੈ ਕਿ ਕਿਹੜੇ N1QL ਪੈਟਰਨ ਲਗਾਤਾਰ ਸਬ-ਓਪਟੀਮਲ ਯੋਜਨਾਵਾਂ ਪੈਦਾ ਕਰਦੇ ਹਨ ਅਤੇ ਕਿਰਿਆਸ਼ੀਲ ਤੌਰ 'ਤੇ ਵਿਕਲਪਾਂ ਦਾ ਸੁਝਾਅ ਦਿੰਦੇ ਹਨ।

ਸੂਚਕਾਂਕ ਸਲਾਹਕਾਰ ਏਕੀਕਰਣ

ਕਾਊਚਬੇਸ ਦਾ ਬਿਲਟ-ਇਨ ਇੰਡੈਕਸ ਸਲਾਹਕਾਰ ਸਿਫ਼ਾਰਸ਼ਾਂ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ, ਪਰ AI ਵਿਸ਼ਵਵਿਆਪੀ ਕੰਮ ਦੇ ਬੋਝ ਨੂੰ ਧਿਆਨ ਵਿੱਚ ਰੱਖ ਕੇ ਇਹਨਾਂ ਨੂੰ ਵਧਾਉਂਦਾ ਹੈ — ਅਲੱਗ-ਥਲੱਗ ਵਿੱਚ ਵਿਅਕਤੀਗਤ ਪੁੱਛਗਿੱਛਾਂ ਦੀ ਬਜਾਏ ਸਮੁੱਚੇ ਐਪਲੀਕੇਸ਼ਨ ਦੇ ਐਕਸੈਸ ਪੈਟਰਨਾਂ ਵਿੱਚ ਪੁੱਛਗਿੱਛ ਲਾਭਾਂ ਦੇ ਵਿਰੁੱਧ ਸੂਚਕਾਂਕ ਬਣਾਉਣ ਦੀ ਲਾਗਤ ਨੂੰ ਸੰਤੁਲਿਤ ਕਰਦਾ ਹੈ।

ਪੁਨਰ-ਸੰਤੁਲਨ ਯੋਜਨਾ

ਜਦੋਂ ਨੋਡਸ ਨੂੰ ਜੋੜਿਆ ਜਾਂ ਹਟਾਇਆ ਜਾਂਦਾ ਹੈ, ਤਾਂ ਕਾਉਚਬੇਸ ਨੂੰ ਡੇਟਾ ਨੂੰ ਮੁੜ ਸੰਤੁਲਿਤ ਕਰਨਾ ਚਾਹੀਦਾ ਹੈ। AI ਇਤਿਹਾਸਕ ਕਲੱਸਟਰ ਵਿਹਾਰ ਦੇ ਆਧਾਰ 'ਤੇ ਮੁੜ-ਸੰਤੁਲਨ ਦੀ ਮਿਆਦ, ਸਰੋਤ ਪ੍ਰਭਾਵ, ਅਤੇ ਅਨੁਕੂਲ ਸਮਾਂ ਵਿੰਡੋ ਦੀ ਭਵਿੱਖਬਾਣੀ ਕਰਦਾ ਹੈ। ਇਹ ਪੀਕ ਘੰਟਿਆਂ ਦੌਰਾਨ ਉਤਪਾਦਨ ਆਵਾਜਾਈ ਨੂੰ ਪ੍ਰਭਾਵਿਤ ਕਰਨ ਤੋਂ ਮੁੜ ਸੰਤੁਲਨ ਕਾਰਜਾਂ ਨੂੰ ਰੋਕਦਾ ਹੈ।

ਮਲਟੀ-ਡਾਟਾਬੇਸ AI ਆਬਜ਼ਰਵੇਬਿਲਟੀ ਆਰਕੀਟੈਕਚਰ

ਜ਼ਿਆਦਾਤਰ ਉਤਪਾਦਨ ਵਾਤਾਵਰਣ ਮਲਟੀਪਲ ਡਾਟਾਬੇਸ ਇੰਜਣ ਚਲਾਉਂਦੇ ਹਨ। ਇੱਕ ਯੂਨੀਫਾਈਡ AI ਆਬਜ਼ਰਵੇਬਿਲਟੀ ਪਲੇਟਫਾਰਮ ਨੂੰ ਸਾਰੇ ਇੰਜਣਾਂ ਵਿੱਚ ਮੈਟ੍ਰਿਕਸ ਨੂੰ ਸਧਾਰਣ ਬਣਾਉਣਾ ਚਾਹੀਦਾ ਹੈ, ਡੇਟਾ ਲੇਅਰ ਵਿੱਚ ਅਸਮਾਨਤਾਵਾਂ ਨੂੰ ਆਪਸ ਵਿੱਚ ਜੋੜਨਾ ਚਾਹੀਦਾ ਹੈ, ਅਤੇ ਓਪਰੇਸ਼ਨ ਟੀਮਾਂ ਨੂੰ ਇੱਕ ਸੁਮੇਲ ਦ੍ਰਿਸ਼ ਪੇਸ਼ ਕਰਨਾ ਚਾਹੀਦਾ ਹੈ।

ਮਲਟੀ-ਡਾਟਾਬੇਸ AI ਆਬਜ਼ਰਵੇਬਿਲਟੀ ਪਲੇਟਫਾਰਮਕੇਂਦਰੀ ਏ.ਆਈਇੰਜਣਕਰਾਸ-ਡੀਬੀ ਸਬੰਧਯੂਨੀਫਾਈਡ ਅਨੌਮਲੀ ਸਕੋਰਿੰਗMySQLInnoDB ਮੈਟ੍ਰਿਕਸਪ੍ਰਤੀਕ੍ਰਿਤੀ ਸਥਿਤੀਹੌਲੀ ਪੁੱਛਗਿੱਛ ਲੌਗmysqld_exporterPostgreSQLpg_stat ਦ੍ਰਿਸ਼ਵੈਕਿਊਮ / ਬਲੋਟWAL ਪੀੜ੍ਹੀpostgres_exporterਮੋਂਗੋਡੀਬੀਸਰਵਰ ਸਥਿਤੀਪੁੱਛਗਿੱਛ ਪ੍ਰੋਫਾਈਲਰਤਿੱਖੀ ਵੰਡmongodb_exporterRedisਮੈਮੋਰੀ / ਫਰੈਗਮੈਂਟੇਸ਼ਨਮੁੱਖ ਪੈਟਰਨਹੌਟਸਪੌਟ ਖੋਜredis_exporterਕਾਉਚਬੇਸN1QL ਮੈਟ੍ਰਿਕਸਸੂਚਕਾਂਕ ਸਲਾਹਕਾਰਮੁੜ ਸੰਤੁਲਨ ਸਥਿਤੀcouchbase_exporterGrafana ਯੂਨੀਫਾਈਡ ਡੈਸ਼ਬੋਰਡ → PagerDuty/OpsGenie ਇੰਟੈਲੀਜੈਂਟ ਅਲਰਟ → ਸਲੈਕ/ਟੀਮ ਸੂਚਨਾਵਾਂ → ਆਟੋ-ਰੀਮੀਡੀਏਸ਼ਨ ਇੰਜਣ

ChatGPT ਅਤੇ ਕਲਾਉਡ ਦੇ ਨਾਲ ਇੱਕ ਕਸਟਮ AI ਡਾਟਾਬੇਸ ਸਹਾਇਕ ਬਣਾਉਣਾ

LLMs ਨੂੰ ਤੁਹਾਡੇ ਡੇਟਾਬੇਸ ਬੁਨਿਆਦੀ ਢਾਂਚੇ ਦੇ ਨਾਲ ਜੋੜਨਾ ਇੱਕ ਇੰਟਰਐਕਟਿਵ DBA ਸਹਾਇਕ ਬਣਾਉਂਦਾ ਹੈ ਜੋ ਕੁਦਰਤੀ ਭਾਸ਼ਾ ਦੇ ਸਵਾਲਾਂ ਦੇ ਜਵਾਬ ਦਿੰਦਾ ਹੈ, ਮੁੱਦਿਆਂ ਦਾ ਨਿਦਾਨ ਕਰਦਾ ਹੈ, ਅਤੇ ਉਪਚਾਰ ਵਰਕਫਲੋ ਨੂੰ ਚਲਾਉਂਦਾ ਹੈ। ਸਹਾਇਕ ਰੀਅਲ-ਟਾਈਮ ਮੀਟ੍ਰਿਕ ਐਕਸੈਸ ਦੇ ਨਾਲ ਰੀਟਰੀਵਲ-ਐਗਮੈਂਟੇਡ ਜਨਰੇਸ਼ਨ (RAG) ਨੂੰ ਜੋੜਦਾ ਹੈ।

# ai_dba_assistant.py — Custom AI DBA assistant with tool integration
import openai
import json
import os
from datetime import datetime


class AIDBAssistant:
    def __init__(self, db_connections, prometheus_url):
        self.client = openai.OpenAI(api_key=os.environ['OPENAI_API_KEY'])
        self.db_conns = db_connections
        self.prom_url = prometheus_url
        self.conversation_history = []
        self.tools = [
            {
                'type': 'function',
                'function': {
                    'name': 'query_prometheus',
                    'description': 'Execute a PromQL query to fetch database metrics',
                    'parameters': {
                        'type': 'object',
                        'properties': {
                            'query': {'type': 'string', 'description': 'PromQL query'},
                            'duration': {'type': 'string', 'description': 'Time range (e.g. 1h, 24h)'}
                        },
                        'required': ['query']
                    }
                }
            },
            {
                'type': 'function',
                'function': {
                    'name': 'run_explain',
                    'description': 'Run EXPLAIN on a SQL query',
                    'parameters': {
                        'type': 'object',
                        'properties': {
                            'query': {'type': 'string'},
                            'db_type': {'type': 'string', 'enum': ['mysql', 'postgresql']}
                        },
                        'required': ['query', 'db_type']
                    }
                }
            },
            {
                'type': 'function',
                'function': {
                    'name': 'get_active_queries',
                    'description': 'List currently running database queries',
                    'parameters': {
                        'type': 'object',
                        'properties': {
                            'db_type': {'type': 'string', 'enum': ['mysql', 'postgresql', 'mongodb']},
                            'min_duration_seconds': {'type': 'integer', 'default': 0}
                        },
                        'required': ['db_type']
                    }
                }
            },
            {
                'type': 'function',
                'function': {
                    'name': 'kill_query',
                    'description': 'Terminate a running database query by ID',
                    'parameters': {
                        'type': 'object',
                        'properties': {
                            'db_type': {'type': 'string'},
                            'process_id': {'type': 'integer'}
                        },
                        'required': ['db_type', 'process_id']
                    }
                }
            }
        ]

    def chat(self, user_message):
        self.conversation_history.append({'role': 'user', 'content': user_message})

        system_prompt = """You are an expert DBA assistant with access to real-time database monitoring tools.
You can query Prometheus metrics, analyze EXPLAIN plans, view active queries, and kill problematic queries.
Always ground your answers in actual data by using the available tools.
When diagnosing issues, follow this methodology:
1. Check current metrics for anomalies
2. Identify root cause
3. Suggest specific remediation steps
4. Execute remediation if the user approves"""

        messages = [{'role': 'system', 'content': system_prompt}] + self.conversation_history

        response = self.client.chat.completions.create(
            model='gpt-4',
            messages=messages,
            tools=self.tools,
            tool_choice='auto'
        )

        message = response.choices[0].message

        if message.tool_calls:
            for tool_call in message.tool_calls:
                fn_name = tool_call.function.name
                fn_args = json.loads(tool_call.function.arguments)
                result = self._execute_tool(fn_name, fn_args)
                self.conversation_history.append(message)
                self.conversation_history.append({
                    'role': 'tool',
                    'tool_call_id': tool_call.id,
                    'content': json.dumps(result)
                })

            follow_up = self.client.chat.completions.create(
                model='gpt-4',
                messages=[{'role': 'system', 'content': system_prompt}] + self.conversation_history
            )
            assistant_reply = follow_up.choices[0].message.content
        else:
            assistant_reply = message.content

        self.conversation_history.append({'role': 'assistant', 'content': assistant_reply})
        return assistant_reply

    def _execute_tool(self, name, args):
        if name == 'query_prometheus':
            from prometheus_api_client import PrometheusConnect
            prom = PrometheusConnect(url=self.prom_url)
            return prom.custom_query(args['query'])
        elif name == 'run_explain':
            return {'plan': 'EXPLAIN output here'}
        elif name == 'get_active_queries':
            return {'queries': []}
        elif name == 'kill_query':
            return {'status': 'killed', 'process_id': args['process_id']}
        return {'error': f'Unknown tool: {name}'}

Prometheus + Grafana + ML ਪਾਈਪਲਾਈਨ ਸੈੱਟਅੱਪ

ਨਿਰੀਖਣਯੋਗਤਾ ਸਟੈਕ AI ਡੇਟਾਬੇਸ ਨਿਗਰਾਨੀ ਦੀ ਰੀੜ੍ਹ ਦੀ ਹੱਡੀ ਬਣਾਉਂਦਾ ਹੈ। ਪ੍ਰੋਮੀਥੀਅਸ ਡੇਟਾਬੇਸ ਨਿਰਯਾਤਕਾਂ ਤੋਂ ਮੈਟ੍ਰਿਕਸ ਨੂੰ ਸਕ੍ਰੈਪ ਕਰਦਾ ਹੈ, ਗ੍ਰਾਫਾਨਾ ਉਹਨਾਂ ਦੀ ਕਲਪਨਾ ਕਰਦਾ ਹੈ, ਅਤੇ ਇੱਕ ML ਪਾਈਪਲਾਈਨ ਵਿਗਾੜ ਖੋਜ ਲਈ ਸਮਾਂ-ਸੀਰੀਜ਼ ਡੇਟਾ ਦੀ ਪ੍ਰਕਿਰਿਆ ਕਰਦੀ ਹੈ।

ਮਲਟੀ-ਡੀਬੀ ਨਿਗਰਾਨੀ ਲਈ ਪ੍ਰੋਮੀਥੀਅਸ ਕੌਂਫਿਗਰੇਸ਼ਨ

# prometheus.yml — Multi-database monitoring configuration
global:
  scrape_interval: 15s
  evaluation_interval: 15s

rule_files:
  - /etc/prometheus/rules/db_anomaly_rules.yml

alerting:
  alertmanagers:
    - static_configs:
        - targets: ['alertmanager:9093']

scrape_configs:
  - job_name: 'mysql'
    static_configs:
      - targets: ['mysql-exporter:9104']
    metrics_path: /metrics
    scrape_interval: 10s

  - job_name: 'postgresql'
    static_configs:
      - targets: ['postgres-exporter:9187']
    scrape_interval: 10s

  - job_name: 'mongodb'
    static_configs:
      - targets: ['mongodb-exporter:9216']
    scrape_interval: 15s

  - job_name: 'redis'
    static_configs:
      - targets: ['redis-exporter:9121']
    scrape_interval: 10s

  - job_name: 'couchbase'
    static_configs:
      - targets: ['couchbase-exporter:9420']
    scrape_interval: 15s

remote_write:
  - url: http://victoriametrics:8428/api/v1/write

ਕਸਟਮ ਗ੍ਰਾਫਾਨਾ ਡੈਸ਼ਬੋਰਡ ਸੰਰਚਨਾ

# grafana_dashboard_generator.py — Auto-generate AI-powered Grafana dashboards
import json
import requests


class GrafanaDashboardGenerator:
    def __init__(self, grafana_url, api_key):
        self.url = grafana_url
        self.headers = {'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json'}

    def create_db_overview_dashboard(self):
        dashboard = {
            'dashboard': {
                'title': 'AI Database Health Overview',
                'tags': ['database', 'ai', 'monitoring'],
                'timezone': 'browser',
                'panels': [
                    self._anomaly_score_panel(grid_pos={'x': 0, 'y': 0, 'w': 12, 'h': 8}),
                    self._query_latency_panel(grid_pos={'x': 12, 'y': 0, 'w': 12, 'h': 8}),
                    self._connection_pool_panel(grid_pos={'x': 0, 'y': 8, 'w': 8, 'h': 8}),
                    self._replication_lag_panel(grid_pos={'x': 8, 'y': 8, 'w': 8, 'h': 8}),
                    self._buffer_cache_panel(grid_pos={'x': 16, 'y': 8, 'w': 8, 'h': 8}),
                    self._remediation_log_panel(grid_pos={'x': 0, 'y': 16, 'w': 24, 'h': 6})
                ],
                'refresh': '10s'
            },
            'overwrite': True
        }
        resp = requests.post(f'{self.url}/api/dashboards/db', headers=self.headers, json=dashboard)
        return resp.json()

    def _anomaly_score_panel(self, grid_pos):
        return {
            'title': 'AI Anomaly Score (All Databases)',
            'type': 'timeseries',
            'gridPos': grid_pos,
            'targets': [
                {'expr': 'db_anomaly_score{db_type="mysql"}', 'legendFormat': 'MySQL'},
                {'expr': 'db_anomaly_score{db_type="postgresql"}', 'legendFormat': 'PostgreSQL'},
                {'expr': 'db_anomaly_score{db_type="mongodb"}', 'legendFormat': 'MongoDB'},
                {'expr': 'db_anomaly_score{db_type="redis"}', 'legendFormat': 'Redis'},
                {'expr': 'db_anomaly_score{db_type="couchbase"}', 'legendFormat': 'Couchbase'}
            ],
            'fieldConfig': {
                'defaults': {
                    'thresholds': {
                        'steps': [
                            {'value': 0, 'color': 'green'},
                            {'value': 0.5, 'color': 'yellow'},
                            {'value': 0.8, 'color': 'red'}
                        ]
                    },
                    'max': 1, 'min': 0
                }
            }
        }

    def _query_latency_panel(self, grid_pos):
        return {
            'title': 'Query Latency P95 with AI Prediction',
            'type': 'timeseries',
            'gridPos': grid_pos,
            'targets': [
                {'expr': 'histogram_quantile(0.95, rate(db_query_duration_seconds_bucket[5m]))', 'legendFormat': 'Actual P95'},
                {'expr': 'db_query_latency_predicted_p95', 'legendFormat': 'AI Predicted P95'}
            ]
        }

    def _connection_pool_panel(self, grid_pos):
        return {
            'title': 'Connection Pool Utilization',
            'type': 'gauge',
            'gridPos': grid_pos,
            'targets': [
                {'expr': 'db_connections_active / db_connections_max * 100', 'legendFormat': '{{db_type}}'}
            ]
        }

    def _replication_lag_panel(self, grid_pos):
        return {
            'title': 'Replication Lag (seconds)',
            'type': 'timeseries',
            'gridPos': grid_pos,
            'targets': [
                {'expr': 'mysql_slave_status_seconds_behind_master', 'legendFormat': 'MySQL'},
                {'expr': 'pg_replication_lag_seconds', 'legendFormat': 'PostgreSQL'},
                {'expr': 'mongodb_replset_member_replication_lag', 'legendFormat': 'MongoDB'}
            ]
        }

    def _buffer_cache_panel(self, grid_pos):
        return {
            'title': 'Buffer/Cache Hit Ratio',
            'type': 'stat',
            'gridPos': grid_pos,
            'targets': [
                {'expr': 'mysql_global_status_innodb_buffer_pool_hit_ratio', 'legendFormat': 'MySQL InnoDB'},
                {'expr': 'pg_stat_database_blks_hit / (pg_stat_database_blks_hit + pg_stat_database_blks_read)', 'legendFormat': 'PostgreSQL'},
                {'expr': 'redis_keyspace_hit_ratio', 'legendFormat': 'Redis'}
            ]
        }

    def _remediation_log_panel(self, grid_pos):
        return {
            'title': 'Auto-Remediation Action Log',
            'type': 'table',
            'gridPos': grid_pos,
            'targets': [
                {'expr': 'db_remediation_actions_total', 'format': 'table', 'instant': True}
            ]
        }

ਇੰਟੈਲੀਜੈਂਟ ਅਲਰਟਿੰਗ ਲਈ ਪੇਜਰਡਿਊਟੀ ਅਤੇ ਓਪਸਜੀਨੀ ਏਕੀਕਰਣ

ਬੁੱਧੀਮਾਨ ਚੇਤਾਵਨੀ ਸਧਾਰਨ ਵੈਬਹੁੱਕ ਸੂਚਨਾਵਾਂ ਤੋਂ ਪਰੇ ਹੈ। AI-ਅਨੁਕੂਲ ਚੇਤਾਵਨੀਆਂ ਵਿੱਚ ਮੂਲ ਕਾਰਨ ਵਿਸ਼ਲੇਸ਼ਣ, ਇਤਿਹਾਸਕ ਸੰਦਰਭ, ਸੁਝਾਏ ਗਏ ਰਨਬੁੱਕਾਂ, ਅਤੇ ਭਰੋਸੇ ਦੇ ਸਕੋਰ ਸ਼ਾਮਲ ਹੁੰਦੇ ਹਨ - ਆਨ-ਕਾਲ ਇੰਜਨੀਅਰਾਂ ਨੂੰ ਉਹ ਸੰਦਰਭ ਪ੍ਰਦਾਨ ਕਰਦੇ ਹਨ ਜਿਨ੍ਹਾਂ ਦੀ ਉਹਨਾਂ ਨੂੰ ਸਮੱਸਿਆਵਾਂ ਨੂੰ ਤੇਜ਼ੀ ਨਾਲ ਹੱਲ ਕਰਨ ਦੀ ਲੋੜ ਹੁੰਦੀ ਹੈ ਜਾਂ ਇਹ ਪੁਸ਼ਟੀ ਕਰਦੇ ਹਨ ਕਿ ਸਵੈ-ਉਪਚਾਰ ਨੇ ਪਹਿਲਾਂ ਹੀ ਸਮੱਸਿਆ ਨੂੰ ਸੰਭਾਲ ਲਿਆ ਹੈ।

# intelligent_alerting.py — AI-enriched alerting for PagerDuty and OpsGenie
import requests
import json
from datetime import datetime


class IntelligentAlertManager:
    def __init__(self, pagerduty_key=None, opsgenie_key=None):
        self.pd_key = pagerduty_key
        self.og_key = opsgenie_key

    def send_enriched_alert(self, anomaly, ai_analysis):
        severity = anomaly.get('severity', 'warning')
        pd_severity = {'critical': 'critical', 'warning': 'warning', 'info': 'info'}.get(severity, 'warning')

        details = {
            'anomaly_score': anomaly.get('score', 0),
            'metric': anomaly.get('metric', 'unknown'),
            'root_cause': ai_analysis.get('root_cause', 'Under investigation'),
            'suggested_actions': ai_analysis.get('actions', []),
            'auto_remediation_status': ai_analysis.get('remediation_status', 'pending'),
            'similar_incidents': ai_analysis.get('similar_past_incidents', []),
            'estimated_impact': ai_analysis.get('impact', 'Unknown'),
            'confidence': ai_analysis.get('confidence', 0)
        }

        if self.pd_key:
            self._send_pagerduty(pd_severity, anomaly, details)
        if self.og_key:
            self._send_opsgenie(severity, anomaly, details)

    def _send_pagerduty(self, severity, anomaly, details):
        payload = {
            'routing_key': self.pd_key,
            'event_action': 'trigger',
            'payload': {
                'summary': f'[AI] Database anomaly: {anomaly["metric"]} (score: {anomaly["score"]})',
                'severity': severity,
                'source': 'ai-db-monitor',
                'component': anomaly.get('db_type', 'database'),
                'custom_details': details
            }
        }
        requests.post('https://events.pagerduty.com/v2/enqueue', json=payload)

    def _send_opsgenie(self, severity, anomaly, details):
        payload = {
            'message': f'[AI] Database anomaly: {anomaly["metric"]} (score: {anomaly["score"]})',
            'priority': {'critical': 'P1', 'warning': 'P3', 'info': 'P5'}.get(severity, 'P3'),
            'details': details,
            'tags': ['ai-monitoring', anomaly.get('db_type', 'database')]
        }
        requests.post(
            'https://api.opsgenie.com/v2/alerts',
            headers={'Authorization': f'GenieKey {self.og_key}'},
            json=payload
        )

AI ਨਾਲ ਰੂਟ ਕਾਰਨ ਵਿਸ਼ਲੇਸ਼ਣ

ਜਦੋਂ ਵਿਗਾੜਾਂ ਦਾ ਪਤਾ ਲਗਾਇਆ ਜਾਂਦਾ ਹੈ, ਤਾਂ ਘਟਨਾ ਦੇ ਜਵਾਬ ਵਿੱਚ ਮੂਲ ਕਾਰਨ ਦਾ ਪਤਾ ਲਗਾਉਣਾ ਸਭ ਤੋਂ ਵੱਧ ਸਮਾਂ ਲੈਣ ਵਾਲਾ ਕਦਮ ਹੈ। AI-ਸੰਚਾਲਿਤ ਰੂਟ ਕਾਰਨ ਵਿਸ਼ਲੇਸ਼ਣ ਕਈ ਸਿਗਨਲਾਂ-ਮੀਟ੍ਰਿਕ ਵਿਗਾੜਾਂ, ਲੌਗ ਪੈਟਰਨ, ਟਰੇਸ ਡੇਟਾ, ਅਤੇ ਹਾਲੀਆ ਤਬਦੀਲੀਆਂ - ਨੂੰ ਘੰਟਿਆਂ ਦੀ ਬਜਾਏ ਸਕਿੰਟਾਂ ਦੇ ਅੰਦਰ ਸੰਭਾਵਿਤ ਕਾਰਨ ਨੂੰ ਦਰਸਾਉਣ ਲਈ ਸਬੰਧਿਤ ਹੈ।

ਪਹੁੰਚ ਸਿਸਟਮ ਨਿਰਭਰਤਾ ਅਤੇ ਜਾਣੇ-ਪਛਾਣੇ ਅਸਫਲ ਮੋਡਾਂ ਦੇ ਗਿਆਨ ਗ੍ਰਾਫ ਨੂੰ ਕਾਇਮ ਰੱਖ ਕੇ ਕੰਮ ਕਰਦੀ ਹੈ। ਜਦੋਂ ਕੋਈ ਅਨੌਮਲੀ ਅੱਗ ਲੱਗ ਜਾਂਦੀ ਹੈ, ਤਾਂ AI ਅੱਪਸਟਰੀਮ ਕਾਰਨਾਂ ਦੀ ਪਛਾਣ ਕਰਨ ਲਈ ਗ੍ਰਾਫ ਨੂੰ ਪਾਰ ਕਰਦਾ ਹੈ। ਉਦਾਹਰਨ ਲਈ, ਜੇਕਰ MySQL 'ਤੇ ਪੁੱਛਗਿੱਛ ਲੇਟੈਂਸੀ ਵਧਦੀ ਹੈ, ਤਾਂ ਸਿਸਟਮ ਜਾਂਚ ਕਰਦਾ ਹੈ: ਕੀ ਕੋਈ ਹਾਲੀਆ ਤੈਨਾਤੀ ਸੀ? ਕੀ ਕਨੈਕਸ਼ਨ ਦੀ ਗਿਣਤੀ ਬਦਲ ਗਈ ਹੈ? ਕੀ ਰੀਪਲੀਕੇਸ਼ਨ ਲੇਗ ਹੈ? ਕੀ ਡਿਸਕ IOPS ਸੰਤ੍ਰਿਪਤ ਹੈ? ਕੀ ਲਾਕ ਵਿਵਾਦ ਹੈ? ਹਰੇਕ ਸਿਗਨਲ ਵੱਖ-ਵੱਖ ਮੂਲ ਕਾਰਨਾਂ ਲਈ ਇੱਕ ਸੰਭਾਵਨਾ ਸਕੋਰ ਵਿੱਚ ਯੋਗਦਾਨ ਪਾਉਂਦਾ ਹੈ।

ML ਪੂਰਵ-ਅਨੁਮਾਨਾਂ ਦੇ ਨਾਲ ਸਮਰੱਥਾ ਯੋਜਨਾ

ML-ਸੰਚਾਲਿਤ ਸਮਰੱਥਾ ਯੋਜਨਾ ਪ੍ਰਤੀਕਿਰਿਆਸ਼ੀਲ ਸਕੇਲਿੰਗ ਤੋਂ ਅੱਗੇ ਭਵਿੱਖਬਾਣੀ ਸਰੋਤ ਪ੍ਰਬੰਧਨ ਵੱਲ ਵਧਦੀ ਹੈ। ਇਤਿਹਾਸਕ ਵਿਕਾਸ ਦੇ ਪੈਟਰਨਾਂ, ਮੌਸਮੀ ਚੱਕਰਾਂ, ਅਤੇ ਯੋਜਨਾਬੱਧ ਕਾਰੋਬਾਰੀ ਸਮਾਗਮਾਂ ਦਾ ਵਿਸ਼ਲੇਸ਼ਣ ਕਰਕੇ, ML ਮਾਡਲ ਅਨੁਮਾਨ ਲਗਾਉਂਦੇ ਹਨ ਕਿ ਡੇਟਾਬੇਸ ਸਰੋਤ ਸੀਮਾਵਾਂ ਨੂੰ ਕਦੋਂ ਮਾਰਣਗੇ।

ਪੈਗੰਬਰ ਸਮਰੱਥਾ ਪੂਰਵ ਅਨੁਮਾਨ ਵਿੱਚ ਉੱਤਮ ਹੈ ਕਿਉਂਕਿ ਇਹ ਗੁੰਮ ਹੋਏ ਡੇਟਾ, ਰੁਝਾਨ ਵਿੱਚ ਤਬਦੀਲੀਆਂ, ਅਤੇ ਮੌਸਮੀ ਪੈਟਰਨਾਂ ਨੂੰ ਮੂਲ ਰੂਪ ਵਿੱਚ ਸੰਭਾਲਦਾ ਹੈ। ਇਸ ਨੂੰ 90 ਦਿਨਾਂ ਦੇ ਰੋਜ਼ਾਨਾ ਸਟੋਰੇਜ ਵਾਧੇ ਦੇ ਡੇਟਾ 'ਤੇ ਸਿਖਲਾਈ ਦਿਓ ਅਤੇ ਇਹ ਭਰੋਸੇ ਦੇ ਅੰਤਰਾਲਾਂ ਦੇ ਨਾਲ ਇੱਕ ਪੂਰਵ ਅਨੁਮਾਨ ਪੈਦਾ ਕਰਦਾ ਹੈ ਜੋ ਇਹ ਦਰਸਾਉਂਦਾ ਹੈ ਕਿ ਤੁਹਾਨੂੰ ਵਾਧੂ ਸਟੋਰੇਜ ਦਾ ਪ੍ਰਬੰਧ ਕਦੋਂ ਕਰਨਾ ਹੋਵੇਗਾ। LSTM ਮਾਡਲ ਥੋੜ੍ਹੇ ਸਮੇਂ ਦੀ ਸਮਰੱਥਾ ਪੂਰਵ-ਅਨੁਮਾਨ ਲਈ ਬਿਹਤਰ ਅਨੁਕੂਲ ਹਨ - ਸਵੇਰ ਦੇ ਟ੍ਰੈਫਿਕ ਸਪਾਈਕ ਤੋਂ ਪਹਿਲਾਂ ਪ੍ਰੀ-ਸਕੇਲ ਲਈ ਕੁਨੈਕਸ਼ਨ ਪੂਲ ਦੀ ਵਰਤੋਂ ਦੇ ਅਗਲੇ 24 ਘੰਟਿਆਂ ਦੀ ਭਵਿੱਖਬਾਣੀ।

ਕਲਾਉਡ-ਵਿਸ਼ੇਸ਼ AI ਟੂਲ

RDS ਲਈ AWS DevOps ਗੁਰੂ

AWS DevOps ਗੁਰੂ RDS ਮੌਕਿਆਂ ਲਈ ML-ਸੰਚਾਲਿਤ ਵਿਗਾੜ ਖੋਜ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ। ਇਹ ਆਪਣੇ ਆਪ ਕਲਾਉਡਵਾਚ ਮੈਟ੍ਰਿਕਸ ਦੀ ਨਿਗਰਾਨੀ ਕਰਦਾ ਹੈ ਅਤੇ ਪ੍ਰਦਰਸ਼ਨ ਸੰਬੰਧੀ ਵਿਗਾੜਾਂ ਦੀ ਪਛਾਣ ਕਰਦਾ ਹੈ, ਉਹਨਾਂ ਨੂੰ ਹਾਲੀਆ ਤੈਨਾਤੀਆਂ ਜਾਂ ਕੌਂਫਿਗਰੇਸ਼ਨ ਤਬਦੀਲੀਆਂ ਨਾਲ ਸਬੰਧਿਤ ਕਰਦਾ ਹੈ। ਏਕੀਕਰਣ ਲਈ ਤੁਹਾਡੇ RDS ਸਰੋਤਾਂ 'ਤੇ DevOps ਗੁਰੂ ਨੂੰ ਸਮਰੱਥ ਬਣਾਉਣ ਅਤੇ SNS ਸੂਚਨਾਵਾਂ ਨੂੰ ਕੌਂਫਿਗਰ ਕਰਨ ਦੀ ਲੋੜ ਹੈ।

Azure SQL ਅਤੇ Cosmos DB ਲਈ Azure AI

Azure, Azure SQL ਡਾਟਾਬੇਸ ਲਈ ਇੰਟੈਲੀਜੈਂਟ ਇਨਸਾਈਟਸ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ, ਜੋ ਕਿ ਪ੍ਰਦਰਸ਼ਨ ਪ੍ਰਤੀਕ੍ਰਿਆਵਾਂ, ਬਲਾਕਿੰਗ ਪੁੱਛਗਿੱਛਾਂ, ਅਤੇ ਸਰੋਤ ਸੀਮਾਵਾਂ ਦਾ ਪਤਾ ਲਗਾਉਣ ਲਈ ਇੱਕ ਬਿਲਟ-ਇਨ ML ਮਾਡਲ ਦੀ ਵਰਤੋਂ ਕਰਦਾ ਹੈ। Azure Cosmos DB ਵਿੱਚ ਬੇਨਤੀ ਯੂਨਿਟ ਓਪਟੀਮਾਈਜੇਸ਼ਨ ਅਤੇ ਭਾਗ ਕੁੰਜੀ ਦੀ ਚੋਣ ਲਈ ਇੱਕ ਏਕੀਕ੍ਰਿਤ AI ਸਲਾਹਕਾਰ ਸ਼ਾਮਲ ਹੈ।

ਕਲਾਊਡ SQL ਅਤੇ ਫਾਇਰਸਟੋਰ ਲਈ GCP ਕਲਾਊਡ ਓਪਰੇਸ਼ਨ

ਗੂਗਲ ਕਲਾਉਡ ਓਪਰੇਸ਼ਨਜ਼ (ਪਹਿਲਾਂ ਸਟੈਕਡ੍ਰਾਈਵਰ) ਕਲਾਉਡ SQL ਲਈ ਬੁੱਧੀਮਾਨ ਚੇਤਾਵਨੀ ਦੀ ਪੇਸ਼ਕਸ਼ ਕਰਦਾ ਹੈ। ਸਿਸਟਮ ਮੈਟ੍ਰਿਕ ਬੇਸਲਾਈਨਾਂ ਨੂੰ ਸਿੱਖਦਾ ਹੈ ਅਤੇ ਚੇਤਾਵਨੀਆਂ ਉਦੋਂ ਹੀ ਉਤਪੰਨ ਕਰਦਾ ਹੈ ਜਦੋਂ ਵਿਵਹਾਰ ਸਿੱਖੇ ਗਏ ਪੈਟਰਨਾਂ ਤੋਂ ਮਹੱਤਵਪੂਰਨ ਤੌਰ 'ਤੇ ਭਟਕ ਜਾਂਦਾ ਹੈ, ਸਥਿਰ ਥ੍ਰੈਸ਼ਹੋਲਡ ਦੇ ਮੁਕਾਬਲੇ ਝੂਠੇ ਸਕਾਰਾਤਮਕ ਨੂੰ ਬਹੁਤ ਘੱਟ ਕਰਦਾ ਹੈ।

ਓਪਨ-ਸਰੋਤ ਡਾਟਾ ਗੁਣਵੱਤਾ ਸੰਦ

ਅਪਾਚੇ ਗ੍ਰਿਫਿਨ

Apache Griffin ਵੱਡੇ ਪੈਮਾਨੇ ਦੀ ਡਾਟਾ ਸੰਪਤੀਆਂ ਲਈ ਡਾਟਾ ਗੁਣਵੱਤਾ ਮਾਪ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ। ਜਦੋਂ ਤੁਹਾਡੀ AI ਨਿਗਰਾਨੀ ਪਾਈਪਲਾਈਨ ਨਾਲ ਏਕੀਕ੍ਰਿਤ ਕੀਤਾ ਜਾਂਦਾ ਹੈ, ਤਾਂ ਇਹ ਡਾਟਾ ਗੁਣਵੱਤਾ ਦੀਆਂ ਵਿਗਾੜਾਂ ਦਾ ਪਤਾ ਲਗਾਉਂਦਾ ਹੈ-ਗੁੰਮ ਮੁੱਲ, ਸਕੀਮਾ ਡ੍ਰਾਈਫਟ, ਡਿਸਟ੍ਰੀਬਿਊਸ਼ਨ ਬਦਲਾਅ-ਜੋ ਅਕਸਰ ਡਾਟਾਬੇਸ ਪ੍ਰਦਰਸ਼ਨ ਸਮੱਸਿਆਵਾਂ ਤੋਂ ਪਹਿਲਾਂ ਹੁੰਦੇ ਹਨ।

ਵੱਡੀਆਂ ਉਮੀਦਾਂ

ਮਹਾਨ ਉਮੀਦਾਂ ਘੋਸ਼ਣਾਤਮਕ ਡੇਟਾ ਪ੍ਰਮਾਣਿਕਤਾ ਨੂੰ ਸਮਰੱਥ ਬਣਾਉਂਦੀਆਂ ਹਨ। ਤੁਹਾਡੇ ਡੇਟਾਬੇਸ ਟੇਬਲ ਲਈ ਉਮੀਦਾਂ ਨੂੰ ਪਰਿਭਾਸ਼ਿਤ ਕਰਕੇ (ਰੇਂਜ ਦੇ ਅੰਦਰ ਕਤਾਰਾਂ ਦੀ ਗਿਣਤੀ, ਸੀਮਾ ਦੇ ਅੰਦਰ ਕਾਲਮ ਮੁੱਲ, ਸੰਦਰਭ ਇਕਸਾਰਤਾ), ਤੁਸੀਂ ਇੱਕ ਡਾਟਾ ਗੁਣਵੱਤਾ ਨਿਗਰਾਨੀ ਪਰਤ ਬਣਾਉਂਦੇ ਹੋ ਜਿਸ ਨੂੰ AI ਮਾਡਲ ਅਸੰਗਤਤਾ ਖੋਜ ਲਈ ਵਾਧੂ ਸਿਗਨਲਾਂ ਵਜੋਂ ਵਰਤ ਸਕਦੇ ਹਨ।

# data_quality_check.py — Great Expectations integration for DB quality monitoring
import great_expectations as gx


def run_database_quality_checks(connection_string, suite_name='db_health'):
    context = gx.get_context()

    datasource = context.data_sources.add_sql(
        name='production_db',
        connection_string=connection_string
    )

    orders_asset = datasource.add_table_asset(name='orders', table_name='orders')
    batch = orders_asset.add_batch_definition_whole_table('full_table').get_batch()

    suite = context.suites.add(
        gx.ExpectationSuite(name=suite_name)
    )

    suite.add_expectation(
        gx.expectations.ExpectTableRowCountToBeBetween(min_value=1000, max_value=10000000)
    )
    suite.add_expectation(
        gx.expectations.ExpectColumnValuesToNotBeNull(column='user_id')
    )
    suite.add_expectation(
        gx.expectations.ExpectColumnValuesToBeUnique(column='order_number')
    )

    validation_result = batch.validate(suite)

    if not validation_result.success:
        failed = [r for r in validation_result.results if not r.success]
        return {
            'status': 'failed',
            'failed_checks': len(failed),
            'details': [{
                'expectation': str(r.expectation_config),
                'observed': r.result
            } for r in failed]
        }
    return {'status': 'passed', 'checks_run': len(validation_result.results)}

ਪੂਰੀ ਪਾਈਪਲਾਈਨ ਏਕੀਕਰਣ ਉਦਾਹਰਨ

ਸਾਰੇ ਭਾਗਾਂ ਨੂੰ ਇਕੱਠੇ ਲਿਆਉਂਦੇ ਹੋਏ, ਹੇਠਾਂ ਦਿੱਤੇ ਆਰਕੈਸਟਰੇਟਰ ਮੀਟ੍ਰਿਕ ਸੰਗ੍ਰਹਿ, ਵਿਗਾੜ ਖੋਜ, LLM ਵਿਸ਼ਲੇਸ਼ਣ, ਚੇਤਾਵਨੀ, ਅਤੇ ਸਵੈ-ਉਪਚਾਰ ਨੂੰ ਇੱਕ ਸਿੰਗਲ ਨਿਰੰਤਰ ਪਾਈਪਲਾਈਨ ਵਿੱਚ ਜੋੜਦੇ ਹਨ ਜੋ ਤੁਹਾਡੇ ਉਤਪਾਦਨ ਵਾਤਾਵਰਣ ਵਿੱਚ ਸਾਰੇ ਡੇਟਾਬੇਸ ਇੰਜਣਾਂ ਦੀ ਨਿਗਰਾਨੀ ਕਰਦਾ ਹੈ।

# pipeline_orchestrator.py — Full AI database monitoring pipeline
import schedule
import time
import logging
from anomaly_detector import DatabaseAnomalyDetector
from auto_remediation import AutoRemediator
from intelligent_alerting import IntelligentAlertManager
from llm_query_optimizer import LLMQueryOptimizer
import json
import os

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


class AIDatabasePipeline:
    def __init__(self):
        self.detector = DatabaseAnomalyDetector(
            prometheus_url=os.environ['PROMETHEUS_URL']
        )
        self.remediator = AutoRemediator(
            db_configs={
                'mysql': {'host': os.environ['MYSQL_HOST'], 'user': 'monitor', 'password': os.environ['MYSQL_PASS'], 'database': 'production'},
                'postgresql': {'host': os.environ['PG_HOST'], 'user': 'monitor', 'password': os.environ['PG_PASS'], 'dbname': 'production'},
                'redis': {'host': os.environ['REDIS_HOST'], 'port': 6379}
            },
            notification_webhook=os.environ.get('SLACK_WEBHOOK')
        )
        self.alerter = IntelligentAlertManager(
            pagerduty_key=os.environ.get('PAGERDUTY_KEY'),
            opsgenie_key=os.environ.get('OPSGENIE_KEY')
        )
        self.optimizer = LLMQueryOptimizer(
            api_key=os.environ['OPENAI_API_KEY'],
            db_config={'host': os.environ['MYSQL_HOST'], 'user': 'root', 'password': os.environ['MYSQL_PASS'], 'database': 'production'},
            db_type='mysql'
        )

    def run_anomaly_detection_cycle(self):
        """Main detection cycle — runs every minute."""
        for db_type in ['mysql', 'postgresql']:
            try:
                results = self.detector.run_full_analysis(db_type)
                logger.info(f'{db_type}: {results["summary"]["total_anomalies"]} anomalies found')

                for anomaly in results['anomalies']:
                    if anomaly['severity'] == 'critical':
                        ai_analysis = self._analyze_anomaly(anomaly, db_type)
                        self.alerter.send_enriched_alert(anomaly, ai_analysis)

                        if ai_analysis.get('confidence', 0) > 0.95:
                            self._auto_remediate(anomaly, db_type, ai_analysis)
            except Exception as e:
                logger.error(f'Detection cycle failed for {db_type}: {e}')

    def run_query_optimization_cycle(self):
        """Batch query optimization — runs daily."""
        try:
            results = self.optimizer.batch_optimize('/var/log/mysql/slow.log', top_n=10)
            for r in results:
                logger.info(f'Query optimized: {r["analysis"].estimated_improvement}')
        except Exception as e:
            logger.error(f'Query optimization failed: {e}')

    def _analyze_anomaly(self, anomaly, db_type):
        return {
            'root_cause': f'Anomaly in {anomaly["metric"]} for {db_type}',
            'confidence': anomaly.get('score', 0.5),
            'actions': ['investigate', 'scale_if_needed'],
            'remediation_status': 'pending'
        }

    def _auto_remediate(self, anomaly, db_type, analysis):
        metric = anomaly.get('metric', '')
        confidence = analysis.get('confidence', 0)

        if 'slow_queries' in metric or 'query_latency' in metric:
            self.remediator.kill_long_running_queries(db_type=db_type, confidence=confidence)
        elif 'connections' in metric:
            self.remediator.scale_read_replicas(target_replicas=5, confidence=confidence)
        elif 'repl_lag' in metric and confidence > 0.98:
            self.remediator.trigger_failover(db_type=db_type, confidence=confidence)

        logger.info(f'Auto-remediation executed for {metric} on {db_type}')

    def start(self):
        logger.info('AI Database Pipeline started')
        schedule.every(1).minutes.do(self.run_anomaly_detection_cycle)
        schedule.every(1).day.at('02:00').do(self.run_query_optimization_cycle)

        while True:
            schedule.run_pending()
            time.sleep(10)


if __name__ == '__main__':
    pipeline = AIDatabasePipeline()
    pipeline.start()

AI ਡੇਟਾਬੇਸ ਨਿਗਰਾਨੀ ਸਫਲਤਾ ਲਈ ਟ੍ਰੈਕ ਕਰਨ ਲਈ ਮੁੱਖ ਮੈਟ੍ਰਿਕਸ

ਮੈਟ੍ਰਿਕਏਆਈ ਤੋਂ ਪਹਿਲਾਂਏਆਈ ਤੋਂ ਬਾਅਦਸੁਧਾਰ
ਖੋਜ ਕਰਨ ਦਾ ਔਸਤ ਸਮਾਂ (MTTD)15-30 ਮਿੰਟ30 ਸਕਿੰਟ–2 ਮਿੰਟ90-95%
ਰੈਜ਼ੋਲਿਊਸ਼ਨ ਦਾ ਔਸਤ ਸਮਾਂ (MTTR)45-120 ਮਿੰਟ2-5 ਮਿੰਟ95%+
ਗਲਤ ਸਕਾਰਾਤਮਕ ਚੇਤਾਵਨੀ ਦਰ50-70%3–8%90%+
ਘਟਨਾਵਾਂ ਆਟੋ-ਸੁਲਝੀਆਂ0%35–50%N/A
ਡੀਬੀਏ ਆਨ-ਕਾਲ ਪੰਨੇ ਪ੍ਰਤੀ ਹਫ਼ਤੇ40-605-1080%+
ਪੁੱਛਗਿੱਛ ਅਨੁਕੂਲਨ ਸਮਾਂ2-4 ਘੰਟੇ ਪ੍ਰਤੀ ਪੁੱਛਗਿੱਛਪ੍ਰਤੀ ਪੁੱਛਗਿੱਛ 5 ਮਿੰਟ95%+
ਸਮਰੱਥਾ ਯੋਜਨਾ ਸ਼ੁੱਧਤਾ60% (ਹੱਥੀ ਅਨੁਮਾਨ)90%+ (ML ਪੂਰਵ ਅਨੁਮਾਨ)50%+

ਵਧੀਆ ਅਭਿਆਸ ਅਤੇ ਉਤਪਾਦਨ ਦੇ ਵਿਚਾਰ

  • ਨਿਰੀਖਣਯੋਗਤਾ ਨਾਲ ਸ਼ੁਰੂ ਕਰੋ, ਫਿਰ ਬੁੱਧੀ ਜੋੜੋ। ML ਮਾਡਲਾਂ ਨੂੰ ਤੈਨਾਤ ਕਰਨ ਤੋਂ ਪਹਿਲਾਂ ਇਹ ਯਕੀਨੀ ਬਣਾਓ ਕਿ ਵਿਆਪਕ ਮੀਟ੍ਰਿਕ ਸੰਗ੍ਰਹਿ ਮੌਜੂਦ ਹੈ। ਤੁਸੀਂ ਉਸ ਡੇਟਾ ਵਿੱਚ ਅਸੰਗਤੀਆਂ ਦਾ ਪਤਾ ਨਹੀਂ ਲਗਾ ਸਕਦੇ ਜੋ ਤੁਸੀਂ ਇਕੱਤਰ ਨਹੀਂ ਕਰਦੇ ਹੋ।
  • ਉਪਚਾਰ ਲਈ ਭਰੋਸੇ ਦੇ ਥ੍ਰੈਸ਼ਹੋਲਡ ਦੀ ਵਰਤੋਂ ਕਰੋ। ਫੇਲਓਵਰ ਵਰਗੀਆਂ ਵਿਨਾਸ਼ਕਾਰੀ ਕਾਰਵਾਈਆਂ ਲਈ ਉੱਚ ਆਤਮ-ਵਿਸ਼ਵਾਸ ਪੱਟੀਆਂ (95 ਪ੍ਰਤੀਸ਼ਤ ਜਾਂ ਵੱਧ) ਅਤੇ ਸਕੇਲਿੰਗ ਵਰਗੀਆਂ ਗੈਰ-ਵਿਨਾਸ਼ਕਾਰੀ ਕਾਰਵਾਈਆਂ ਲਈ ਹੇਠਲੇ ਥ੍ਰੈਸ਼ਹੋਲਡ (85 ਪ੍ਰਤੀਸ਼ਤ) ਸੈਟ ਕਰੋ।
  • ਮਨੁੱਖੀ ਨਿਗਰਾਨੀ ਨੂੰ ਬਣਾਈ ਰੱਖੋ. ਸਵੈ-ਉਪਚਾਰ ਨੂੰ ਹਮੇਸ਼ਾ ਕਾਰਵਾਈਆਂ ਨੂੰ ਲੌਗ ਕਰਨਾ ਚਾਹੀਦਾ ਹੈ ਅਤੇ ਮਨੁੱਖਾਂ ਨੂੰ ਸੂਚਿਤ ਕਰਨਾ ਚਾਹੀਦਾ ਹੈ। ਫੇਲਓਵਰ ਵਰਗੀਆਂ ਗੰਭੀਰ ਕਾਰਵਾਈਆਂ ਲਈ ਉੱਚੇ ਆਤਮ ਵਿਸ਼ਵਾਸ ਜਾਂ ਸਪਸ਼ਟ ਮਨੁੱਖੀ ਪ੍ਰਵਾਨਗੀ ਦੀ ਲੋੜ ਹੁੰਦੀ ਹੈ।
  • ਮਾਡਲਾਂ ਨੂੰ ਨਿਯਮਿਤ ਤੌਰ 'ਤੇ ਦੁਬਾਰਾ ਸਿਖਲਾਈ ਦਿਓ। ਡੇਟਾਬੇਸ ਵਰਕਲੋਡ ਪੈਟਰਨ ਐਪਲੀਕੇਸ਼ਨ ਤਬਦੀਲੀਆਂ ਦੇ ਨਾਲ ਵਿਕਸਤ ਹੁੰਦੇ ਹਨ. ਘੱਟੋ-ਘੱਟ ਹਫ਼ਤਾਵਾਰੀ ਅਸੰਗਤਤਾ ਖੋਜ ਮਾਡਲਾਂ ਨੂੰ ਦੁਬਾਰਾ ਸਿਖਲਾਈ ਦਿਓ, ਜਾਂ ਔਨਲਾਈਨ ਸਿਖਲਾਈ ਲਾਗੂ ਕਰੋ ਜੋ ਲਗਾਤਾਰ ਅਨੁਕੂਲ ਹੋਣ।
  • ਪਹਿਲਾਂ ਸਟੇਜਿੰਗ ਵਿੱਚ ਟੈਸਟ ਉਪਚਾਰ। ਉਤਪਾਦਨ ਵਿੱਚ ਸਮਰੱਥ ਕਰਨ ਤੋਂ ਪਹਿਲਾਂ ਹਰ ਆਟੋ-ਰੀਮੀਡੀਏਸ਼ਨ ਵਰਕਫਲੋ ਨੂੰ ਇੱਕ ਸਟੇਜਿੰਗ ਵਾਤਾਵਰਣ ਵਿੱਚ ਹਫੜਾ-ਦਫੜੀ ਵਾਲੇ ਇੰਜੀਨੀਅਰਿੰਗ ਦ੍ਰਿਸ਼ਾਂ ਦੇ ਨਾਲ ਪ੍ਰਮਾਣਿਤ ਕੀਤਾ ਜਾਣਾ ਚਾਹੀਦਾ ਹੈ।
  • ਮਲਟੀਪਲ ML ਪਹੁੰਚਾਂ ਨੂੰ ਜੋੜੋ। ਕੋਈ ਸਿੰਗਲ ਐਲਗੋਰਿਦਮ ਸਾਰੀਆਂ ਵਿਸੰਗਤੀਆਂ ਕਿਸਮਾਂ ਨੂੰ ਸੰਭਾਲਦਾ ਨਹੀਂ ਹੈ। ਵਿਆਪਕ ਕਵਰੇਜ ਲਈ ਪੈਗੰਬਰ (ਮੌਸਮੀ), LSTM (ਕ੍ਰਮਵਾਰ), ਅਤੇ ਆਈਸੋਲੇਸ਼ਨ ਫੋਰੈਸਟ (ਮਲਟੀਵੇਰੀਏਟ) ਨੂੰ ਜੋੜਨ ਵਾਲੇ ensemble ਵਿਧੀਆਂ ਦੀ ਵਰਤੋਂ ਕਰੋ।
  • ਸੁਰੱਖਿਅਤ LLM ਏਕੀਕਰਣ। ਪੁੱਛਗਿੱਛ ਵਿਸ਼ਲੇਸ਼ਣ ਲਈ LLMs ਦੀ ਵਰਤੋਂ ਕਰਦੇ ਸਮੇਂ, ਕਦੇ ਵੀ ਅਸਲ ਡਾਟਾ ਮੁੱਲ ਨਾ ਭੇਜੋ—ਸਿਰਫ ਸਕੀਮਾ ਮੈਟਾਡੇਟਾ ਅਤੇ ਯੋਜਨਾਵਾਂ ਦੀ ਵਿਆਖਿਆ ਕਰੋ। AI ਟੂਲਸ ਲਈ ਸਮਰਪਿਤ ਸਿਰਫ਼-ਪੜ੍ਹਨ ਲਈ ਡਾਟਾਬੇਸ ਪ੍ਰਮਾਣ ਪੱਤਰਾਂ ਦੀ ਵਰਤੋਂ ਕਰੋ।
  • ਫੀਡਬੈਕ ਲੂਪਸ ਬਣਾਓ। ਅਸੰਗਤਤਾ ਦਾ ਪਤਾ ਲਗਾਉਣ ਲਈ ਗਲਤ ਸਕਾਰਾਤਮਕ ਅਤੇ ਗਲਤ ਨਕਾਰਾਤਮਕ ਦਰਾਂ ਨੂੰ ਟ੍ਰੈਕ ਕਰੋ। ਮਾਡਲ ਦੀ ਸ਼ੁੱਧਤਾ ਨੂੰ ਲਗਾਤਾਰ ਬਿਹਤਰ ਬਣਾਉਣ ਲਈ ਚੇਤਾਵਨੀ ਪ੍ਰਸੰਗਿਕਤਾ 'ਤੇ ਮਨੁੱਖੀ ਫੀਡਬੈਕ ਦੀ ਵਰਤੋਂ ਕਰੋ।

ਸਿੱਟਾ

AI-ਸੰਚਾਲਿਤ ਡੇਟਾਬੇਸ ਸਮੱਸਿਆ ਨਿਪਟਾਰਾ ਪ੍ਰਤੀਕਿਰਿਆਸ਼ੀਲ ਫਾਇਰਫਾਈਟਿੰਗ ਤੋਂ ਕਿਰਿਆਸ਼ੀਲ, ਬੁੱਧੀਮਾਨ ਕਾਰਜਾਂ ਵਿੱਚ ਇੱਕ ਬੁਨਿਆਦੀ ਤਬਦੀਲੀ ਨੂੰ ਦਰਸਾਉਂਦਾ ਹੈ। ਸਮਾਂ-ਸੀਰੀਜ਼ ਅਸੰਗਤ ਖੋਜ, LLM-ਸੰਚਾਲਿਤ ਪੁੱਛਗਿੱਛ ਅਨੁਕੂਲਨ, ਭਵਿੱਖਬਾਣੀ ਚੇਤਾਵਨੀ, ਅਤੇ ਸਵੈਚਾਲਤ ਉਪਚਾਰ ਨੂੰ ਜੋੜ ਕੇ, ਟੀਮਾਂ ਸਬ-ਮਿੰਟ ਖੋਜ, ਝੂਠੀਆਂ ਚੇਤਾਵਨੀਆਂ ਵਿੱਚ ਨਾਟਕੀ ਕਟੌਤੀ, ਅਤੇ ਰੈਜ਼ੋਲੂਸ਼ਨ ਦੇ ਸਮੇਂ ਵਿੱਚ ਮਹੱਤਵਪੂਰਨ ਸੁਧਾਰ ਪ੍ਰਾਪਤ ਕਰ ਸਕਦੀਆਂ ਹਨ। ਕੁੰਜੀ ਵਧਦੀ-ਫੁੱਲ ਰਹੀ ਹੈ-ਮੈਟ੍ਰਿਕ ਸੰਗ੍ਰਹਿ ਅਤੇ ਡੈਸ਼ਬੋਰਡਾਂ ਨਾਲ ਸ਼ੁਰੂ ਕਰੋ, ਵਿਗਾੜ ਖੋਜ ਵਿੱਚ ਪਰਤ, ਫਿਰ ਹੌਲੀ-ਹੌਲੀ ਸਵੈ-ਉਪਚਾਰ ਨੂੰ ਸਮਰੱਥ ਬਣਾਓ ਕਿਉਂਕਿ ਸਿਸਟਮ ਵਿੱਚ ਵਿਸ਼ਵਾਸ ਵਧਦਾ ਹੈ। ਭਾਵੇਂ ਤੁਸੀਂ MySQL, PostgreSQL, MongoDB, Redis, ਜਾਂ Couchbase ਦਾ ਪ੍ਰਬੰਧਨ ਕਰ ਰਹੇ ਹੋ, AI-ਸੰਚਾਲਿਤ ਪਹੁੰਚ ਵਿਸ਼ਵਵਿਆਪੀ ਤੌਰ 'ਤੇ ਲਾਗੂ ਹੁੰਦੀ ਹੈ, ਹਰ ਇੰਜਣ ਦੀਆਂ ਵਿਲੱਖਣ ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ ਨੂੰ ਅਨੁਕੂਲ ਬਣਾਉਂਦੇ ਹੋਏ, ਤੁਹਾਡੀ ਪੂਰੀ ਡਾਟਾ ਪਰਤ ਵਿੱਚ ਇੱਕ ਏਕੀਕ੍ਰਿਤ ਨਿਰੀਖਣਯੋਗਤਾ ਅਨੁਭਵ ਪ੍ਰਦਾਨ ਕਰਦੇ ਹੋਏ।