> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flashduty.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 执行探索查询

> 对已配置的数据源执行探索查询，返回 frames、samples 或 logs 形态的结果。

## 限制说明

| 项目        | 说明                                    |
| --------- | ------------------------------------- |
| 速率限制      | 每个账户 **100 次/分钟**；**16 次/秒**          |
| 权限要求      | **数据源查看**（`monit`）                    |
| Edge 版本要求 | 受支持的部署要求 **monit-edge v0.68.0 或更高版本** |

## 使用说明

* 需要数据源原生结果形态时使用本接口；`/monit/query/data` 返回稳定的 `query_result.v1` 契约。本接口根据 `data.result.kind`（`frames`、`samples` 或 `logs`）分发结果。
* `execution.kind` 决定可接受的配套字段：`instant` 只需 `to_ms`，`range` 需要 `from_ms`、`to_ms` 和 `max_data_points`，`window` 需要 `from_ms` 和 `to_ms`。不接受 `step_seconds`，步长由 `max_data_points` 与 `min_step_seconds` 推导。
* `args` 用于宏替换（例如 Grafana 风格变量），取值均为字符串。
* `logs` 结果最多返回 1,000 条，并通过 `applied_limit` 与 `has_more` 说明截断情况。时序与采样结果各最多 1,000 条，成功响应整体上限 8 MiB。
* WebAPI 跨实例转发与 Edge 执行合计可能耗时 35 秒，客户端超时建议至少 40 秒。


## OpenAPI

````yaml /api-reference/monitors.openapi.zh.json post /monit/query/explore
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/query/explore:
    post:
      tags:
        - Monitors/诊断分析
      summary: 执行探索查询
      description: 对已配置的数据源执行探索查询，返回 frames、samples 或 logs 形态的结果。
      operationId: monit-read-query-explore
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/QueryExploreRequest'
            example:
              datasource_id: 101
              expr: rate(http_requests_total[5m])
              args: {}
              execution:
                kind: range
                from_ms: 1787187600000
                to_ms: 1787191200000
                max_data_points: 1200
                min_step_seconds: 15
      responses:
        '200':
          description: 成功
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/SuccessEnvelope'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/ExploreData'
              example:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                data:
                  format: explore_result.v1
                  result:
                    kind: frames
                    frames:
                      - kind: time_series
                        fields:
                          - name: time
                            type: time
                            values:
                              - '2026-08-20T10:00:00Z'
                              - '2026-08-20T10:01:00Z'
                          - name: value
                            type: float
                            labels:
                              job: api
                            values:
                              - 1.25
                              - null
                  execution:
                    kind: range
                    effective_step_seconds: 60
        '400':
          description: 标准 HTTP 错误；error.reason：invalid_request。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          description: 标准 HTTP 错误；error.reason：access_denied。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: 标准 HTTP 错误；error.reason：datasource_not_found。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '413':
          description: 标准 HTTP 错误；error.reason：source_too_large、result_too_large。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: 标准 HTTP 错误；error.reason：overloaded。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '499':
          description: 标准 HTTP 错误；error.reason：canceled。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: 标准 HTTP 错误；error.reason：internal。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: >-
            标准 HTTP
            错误；error.reason：no_active_edge、edge_upgrade_required、mixed_edge_versions、edge_unavailable。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '504':
          description: 标准 HTTP 错误；error.reason：timeout。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    QueryExploreRequest:
      type: object
      description: 探索查询请求。四个顶层字段均为必填，未知字段会被拒绝。
      required:
        - datasource_id
        - expr
        - args
        - execution
      properties:
        datasource_id:
          type: integer
          format: int64
          minimum: 1
          maximum: 9007199254740991
          description: >-
            数据源 ID，来自 `/monit/datasource/list`。必须是正数且不超过 JavaScript
            安全整数范围，且属于当前账户。
        expr:
          type: string
          minLength: 1
          description: >-
            使用数据源原生语言的查询表达式（如 PromQL、LogsQL、SQL 等）。非空 UTF-8 字符串，最长 64
            KiB；部分数据源类型限制更小。
        args:
          type: object
          additionalProperties:
            type: string
          maxProperties: 128
          description: 宏替换参数，按变量名索引，用于 Grafana 风格变量。键最长 256 字节，值最长 64 KiB，总预算 128 KiB。
        execution:
          $ref: '#/components/schemas/QueryExploreExecution'
    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
    ExploreData:
      type: object
      description: 探索查询结果载荷。
      required:
        - format
        - result
      properties:
        format:
          type: string
          enum:
            - explore_result.v1
          description: 结果契约版本，固定为 `explore_result.v1`。
        result:
          $ref: '#/components/schemas/ExploreResult'
        execution:
          $ref: '#/components/schemas/ExploreResponseExecution'
    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
    QueryExploreExecution:
      type: object
      description: >-
        查询的时间语义。可接受的配套字段取决于 `kind`：`instant` 只需 `to_ms`（`from_ms` 可选），`range` 需要
        `from_ms`、`to_ms` 和 `max_data_points`，`window` 需要 `from_ms` 和
        `to_ms`。HTTP 接口不接受 `step_seconds`。
      required:
        - kind
      properties:
        kind:
          type: string
          enum:
            - instant
            - range
            - window
          description: 执行类型。`instant` 在单个时间点取值，`range` 在时间范围内取序列，`window` 返回时间窗口内的原始行。
        from_ms:
          type: integer
          format: int64
          description: 范围起点的 Unix 毫秒时间戳。`range` 和 `window` 必填，`instant` 可选。
        to_ms:
          type: integer
          format: int64
          description: 范围终点的 Unix 毫秒时间戳。所有执行类型均必填。
        max_data_points:
          type: integer
          format: int64
          minimum: 2
          maximum: 5000
          description: 返回的数据点数量上限。`range` 必填，`instant` 与 `window` 不接受该字段。
        min_step_seconds:
          type: integer
          format: int64
          minimum: 1
          description: 由 `max_data_points` 推导出的步长下限（秒）。可选，仅在 `range` 下接受。
    ExploreResult:
      type: object
      description: 结果主体。`frames`、`samples`、`entries` 三者中只有与 `kind` 匹配的一个会出现。
      required:
        - kind
      properties:
        kind:
          type: string
          enum:
            - frames
            - samples
            - logs
          description: 结果形态。`frames` 返回列式表格或时序，`samples` 返回带标签的瞬时值，`logs` 返回日志条目。
        frames:
          type: array
          items:
            $ref: '#/components/schemas/ExploreFrame'
          description: 列式 Frame 列表，`kind` 为 `frames` 时出现，最多 1,000 个。
        samples:
          type: array
          items:
            $ref: '#/components/schemas/ExploreSample'
          description: 瞬时采样列表，`kind` 为 `samples` 时出现，最多 1,000 条。
        entries:
          type: array
          items:
            $ref: '#/components/schemas/ExploreLogEntry'
          description: 日志条目列表，`kind` 为 `logs` 时出现，长度不超过 `applied_limit`。
        applied_limit:
          type: integer
          description: 日志结果实际生效的条数上限，最大 1000。
        has_more:
          type: boolean
          description: 日志结果是否因 `applied_limit` 被截断。
    ExploreResponseExecution:
      type: object
      description: 实际使用的执行信息，数据源返回带步长结果时出现。
      required:
        - kind
        - effective_step_seconds
      properties:
        kind:
          type: string
          enum:
            - range
          description: 执行类型；该对象出现时固定为 `range`。
        effective_step_seconds:
          type: integer
          format: int64
          description: 应用 `max_data_points` 与 `min_step_seconds` 后实际执行的步长（秒）。
    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
    ExploreFrame:
      type: object
      description: 单个列式 Frame，Frame 内所有字段的取值数量一致。
      required:
        - kind
        - fields
      properties:
        kind:
          type: string
          enum:
            - table
            - time_series
          description: Frame 形态。`table` 为无标签表格，`time_series` 恰好包含一个时间字段和一个 float 字段。
        fields:
          type: array
          items:
            $ref: '#/components/schemas/ExploreField'
          description: Frame 的列。
    ExploreSample:
      type: object
      description: 单个瞬时采样。
      required:
        - labels
        - value
      properties:
        labels:
          type: object
          additionalProperties:
            type: string
          description: 采样的标签集合。可以为空，但不能为 null。
        value:
          description: 采样值：数字，或字符串 `NaN`、`+Inf`、`-Inf`。不能为 null。
    ExploreLogEntry:
      type: object
      description: 单条日志。
      required:
        - timestamp_ns
        - fields
      properties:
        timestamp_ns:
          type: string
          description: 条目时间，使用 Unix 纪元纳秒的规范无符号十进制字符串表示，最长 20 位。
        fields:
          type: object
          additionalProperties: true
          description: 日志字段的原始 JSON 取值。超出 JavaScript 安全整数范围的整数字面量会以十进制字符串返回。
    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
    ExploreField:
      type: object
      description: Frame 的一列。取值按列组织，可以包含 null。
      required:
        - name
        - type
        - values
      properties:
        name:
          type: string
          description: 列名，最长 1 MiB 的 UTF-8 字符串。
        type:
          type: string
          enum:
            - string
            - float
            - time
          description: >-
            列类型。`time_series` 内不接受 `string`；`float` 存放数值，`time` 取值为 UTC
            RFC3339Nano 字符串。
        labels:
          type: object
          additionalProperties:
            type: string
          description: 该列的标签集合。仅 `time_series` 的取值字段可以携带标签，`table` 字段不允许。
        values:
          type: array
          items:
            description: >-
              单个单元格。`time` 为 UTC RFC3339Nano 字符串，`float` 可以是字符串
              `NaN`、`+Inf`、`-Inf`，除 `time_series` 中的时间值外均可以为 null。
          description: 按行顺序排列的列取值。
  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
        时都必须携带。它等同于所属账户的身份凭证，请妥善保管。

````