查询 RUM 数据
curl --request POST \
--url 'https://api.flashcat.cloud/rum/data/query?app_key=' \
--header 'Content-Type: application/json' \
--data '
{
"end_time": 1712707200000,
"queries": [
{
"format": "table",
"id": "errors_by_type",
"sql": "SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10"
}
],
"start_time": 1712620800000
}
'import requests
url = "https://api.flashcat.cloud/rum/data/query?app_key="
payload = {
"end_time": 1712707200000,
"queries": [
{
"format": "table",
"id": "errors_by_type",
"sql": "SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10"
}
],
"start_time": 1712620800000
}
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({
end_time: 1712707200000,
queries: [
{
format: 'table',
id: 'errors_by_type',
sql: 'SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10'
}
],
start_time: 1712620800000
})
};
fetch('https://api.flashcat.cloud/rum/data/query?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/rum/data/query?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([
'end_time' => 1712707200000,
'queries' => [
[
'format' => 'table',
'id' => 'errors_by_type',
'sql' => 'SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10'
]
],
'start_time' => 1712620800000
]),
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/rum/data/query?app_key="
payload := strings.NewReader("{\n \"end_time\": 1712707200000,\n \"queries\": [\n {\n \"format\": \"table\",\n \"id\": \"errors_by_type\",\n \"sql\": \"SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10\"\n }\n ],\n \"start_time\": 1712620800000\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/rum/data/query?app_key=")
.header("Content-Type", "application/json")
.body("{\n \"end_time\": 1712707200000,\n \"queries\": [\n {\n \"format\": \"table\",\n \"id\": \"errors_by_type\",\n \"sql\": \"SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10\"\n }\n ],\n \"start_time\": 1712620800000\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/rum/data/query?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 \"end_time\": 1712707200000,\n \"queries\": [\n {\n \"format\": \"table\",\n \"id\": \"errors_by_type\",\n \"sql\": \"SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10\"\n }\n ],\n \"start_time\": 1712620800000\n}"
response = http.request(request)
puts response.read_body{
"data": {
"errors_by_type": {
"data": {
"fields": [
{
"name": "error_type",
"nullable": true,
"type": "VARCHAR"
},
{
"name": "errors",
"nullable": false,
"type": "BIGINT"
}
],
"values": [
[
"TypeError",
"ReferenceError"
],
[
1523,
342
]
]
}
}
},
"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": "RequestTooFrequently",
"message": "Request too frequently."
},
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4"
}{
"error": {
"code": "InternalError",
"message": "We encountered an internal error, and it has been reported. Please try again later."
},
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4"
}RUM 数据查询
查询 RUM 数据
在指定时间范围内执行一个或多个 SQL 风格的 RUM 数据查询。
POST
/
rum
/
data
/
query
查询 RUM 数据
curl --request POST \
--url 'https://api.flashcat.cloud/rum/data/query?app_key=' \
--header 'Content-Type: application/json' \
--data '
{
"end_time": 1712707200000,
"queries": [
{
"format": "table",
"id": "errors_by_type",
"sql": "SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10"
}
],
"start_time": 1712620800000
}
'import requests
url = "https://api.flashcat.cloud/rum/data/query?app_key="
payload = {
"end_time": 1712707200000,
"queries": [
{
"format": "table",
"id": "errors_by_type",
"sql": "SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10"
}
],
"start_time": 1712620800000
}
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({
end_time: 1712707200000,
queries: [
{
format: 'table',
id: 'errors_by_type',
sql: 'SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10'
}
],
start_time: 1712620800000
})
};
fetch('https://api.flashcat.cloud/rum/data/query?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/rum/data/query?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([
'end_time' => 1712707200000,
'queries' => [
[
'format' => 'table',
'id' => 'errors_by_type',
'sql' => 'SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10'
]
],
'start_time' => 1712620800000
]),
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/rum/data/query?app_key="
payload := strings.NewReader("{\n \"end_time\": 1712707200000,\n \"queries\": [\n {\n \"format\": \"table\",\n \"id\": \"errors_by_type\",\n \"sql\": \"SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10\"\n }\n ],\n \"start_time\": 1712620800000\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/rum/data/query?app_key=")
.header("Content-Type", "application/json")
.body("{\n \"end_time\": 1712707200000,\n \"queries\": [\n {\n \"format\": \"table\",\n \"id\": \"errors_by_type\",\n \"sql\": \"SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10\"\n }\n ],\n \"start_time\": 1712620800000\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/rum/data/query?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 \"end_time\": 1712707200000,\n \"queries\": [\n {\n \"format\": \"table\",\n \"id\": \"errors_by_type\",\n \"sql\": \"SELECT error_type, count(*) AS errors FROM errors GROUP BY error_type ORDER BY errors DESC LIMIT 10\"\n }\n ],\n \"start_time\": 1712620800000\n}"
response = http.request(request)
puts response.read_body{
"data": {
"errors_by_type": {
"data": {
"fields": [
{
"name": "error_type",
"nullable": true,
"type": "VARCHAR"
},
{
"name": "errors",
"nullable": false,
"type": "BIGINT"
}
],
"values": [
[
"TypeError",
"ReferenceError"
],
[
1523,
342
]
]
}
}
},
"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": "RequestTooFrequently",
"message": "Request too frequently."
},
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4"
}{
"error": {
"code": "InternalError",
"message": "We encountered an internal error, and it has been reported. Please try again later."
},
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4"
}时间范围对齐与缓存
为便于重复查询复用缓存结果,聚合查询的时间范围会被对齐到网格:format=time_series:起始时间向下、结束时间向上取整到interval。时间桶的数量和位置不变,首尾两个桶覆盖完整区间,而不是部分区间。- 聚合(非时序)查询:起始时间向下、结束时间向上取整到
max(1 分钟, 时间范围 ÷ 1226 向上取到下一个标准间隔档),例如 24 小时对齐到 2 分钟,7 天对齐到 10 分钟,30 天对齐到 1 小时。时间范围短于 100 个网格步长时不对齐、不缓存。起始端最多多出一个网格步长的数据;结束端取整到未来,该部分没有数据。 - 明细/列表查询(无聚合、分页),以及 SQL 中含有
now()等随执行时间变化的函数的查询,不做对齐也不缓存。
限制说明
| 项目 | 说明 |
|---|---|
| 速率限制 | 每个账户 1,000 次/分钟;50 次/秒 |
| 权限要求 | 无 —— 持有有效的 app_key 即可调用 |
使用说明
- 单次请求可提交 1 到 10 个查询;每个查询的
id会成为响应对象中的 key。 start_time、end_time为 Unix 毫秒时间戳,跨度不超过 31 天。服务端会自动追加时间范围与账户过滤条件,sql中无需再写。FROM填写 RUM 数据表名:sessions、views、actions、errors、resources、long_tasks、vitals、issues或sourcemaps(也接受单数形式)。列名即POST /rum/field/list返回的field_key。- 若查询在顶层
AND条件中用=或IN限定了application_id,调用者必须能读取这些应用:所属团队不包含调用者的私有应用会让整个请求返回AccessDenied,不存在的应用返回ResourceNotFound,单次请求最多涉及 50 个不同应用。未限定应用的查询会自动跳过调用者无权读取的私有应用。 - SQL 语法错误、
time_zone无效或时间范围不合法时,整个请求返回InvalidParameter。之后阶段才失败的查询(表或列不存在、search_after_ctx无效、数据库报错)只在该查询自己的结果中返回error,错误码为InternalError,其他查询仍正常返回data;dql解析失败同样只影响该查询,错误码为InvalidParameter,报错信息带上该查询原文。 values按列组织:values[i]是列fields[i]在所有行上的取值。table查询最多返回 1,000 行;未写LIMIT或超过 1,000 时按 1,000 处理。不含聚合、带ORDER BY且没有OFFSET的查询在本页取满时会返回search_after_ctx,用相同的sql带上它即可取下一页。time_series查询会在最前面插入ts列(时间桶起点,Unix 毫秒),并按它分组、排序。桶宽以毫秒在interval中返回,取值为固定档位(1、2、5、10、20、50、100、200、500 毫秒;1、2、5、10、15、30 秒;1、2、5、10、15、30 分钟;1、2、3、6、12 小时;1、2、3、7 天;30、60、90、180 天)中同时不小于interval和「时间跨度 ÷max_points」的最小一档。- 时间跨度较大时,聚合查询可能基于抽样数据执行;此时响应带有
sampling,且COUNT、SUM、COUNT(DISTINCT)列已乘以scale_factor。设置disable_sampling: true可始终查询全量数据。
授权
请求体
application/json
此页面对您有帮助吗?