获取应用指标
获取应用的 CPU、RAM 和网络历史(GET /v2/apps/:app_id/metrics):过去 24 小时每 5 或 10 分钟一个数据点,Pro 和 Enterprise 套餐可获取 7 天、每小时一个数据点。
GET
/
v2
/
apps
/
{app_id}
/
metrics
获取应用指标
curl --request GET \
--url https://api.squarecloud.app/v2/apps/{app_id}/metrics \
--header 'Authorization: <authorization>'import requests
url = "https://api.squarecloud.app/v2/apps/{app_id}/metrics"
headers = {"Authorization": "<authorization>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: '<authorization>'}};
fetch('https://api.squarecloud.app/v2/apps/{app_id}/metrics', 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.squarecloud.app/v2/apps/{app_id}/metrics",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.squarecloud.app/v2/apps/{app_id}/metrics"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "<authorization>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.squarecloud.app/v2/apps/{app_id}/metrics")
.header("Authorization", "<authorization>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.squarecloud.app/v2/apps/{app_id}/metrics")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<authorization>'
response = http.request(request)
puts response.read_body{
"status": "success",
"response": [
{
"date": "2025-08-13T12:55:01.348Z",
"cpu": 0.45,
"ram": 111.27,
"net": [
16834,
126
]
},
{
"date": "2025-08-13T12:50:01.349Z",
"cpu": 0.45,
"ram": 111.22,
"net": [
16834,
126
]
},
{
"date": "2025-08-13T12:45:01.350Z",
"cpu": 0.58,
"ram": 111.36,
"net": [
16834,
126
]
},
{
"date": "2025-08-13T12:40:01.348Z",
"cpu": 0.43,
"ram": 118.44,
"net": [
16834,
126
]
}
]
}
需要具有
apps:read 权限范围的 API 密钥。
此端点返回的是历史资源使用情况,而非当前快照:最多包含最近 24 小时内的 288 个数据点,每 5 分钟采样一次,涵盖 CPU、RAM 和网络。RAM 少于 512 MB 的应用每 10 分钟采样一次(最多 144 个数据点)。在 Pro 和 Enterprise 套餐中,对于 RAM 为 512 MB 及以上的应用,range=7d 会改为返回最近 7 天,每小时一个数据点,包含该小时的平均值和峰值。数据点按最新优先排列。可用它来渲染使用量图表或观察长期趋势;若需要应用当前的实时数据,请改用获取应用状态,或使用实时日志中的 status 事件。
结果按(所有者、应用)缓存 2.5 分钟(7d 为 10 分钟),该端点的速率限制为每个用户每 5 秒 10 次请求,超出该上限后会被短暂封锁。
参数
string
必填
应用的 ID。你可以在应用控制面板的 URL 中找到它。
string
默认值:"24h"
历史时间窗口:
24h(每 5 分钟一个数据点,RAM 低于 512 MB 时每 10 分钟一个)或 7d(每小时一个数据点,Pro 和 Enterprise 套餐,且应用 RAM 为 512 MB 及以上)。其他情况下,7d 会返回最近 24 小时,而不是报错。响应
string
指示调用是否成功。成功时为
success,否则为 error。array
{
"status": "success",
"response": [
{
"date": "2025-08-13T12:55:01.348Z",
"cpu": 0.45,
"ram": 111.27,
"net": [
16834,
126
]
},
{
"date": "2025-08-13T12:50:01.349Z",
"cpu": 0.45,
"ram": 111.22,
"net": [
16834,
126
]
},
{
"date": "2025-08-13T12:45:01.350Z",
"cpu": 0.58,
"ram": 111.36,
"net": [
16834,
126
]
},
{
"date": "2025-08-13T12:40:01.348Z",
"cpu": 0.43,
"ram": 118.44,
"net": [
16834,
126
]
}
]
}
常见错误
| 代码 | HTTP | 说明 |
|---|---|---|
INVALID_PARAMETERS | 400 | range 不是 24h 或 7d。 |
相关内容
- CLI:
squarecloud app metrics - SDK:
api.apps.metrics()(JavaScript)、client.apps.metrics()(Python)、c.Apps.Metrics()(Go)
⌘I
获取应用指标
curl --request GET \
--url https://api.squarecloud.app/v2/apps/{app_id}/metrics \
--header 'Authorization: <authorization>'import requests
url = "https://api.squarecloud.app/v2/apps/{app_id}/metrics"
headers = {"Authorization": "<authorization>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: '<authorization>'}};
fetch('https://api.squarecloud.app/v2/apps/{app_id}/metrics', 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.squarecloud.app/v2/apps/{app_id}/metrics",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.squarecloud.app/v2/apps/{app_id}/metrics"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "<authorization>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.squarecloud.app/v2/apps/{app_id}/metrics")
.header("Authorization", "<authorization>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.squarecloud.app/v2/apps/{app_id}/metrics")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<authorization>'
response = http.request(request)
puts response.read_body{
"status": "success",
"response": [
{
"date": "2025-08-13T12:55:01.348Z",
"cpu": 0.45,
"ram": 111.27,
"net": [
16834,
126
]
},
{
"date": "2025-08-13T12:50:01.349Z",
"cpu": 0.45,
"ram": 111.22,
"net": [
16834,
126
]
},
{
"date": "2025-08-13T12:45:01.350Z",
"cpu": 0.58,
"ram": 111.36,
"net": [
16834,
126
]
},
{
"date": "2025-08-13T12:40:01.348Z",
"cpu": 0.43,
"ram": 118.44,
"net": [
16834,
126
]
}
]
}

