查询结构化数据
curl --request POST \
--url 'https://api.flashcat.cloud/monit/query/data?app_key=' \
--header 'Content-Type: application/json' \
--data '
{
"ds_type": "prometheus",
"ds_name": "prod-prom",
"expr": "sum by (job) (rate(http_requests_total[5m]))",
"delay_seconds": 0,
"args": {}
}
'import requests
url = "https://api.flashcat.cloud/monit/query/data?app_key="
payload = {
"ds_type": "prometheus",
"ds_name": "prod-prom",
"expr": "sum by (job) (rate(http_requests_total[5m]))",
"delay_seconds": 0,
"args": {}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
ds_type: 'prometheus',
ds_name: 'prod-prom',
expr: 'sum by (job) (rate(http_requests_total[5m]))',
delay_seconds: 0,
args: {}
})
};
fetch('https://api.flashcat.cloud/monit/query/data?app_key=', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.flashcat.cloud/monit/query/data?app_key=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'ds_type' => 'prometheus',
'ds_name' => 'prod-prom',
'expr' => 'sum by (job) (rate(http_requests_total[5m]))',
'delay_seconds' => 0,
'args' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.flashcat.cloud/monit/query/data?app_key="
payload := strings.NewReader("{\n \"ds_type\": \"prometheus\",\n \"ds_name\": \"prod-prom\",\n \"expr\": \"sum by (job) (rate(http_requests_total[5m]))\",\n \"delay_seconds\": 0,\n \"args\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.flashcat.cloud/monit/query/data?app_key=")
.header("Content-Type", "application/json")
.body("{\n \"ds_type\": \"prometheus\",\n \"ds_name\": \"prod-prom\",\n \"expr\": \"sum by (job) (rate(http_requests_total[5m]))\",\n \"delay_seconds\": 0,\n \"args\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/monit/query/data?app_key=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"ds_type\": \"prometheus\",\n \"ds_name\": \"prod-prom\",\n \"expr\": \"sum by (job) (rate(http_requests_total[5m]))\",\n \"delay_seconds\": 0,\n \"args\": {}\n}"
response = http.request(request)
puts response.read_body{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"data": {
"format": "query_result.v1",
"result": {
"kind": "samples",
"samples": [
{
"labels": {
"job": "api"
},
"value": 1.25
}
]
}
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InvalidParameter",
"message": "The specified parameter is not valid."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "Unauthorized",
"message": "You are unauthorized."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "AccessDenied",
"message": "Access Denied."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InvalidParameter",
"message": "The specified parameter template_id is not valid.",
"reason": "<string>"
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "RequestTooFrequently",
"message": "Request too frequently."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InvalidParameter",
"message": "The specified parameter template_id is not valid.",
"reason": "<string>"
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InternalError",
"message": "We encountered an internal error, and it has been reported. Please try again later."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "ServiceUnavailable",
"message": "service temporarily unavailable"
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InvalidParameter",
"message": "The specified parameter template_id is not valid.",
"reason": "<string>"
}
}诊断分析
查询结构化数据
对数据源执行同步即席查询,返回 query_result.v1 结果,形态为 frames、records 或 samples。
POST
/
monit
/
query
/
data
查询结构化数据
curl --request POST \
--url 'https://api.flashcat.cloud/monit/query/data?app_key=' \
--header 'Content-Type: application/json' \
--data '
{
"ds_type": "prometheus",
"ds_name": "prod-prom",
"expr": "sum by (job) (rate(http_requests_total[5m]))",
"delay_seconds": 0,
"args": {}
}
'import requests
url = "https://api.flashcat.cloud/monit/query/data?app_key="
payload = {
"ds_type": "prometheus",
"ds_name": "prod-prom",
"expr": "sum by (job) (rate(http_requests_total[5m]))",
"delay_seconds": 0,
"args": {}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
ds_type: 'prometheus',
ds_name: 'prod-prom',
expr: 'sum by (job) (rate(http_requests_total[5m]))',
delay_seconds: 0,
args: {}
})
};
fetch('https://api.flashcat.cloud/monit/query/data?app_key=', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.flashcat.cloud/monit/query/data?app_key=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'ds_type' => 'prometheus',
'ds_name' => 'prod-prom',
'expr' => 'sum by (job) (rate(http_requests_total[5m]))',
'delay_seconds' => 0,
'args' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.flashcat.cloud/monit/query/data?app_key="
payload := strings.NewReader("{\n \"ds_type\": \"prometheus\",\n \"ds_name\": \"prod-prom\",\n \"expr\": \"sum by (job) (rate(http_requests_total[5m]))\",\n \"delay_seconds\": 0,\n \"args\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.flashcat.cloud/monit/query/data?app_key=")
.header("Content-Type", "application/json")
.body("{\n \"ds_type\": \"prometheus\",\n \"ds_name\": \"prod-prom\",\n \"expr\": \"sum by (job) (rate(http_requests_total[5m]))\",\n \"delay_seconds\": 0,\n \"args\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/monit/query/data?app_key=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"ds_type\": \"prometheus\",\n \"ds_name\": \"prod-prom\",\n \"expr\": \"sum by (job) (rate(http_requests_total[5m]))\",\n \"delay_seconds\": 0,\n \"args\": {}\n}"
response = http.request(request)
puts response.read_body{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"data": {
"format": "query_result.v1",
"result": {
"kind": "samples",
"samples": [
{
"labels": {
"job": "api"
},
"value": 1.25
}
]
}
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InvalidParameter",
"message": "The specified parameter is not valid."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "Unauthorized",
"message": "You are unauthorized."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "AccessDenied",
"message": "Access Denied."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InvalidParameter",
"message": "The specified parameter template_id is not valid.",
"reason": "<string>"
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "RequestTooFrequently",
"message": "Request too frequently."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InvalidParameter",
"message": "The specified parameter template_id is not valid.",
"reason": "<string>"
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InternalError",
"message": "We encountered an internal error, and it has been reported. Please try again later."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "ServiceUnavailable",
"message": "service temporarily unavailable"
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InvalidParameter",
"message": "The specified parameter template_id is not valid.",
"reason": "<string>"
}
}调用限制
| 项 | 值 |
|---|---|
| 速率限制 | 每账户 100 次/分钟、5 次/秒 |
| 权限 | 任意有效的 app_key(只读,不受特定权限分类限制) |
| Edge 版本要求 | 受支持的部署要求 monit-edge v0.65.0 或更高版本 |
使用说明
- 数据源由
ds_type加ds_name指定,而不是数据源 ID。数据源必须属于当前账户且已启用。若数据源限制了可查询的团队,只有这些团队的成员、其管理团队以及账户所有者或管理员可以查询,其他人会收到AccessDenied。 - 此公开接口以 monit-edge v0.65.0 为最低受支持版本。迁移期间,WebAPI 仍保留旧版 Edge 适配器:query.v2 结果仍可能保留 frames、records 或 samples,而 legacy rows 只能提供其已保留的信息。这些适配器不会改变最低支持版本;旧协议缺少 query.v3 的取消和错误生命周期语义,legacy rows 已丢失的数据也无法恢复。
- 公开响应格式固定为
query_result.v1,与 Edge 内部查询协议版本无关。必须根据result.kind(frames、records或samples)分发结果,不要根据ds_type或 Edge 版本猜测结果形态。 frames结果可以包含多个表格或时序 Frame。字段值按列组织,同一 Frame 中所有字段的值数量一致。records结果可以包含嵌套 JSON 和 null record。超出 JavaScript 安全整数范围的整数字面量会以十进制字符串返回。samples结果包含标签集合和瞬时值。值可以是数字,也可以是字符串NaN、+Inf或-Inf。- Prometheus 表达式在下发查询前会做语法检查,表达式非法时返回 HTTP 400。
- 请求体上限为 256 KiB,完整成功响应上限为 10 MiB,超限均返回 HTTP 413。结果超过 1,000 行时返回 HTTP 400。请缩短时间范围、减少字段或在数据源侧聚合。
- 查询失败使用非 2xx HTTP 状态码和标准错误 envelope。
- WebAPI 跨实例转发和 Edge 执行合计可能耗时 35 秒。客户端超时建议至少设为 40 秒,并在调用方放弃查询时向下传播取消信号。
授权
请求体
application/json
结构化查询接口的请求体。
数据源类型,需要与 ds_name 一起匹配账户下一个已启用的数据源。
prometheus:Prometheus 兼容数据源,expr为 PromQL。loki:Grafana Loki,expr为 LogQL。victorialogs:VictoriaLogs。sls:阿里云日志服务(SLS)。tencent_cls:腾讯云日志服务(CLS),需要 monit-edge v0.66.0 或更高版本。elasticsearch:Elasticsearch。mysql:MySQL,expr为 SQL。postgres:PostgreSQL,expr为 SQL。oracle:Oracle 数据库,expr为 SQL。clickhouse:ClickHouse,expr为 SQL。
其他数据源类型(例如 MongoDB、Redis、Kafka)会被拒绝。
可用选项:
clickhouse, elasticsearch, loki, mysql, oracle, postgres, prometheus, sls, tencent_cls, victorialogs 额外的查询参数,字符串键值对;键按数据源加前缀(例如 sls.project、loki.type)。最多 128 项,键最长 256 字节,值最长 64 KiB,总计不超过 128 KiB。可接受的参数取决于 ds_type:
prometheus:可选prometheus.time,评估时间,Unix 秒,不能晚于当前时间。loki、victorialogs:<source>.type取stats(默认)或raw。stats可带<source>.time(Unix 秒,不能晚于当前时间)。raw必须给出时间范围,可用<source>.start+<source>.end(Unix 秒),或<source>.timespan.value+<source>.timespan.unit(s、m、h或d),跨度不超过 6 小时,并可带<source>.limit,取值 1 到 1001。sls:必须提供sls.project和sls.logstore。可选sls.lines(1 到 100)、sls.offset(0 或更大),以及不超过 6 小时的时间范围,可用sls.from+sls.to(Unix 秒)或sls.timespan.value+sls.timespan.unit给出。tencent_cls:必须提供tencent_cls.region、tencent_cls.topic_id、tencent_cls.query_mode(raw或analysis)和tencent_cls.syntax(cql或lucene)。可选tencent_cls.limit(1 到 100,仅raw模式,需要 monit-edge v0.67.0 或更高版本),以及时间范围,可用tencent_cls.from+tencent_cls.to(Unix 秒)或tencent_cls.timespan.value+tencent_cls.timespan.unit给出,raw模式不超过 6 小时,analysis模式不超过 24 小时。其他任何键都会被拒绝。elasticsearch:es.type只能为sql或不传,其他值会被拒绝。mysql、postgres、oracle、clickhouse:未定义任何参数。
绝对时间 <source>.time 只对其对应的数据源类型有效。v0.74.0 之前的 Edge 通过回看偏移近似实现,且只接受最近 86,400 秒内的时间。
Show child attributes
Show child attributes
此页面对您有帮助吗?