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。此公开接口要求 monit-edge v0.65.0 或更高版本。
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>"
}
}授权
在 Flashduty 控制台 账户 → APP Key 中签发的 app_key。调用任何公开 API 时都必须携带。它等同于所属账户的身份凭证,请妥善保管。
请求体
稳定结构化查询接口的请求。字段与已下线的 rows 接口一致。
数据源类型;必须匹配租户下已配置的数据源。示例:prometheus、loki、victorialogs、sls、elasticsearch、mysql、postgres、oracle、clickhouse。
数据源名称;必须匹配租户下已配置的数据源。
查询表达式。语法取决于 ds_type,由对应的 monit-edge 客户端解释(Prometheus 用 PromQL,Loki 用 LogQL,SQL 类数据源用 SQL,等等)。
可选的一致性校验。若提供,必须等于已认证账户;不一致将被拒绝。业务执行始终使用已认证账户。
应用于点查询(Prometheus、Loki stats、VictoriaLogs stats)的回看偏移,单位秒。明细 / raw 查询忽略该字段。
透传给 monit-edge 的多态键值扩展参数。所有值必须是字符串,键一律按数据源加前缀(如 sls.project、loki.type)。校验规则取决于 ds_type:SLS 必须提供 sls.project 与 sls.logstore;Elasticsearch 的 es.type 只接受 sql 或不传,其他值一律拒绝;Loki 与 VictoriaLogs 的 <source>.type 接受 stats、raw 或不传,其中 raw 还必须给出时间范围——<source>.start + <source>.end,或 <source>.timespan.value + <source>.timespan.unit(单位取 s/m/h/d)。Prometheus 及其余 SQL 类数据源完全忽略 args。
Show child attributes
Show child attributes
此页面对您有帮助吗?