# 数据库和中间件监控规则

1.mysql

```
  - alert: MysqlDown
    expr: mysql_up == 0
    for: 0m
    labels:
      severity: critical
    annotations:
      summary: MySQL 离线 (instance {{ $labels.instance }})
      description: "MySQL instance已经离线 {{ $labels.instance }}\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: MysqlTooManyConnections(>80%)
    expr: avg by (instance) (rate(mysql_global_status_threads_connected[1m])) / avg by (instance) (mysql_global_variables_max_connections) * 100 > 80
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: MySQL太多连接(> 80%) (instance {{ $labels.instance }})
      description: "超过80% of MySQL连接数已经使用 {{ $labels.instance }}\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: MysqlHighThreadsRunning
    expr: avg by (instance) (rate(mysql_global_status_threads_running[1m])) / avg by (instance) (mysql_global_variables_max_connections) * 100 > 60
    for: 2m
    labels:
      severity: warning
    annotations:
      summary:MySQL高线程运行(instance {{ $labels.instance }})
      description: "超过60% of MySQL 连接数处于运行状态 {{ $labels.instance }}\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: MysqlSlowQueries
    expr: increase(mysql_global_status_slow_queries[1m]) > 0
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: MySQL 慢查询 (instance {{ $labels.instance }})
      description: "MySQL服务器mysql有一些新的慢查询.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: MysqlInnodbLogWaits
    expr: rate(mysql_global_status_innodb_log_waits[15m]) > 10
    for: 0m
    labels:
      severity: warning
    annotations:
      summary: MySQL InnoDB 日志等待 (instance {{ $labels.instance }})
      description: "MySQL innodb 日志写入停滞\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: MysqlRestarted
    expr: mysql_global_status_uptime < 60
    for: 0m
    labels:
      severity: info
    annotations:
      summary: MySQL 重启中 (instance {{ $labels.instance }})
      description: "MySQL刚重启，不到一分钟{{ $labels.instance }}.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
```

2.oracle

```
- alert: OracleDown
    expr: oracledb_up == 0
    for: 0m
    labels:
      severity: critical
    annotations:
      summary: Oracle 离线 (instance {{ $labels.instance }})
      description: "Oracle instance已经离线 {{ $labels.instance }}\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
-      
```

3.redis

```
  - alert: RedisDown
    expr: redis_up == 0
    for: 0m
    labels:
      severity: critical
    annotations:
      summary: Redis 掉线 (instance {{ $labels.instance }})
      description: "Redis instance 掉线\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: RedisMissingMaster
    expr: (count(redis_instance_info{role="master"}) or vector(0)) < 1
    for: 0m
    labels:
      severity: critical
    annotations:
      summary: Redis 缺少 master (instance {{ $labels.instance }})
      description: "Redis 集群没有标记为 master 的节点.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: RedisTooManyMasters
    expr: count(redis_instance_info{role="master"}) > 1
    for: 0m
    labels:
      severity: critical
    annotations:
      summary: Redis太多masters (instance {{ $labels.instance }})
      description: "Redis 集群有太多节点被标记为 master.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"


  - alert: RedisReplicationBroken
    expr: delta(redis_connected_slaves[1m]) < 0
    for: 0m
    labels:
      severity: critical
    annotations:
      summary:Redis 复制中断(instance {{ $labels.instance }})
      description: "Redis 实例丢失了一个 slave\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: RedisClusterFlapping
    expr: changes(redis_connected_slaves[1m]) > 1
    for: 2m
    labels:
      severity: critical
    annotations:
      summary: Redis 集群震荡 (instance {{ $labels.instance }})
      description: "在 Redis 副本连接中检测到更改。当副本节点失去与主节点的连接并重新连接（也就是抖动）时，就会发生这种情况。\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: RedisMissingBackup
    expr: time() - redis_rdb_last_save_timestamp_seconds > 60 * 60 * 24
    for: 0m
    labels:
      severity: critical
    annotations:
      summary: Redis 缺少备份 (instance {{ $labels.instance }})
      description: Redis 24小时未备份\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  # The exporter must be started with --include-system-metrics flag or REDIS_EXPORTER_INCL_SYSTEM_METRICS=true environment variable.
  - alert: RedisOutOfSystemMemory
    expr: redis_memory_used_bytes / redis_total_system_memory_bytes * 100 > 90
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: Redis 耗尽系统内存 (instance {{ $labels.instance }})
      description: "Redis 消耗系统内存(> 90%)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: RedisOutOfConfiguredMaxmemory
    expr: redis_memory_used_bytes / redis_memory_max_bytes * 100 > 90
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: Redis 超出配置的最大内存 (instance {{ $labels.instance }})
      description: "Redis 已经用完了配置的最大记忆的比例(> 90%)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: RedisTooManyConnections
    expr: redis_connected_clients > 100
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: Redis 太多的连接数 (instance {{ $labels.instance }})
      description: "Redis instance 有太多的连接数\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"


  - alert: RedisRejectedConnections
    expr: increase(redis_rejected_connections_total[1m]) > 0
    for: 0m
    labels:
      severity: critical
    annotations:
      summary:redis拒绝连接 (instance {{ $labels.instance }})
      description: "redis的一些连接被拒绝了\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
```

4.mongodb

```
  - alert: MongodbDown
    expr: mongodb_up == 0
    for: 0m
    labels:
      severity: critical
    annotations:
      summary: MongoDB 掉线 (instance {{ $labels.instance }})
      description: "MongoDB instance 掉线\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"


  - alert: MongodbNumberCursorsOpen
    expr: mongodb_mongod_metrics_cursor_open{state="total"} > 10 * 1000
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: MongoDB 数字游标打开过多 (instance {{ $labels.instance }})
      description: "MongoDB 为客户端打开的游标过多 (> 10k)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: MongodbCursorsTimeouts
    expr: increase(mongodb_mongod_metrics_cursor_timed_out_total[1m]) > 100
    for: 2m
    labels:
      severity: warning
    annotations:
      summary:MongoDB 游标超时 (instance {{ $labels.instance }})
      description: "太多游标超时\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: MongodbTooManyConnections
    expr: avg by(instance) (rate(mongodb_connections{state="current"}[1m])) / avg by(instance) (sum (mongodb_connections) by (instance)) * 100 > 80
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: MongoDB太多连接(instance {{ $labels.instance }})
      description: "太多连接(使用> 80%)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: MongodbVirtualMemoryUsage
    expr: (sum(mongodb_memory{type="virtual"}) BY (instance) / sum(mongodb_memory{type="mapped"}) BY (instance)) > 3
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: MongoDB 虚拟内存使用情况 (instance {{ $labels.instance }})
      description: "内存占用高\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
```

5.rabbitmq

```
  - alert: RabbitmqNodeDown
    expr: sum(rabbitmq_build_info) < 3
    for: 0m
    labels:
      severity: critical
    annotations:
      summary: Rabbitmq node 掉线 (instance {{ $labels.instance }})
      description: " RabbitMQ cluster少于三个节点在运行\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"


  - alert: RabbitmqTooManyConnections
    expr: rabbitmq_connections > 1000
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: Rabbitmq 太多连接数 (instance {{ $labels.instance }})
      description: "一个节点的总连接数太多\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: RabbitmqNoQueueConsumer
    expr: rabbitmq_queue_consumers < 1
    for: 1m
    labels:
      severity: warning
    annotations:
      summary: Rabbitmq 无队列消费者 (instance {{ $labels.instance }})
      description: "一个队列的消费者少于 1 个\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
      
```

6.Elasticsearch

```
  - alert: ElasticsearchHeapUsageTooHigh
    expr: (elasticsearch_jvm_memory_used_bytes{area="heap"} / elasticsearch_jvm_memory_max_bytes{area="heap"}) * 100 > 90
    for: 2m
    labels:
      severity: critical
    annotations:
      summary: Elasticsearch 堆使用率过高 (instance {{ $labels.instance }})
      description: "堆使用超过90%\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: ElasticsearchHeapUsageWarning
    expr: (elasticsearch_jvm_memory_used_bytes{area="heap"} / elasticsearch_jvm_memory_max_bytes{area="heap"}) * 100 > 80
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: Elasticsearch 堆使用警告 (instance {{ $labels.instance }})
      description: "堆使用超过 80%\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: ElasticsearchDiskOutOfSpace
    expr: elasticsearch_filesystem_data_available_bytes / elasticsearch_filesystem_data_size_bytes * 100 < 10
    for: 0m
    labels:
      severity: critical
    annotations:
      summary: Elasticsearch 磁盘空间不足 (instance {{ $labels.instance }})
      description: "磁盘空间使用率>90%\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: ElasticsearchDiskSpaceLow
    expr: elasticsearch_filesystem_data_available_bytes / elasticsearch_filesystem_data_size_bytes * 100 < 20
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: Elasticsearch 磁盘空间紧张(instance {{ $labels.instance }})
      description: "磁盘空间使用率>80%\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: ElasticsearchClusterRed
    expr: elasticsearch_cluster_health_status{color="red"} == 1
    for: 0m
    labels:
      severity: critical
    annotations:
      summary: Elasticsearch 集群红色(instance {{ $labels.instance }})
      description: "Elastic 集群红色状态\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: ElasticsearchClusterYellow
    expr: elasticsearch_cluster_health_status{color="yellow"} == 1
    for: 0m
    labels:
      severity: warning
    annotations:
      summary: Elasticsearch 集群黄色 (instance {{ $labels.instance }})
      description: "Elasticsearch 集群黄色状态\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: ElasticsearchHealthyNodes
    expr: elasticsearch_cluster_health_number_of_nodes < 3
    for: 0m
    labels:
      severity: critical
    annotations:
      summary: Elasticsearch 健康节点过少 (instance {{ $labels.instance }})
      description: "Elasticsearch 健康节点<3\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: ElasticsearchHealthyDataNodes
    expr: elasticsearch_cluster_health_number_of_data_nodes < 3
    for: 0m
    labels:
      severity: critical
    annotations:
      summary:Elasticsearch 健康数据节点过少(instance {{ $labels.instance }})
      description: "Elasticsearch 健康数据节点<3\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: ElasticsearchPendingTasks
    expr: elasticsearch_cluster_health_number_of_pending_tasks > 0
    for: 15m
    labels:
      severity: warning
    annotations:
      summary: Elasticsearch 有待处理任务 (instance {{ $labels.instance }})
      description: "Elasticsearch 有待处理任务. 集群运行缓慢.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: ElasticsearchNoNewDocuments
    expr: increase(elasticsearch_indices_docs{es_data_node="true"}[10m]) < 1
    for: 0m
    labels:
      severity: warning
    annotations:
      summary: Elasticsearch 没有新文件 (instance {{ $labels.instance }})
      description: "10 分钟内没有新文件!\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
```

7.kafka

```
  - alert: KafkaTopicsReplicas
    expr: sum(kafka_topic_partition_in_sync_replica) by (topic) < 3
    for: 0m
    labels:
      severity: critical
    annotations:
      summary: Kafka topics 副本太少 (instance {{ $labels.instance }})
      description: "Kafka topics 同步分区小于3个\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

  - alert: KafkaConsumersGroup
    expr: sum(kafka_consumergroup_lag) by (consumergroup) > 50
    for: 1m
    labels:
      severity: critical
    annotations:
      summary: Kafka消费者组过多(instance {{ $labels.instance }})
      description: "Kafka consumers group\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://qiangrens-organization.gitbook.io/qkd90/fu-wu-qi-yun-wei-he-ce-shi/shu-ju-ku-he-zhong-jian-jian-jian-kong-gui-ze.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
