> ## Documentation Index
> Fetch the complete documentation index at: https://test-8ad8522e-feat-ai-sre.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 调用数据源工具

> 对已配置的数据源执行单个确定性诊断或查询工具。

## 限制说明

| 项目   | 说明                             |
| ---- | ------------------------------ |
| 速率限制 | 每个账户 **2,000 次/分钟**；**32 次/秒** |
| 权限要求 | **数据源查看**（`monit`）             |

通过 `/monit/datasource/list` 获取数据源 ID。停用数据源返回 `datasource_disabled`，`alerting_enabled=false` 不阻断工具。错误使用非 2xx HTTP 状态和 `error.code`、`error.message`、`error.reason`。`tool_not_supported` 表示选中的执行端未提供该工具，不表示厂商权限不足。禁止自动切换 Edge 或回退旧 diagnose 重试。

## 使用说明

* 本入口共用两类工具：由执行端 Edge 定义的诊断工具（如 `mysql.overview`、`prometheus.metric_trends`）和命名为 `<type>.query` 的查询工具。工具前缀必须与数据源类型一致。
* 查询工具要求 Edge 集群支持 Explore 查询（协议里程碑 v0.68.0）；诊断工具要求 v0.71.0 基础 invoke 协议。不支持的集群返回 `edge_upgrade_required`、`mixed_edge_versions` 或 `edge_version_unknown`；禁止自动回退 `/monit/query/data` 或其他接口。
* 查询工具的 `params` 遵循 `tool` 字段描述中按数据源列出的专属 Schema。`expr` 和 `execution` 必填。`limit`/`direction` 只约束原始日志条数与检索方向，不代表 SQL 行数或扫描量。未知扩展字段被容忍，但不参与执行也不透传。
* 查询结果的 `data` 是完整 Explore 结果：`format` 为 `explore_result.v1`，`result.kind` 为 `samples`、`frames` 或 `logs`；日志结果保留 `applied_limit` 和 `has_more`。查询结果不合成 `summary` 或 `truncated`。
* 请求体上限 128 KiB；两类工具的完整成功响应上限均为 10 MiB；诊断工具超时最多 25 秒。


## OpenAPI

````yaml /api-reference/monitors.openapi.zh.json post /monit/datasource/tools/invoke
openapi: 3.1.0
info:
  title: Flashduty 开放 API
  description: >-
    Flashduty 事件管理平台的公开 HTTP API —— 覆盖故障、通知模板、协作空间、值班排班、监控、RUM、以及平台管理。每次调用都需在
    query 中携带 `app_key`，该 key 在 Flashduty 控制台 账户 → APP Key 中签发。所有响应使用统一结构：成功时为
    `{ request_id, data }`，失败时为 `{ request_id, error }`。
  version: 1.0.0
servers:
  - url: https://api.flashcat.cloud
    description: Flashduty Open API
security:
  - AppKeyAuth: []
tags:
  - name: Monitors/告警规则
    description: 创建、管理和导出监控告警规则，查询规则统计和审计历史。
  - name: Monitors/告警数据源
    description: 管理监控告警规则用于查询指标的数据源。
  - name: Monitors/诊断分析
    description: Flashduty AI SRE 使用的诊断与查询接口——数据源即席查询、日志/指标诊断,以及监控对象侧的工具调用。
  - name: Monitors/通用工具
    description: 监控服务开通及数据预览工具。
paths:
  /monit/datasource/tools/invoke:
    post:
      tags:
        - Monitors/告警数据源
      summary: 调用数据源工具
      description: 对已配置的数据源执行单个确定性诊断或查询工具。
      operationId: monit-datasource-tools-invoke
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DatasourceToolInvokeRequest'
            examples:
              diagnostic:
                value:
                  datasource_id: 10
                  params: {}
                  tool: mysql.overview
              query:
                value:
                  datasource_id: 24000
                  tool: prometheus.query
                  params:
                    expr: sum(rate(http_requests_total[5m]))
                    execution:
                      kind: instant
                      to_ms: 1789000000000
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/SuccessEnvelope'
                  - properties:
                      data:
                        $ref: '#/components/schemas/DatasourceToolResult'
                    type: object
              examples:
                diagnostic:
                  value:
                    data:
                      data:
                        version: 8.0.36
                      datasource_id: 10
                      summary: MySQL overview
                      tool: mysql.overview
                    request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                query:
                  value:
                    request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                    data:
                      datasource_id: 24000
                      tool: prometheus.query
                      data:
                        format: explore_result.v1
                        result:
                          kind: samples
                          samples:
                            - labels:
                                __name__: up
                                instance: 10.101.214.50:7070
                              value: 1
          description: 成功
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: >-
            标准 HTTP 错误；error.reason：invalid_request, tool_not_supported,
            datasource_error.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: 标准 HTTP 错误；error.reason：access_denied.
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: 标准 HTTP 错误；error.reason：datasource_not_found.
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: 标准 HTTP 错误；error.reason：datasource_disabled, datasource_in_use.
        '413':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: 标准 HTTP 错误；error.reason：source_too_large, result_too_large.
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: 标准 HTTP 错误；error.reason：overloaded.
        '499':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: 标准 HTTP 错误；error.reason：canceled.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: 标准 HTTP 错误；error.reason：internal.
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: >-
            标准 HTTP 错误；error.reason：no_active_edge, edge_upgrade_required,
            mixed_edge_versions.
        '504':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: 标准 HTTP 错误；error.reason：timeout.
components:
  schemas:
    DatasourceToolInvokeRequest:
      properties:
        account_id:
          description: 可选一致性检查，必须等于认证账户。
          format: uint64
          type: integer
        datasource_id:
          description: 通过 /monit/datasource/list 获取的数据源 ID。
          format: uint64
          minimum: 1
          type: integer
        params:
          additionalProperties: true
          description: >-
            工具专属 JSON 参数；省略等同于 {}。显式 null 非法。查询工具（`<type>.query`）使用 `tool`
            描述中按数据源列出的专属参数 Schema。
          type: object
          x-flashduty-raw-json: true
        tool:
          description: >-
            以数据源类型为前缀的单个工具名。诊断工具由执行端 Edge 定义（如 `mysql.overview`）。查询工具为
            `<type>.query`，`<type>` 取
            `prometheus`、`mysql`、`postgres`、`oracle`、`clickhouse`、`elasticsearch`、`loki`、`victorialogs`、`sls`、`tencent_cls`
            之一；`params` 分别遵循
            `PrometheusQueryParams`、`MySQLQueryParams`、`PostgresQueryParams`、`OracleQueryParams`、`ClickHouseQueryParams`、`ElasticsearchQueryParams`、`LokiQueryParams`、`VictoriaLogsQueryParams`、`SLSQueryParams`、`TencentCLSQueryParams`。
          maxLength: 128
          minLength: 1
          type: string
      required:
        - datasource_id
        - tool
      type: object
    SuccessEnvelope:
      type: object
      description: >-
        成功响应结构。2xx 响应中 `request_id` 标识本次调用（同时出现在 `Flashcat-Request-Id`
        响应头中），`data` 为接口业务 payload。失败响应使用不同结构，参见 `ErrorResponse`。
      properties:
        request_id:
          type: string
          description: 本次请求的唯一 ID，也会在 Flashcat-Request-Id 响应头中返回。反馈问题时请一并附上。
          example: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
        data:
          description: 每个接口自己的业务 payload，详见各接口的 200 响应 schema。
      required:
        - request_id
        - data
    DatasourceToolResult:
      properties:
        data:
          description: 工具专属 JSON 证据，原样保留，不为 null，不包含旧 diagnose 额外信封。
          not:
            type: 'null'
          x-flashduty-raw-json: true
        datasource_id:
          description: 通过 /monit/datasource/list 获取的数据源 ID。
          format: uint64
          minimum: 1
          type: integer
        summary:
          description: 可选非空摘要。
          type: string
          x-flashduty-preserve-absence: true
        tool:
          description: 执行的工具名，与请求一致。
          type: string
        truncated:
          $ref: '#/components/schemas/DatasourceToolTruncation'
          x-flashduty-preserve-absence: true
      required:
        - datasource_id
        - tool
        - data
      type: object
    ErrorResponse:
      type: object
      description: 错误响应结构。`error` 必填，`data` 不存在。
      properties:
        request_id:
          type: string
          example: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
          description: 本次请求的唯一追踪 ID（trace ID），反馈问题时请提供该值以便检索日志。
        error:
          $ref: '#/components/schemas/DutyError'
      required:
        - request_id
        - error
    DatasourceToolTruncation:
      properties:
        reason:
          description: 结果截断原因；该对象存在即表示发生截断。
          type: string
      required:
        - reason
      type: object
    DutyError:
      type: object
      description: 响应结构中的错误 payload，仅在非 2xx 响应时出现。
      properties:
        code:
          $ref: '#/components/schemas/ErrorCode'
        message:
          type: string
          description: 用户可读的错误描述，语言会跟随调用方的 Accept-Language。可能包含字段名、ID 等请求上下文。
          example: The specified parameter template_id is not valid.
        reason:
          description: 可选的机器可读拒绝原因，包含数据源工具错误；结合 HTTP 状态及 code 判断。
          type: string
          x-flashduty-preserve-absence: true
      required:
        - code
        - message
    ErrorCode:
      type: string
      description: >-
        Flashduty 错误码枚举。每个失败响应的 `error.code` 都是下列稳定值之一，HTTP 状态码仅作参考。


        | 错误码 | HTTP | 含义 |

        |---|---|---|

        | `OK` | 200 | 保留值，正常错误响应不会返回。 |

        | `InvalidParameter` | 400 | 必填参数缺失或未通过校验。 |

        | `BadRequest` | 400 | 通用的 400 错误，通常是请求本身不合法。 |

        | `InvalidContentType` | 400 | 请求头 `Content-Type` 不是 `application/json`。
        |

        | `ResourceNotFound` | 400 | 目标资源不存在。注意 HTTP 状态码是 400 而非 404（历史设计）。 |

        | `NoLicense` | 400 | 功能需要有效授权，但未找到可用的 license。 |

        | `ReferenceExist` | 400 | 该资源仍被其他实体引用，无法删除。 |

        | `Unauthorized` | 401 | `app_key` 缺失、无效或已过期。 |

        | `BalanceNotEnough` | 402 | 账户余额不足，无法执行需要计费的操作。 |

        | `AccessDenied` | 403 | 身份认证通过，但 RBAC 权限不足以执行该操作。 |

        | `RouteNotFound` | 404 | 请求的 URL 路径不是已知路由。 |

        | `MethodNotAllowed` | 405 | 当前路径不接受所使用的 HTTP 方法。 |

        | `UndonedOrderExist` | 409 | 账户存在未完成的订单，请稍后重试。 |

        | `RequestLocked` | 423 | 因连续失败被临时锁定。 |

        | `EntityTooLarge` | 413 | 请求体超过允许的最大长度。 |

        | `RequestTooFrequently` | 429 | 命中限流（全局、账户级或集成级）。 |

        | `RequestVerifyRequired` | 428 | 操作需要二次验证码，但未提供。 |

        | `DangerousOperation` | 428 | 危险操作，需要进行 MFA 验证。 |

        | `InternalError` | 500 | 服务端未预期错误。反馈问题请附上 `request_id`。 |

        | `ServiceUnavailable` | 503 | 后端依赖不可用，请稍后重试。 |
      enum:
        - OK
        - InvalidParameter
        - BadRequest
        - InvalidContentType
        - ResourceNotFound
        - NoLicense
        - ReferenceExist
        - Unauthorized
        - BalanceNotEnough
        - AccessDenied
        - RouteNotFound
        - MethodNotAllowed
        - UndonedOrderExist
        - RequestLocked
        - EntityTooLarge
        - RequestTooFrequently
        - RequestVerifyRequired
        - DangerousOperation
        - InternalError
        - ServiceUnavailable
      x-enumDescriptions:
        OK: 保留值，正常错误响应不会返回。
        InvalidParameter: 必填参数缺失或未通过校验。
        BadRequest: 通用的 400 错误，通常是请求本身不合法。
        InvalidContentType: 请求头 `Content-Type` 不是 `application/json`。
        ResourceNotFound: 目标资源不存在。注意 HTTP 状态码是 400 而非 404（历史设计）。
        NoLicense: 功能需要有效授权，但未找到可用的 license。
        ReferenceExist: 该资源仍被其他实体引用，无法删除。
        Unauthorized: '`app_key` 缺失、无效或已过期。'
        BalanceNotEnough: 账户余额不足，无法执行需要计费的操作。
        AccessDenied: 身份认证通过，但 RBAC 权限不足以执行该操作。
        RouteNotFound: 请求的 URL 路径不是已知路由。
        MethodNotAllowed: 当前路径不接受所使用的 HTTP 方法。
        UndonedOrderExist: 账户存在未完成的订单，请稍后重试。
        RequestLocked: 因连续失败被临时锁定。
        EntityTooLarge: 请求体超过允许的最大长度。
        RequestTooFrequently: 命中限流（全局、账户级或集成级）。
        RequestVerifyRequired: 操作需要二次验证码，但未提供。
        DangerousOperation: 危险操作，需要进行 MFA 验证。
        InternalError: 服务端未预期错误。反馈问题请附上 `request_id`。
        ServiceUnavailable: 后端依赖不可用，请稍后重试。
      example: InvalidParameter
  responses:
    Unauthorized:
      description: app_key 缺失或无效。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingAppKey:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: Unauthorized
                  message: You are unauthorized.
  securitySchemes:
    AppKeyAuth:
      type: apiKey
      in: query
      name: app_key
      description: >-
        在 Flashduty 控制台 账户 → APP Key 中签发的 app_key。调用任何公开 API
        时都必须携带。它等同于所属账户的身份凭证，请妥善保管。

````