查询 Prometheus 标签值列表
curl --request GET \
--url 'https://api.flashcat.cloud/monit/prometheus/api/v1/label/{label_name}/values?app_key='import requests
url = "https://api.flashcat.cloud/monit/prometheus/api/v1/label/{label_name}/values?app_key="
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://api.flashcat.cloud/monit/prometheus/api/v1/label/{label_name}/values?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/prometheus/api/v1/label/{label_name}/values?app_key=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$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.flashcat.cloud/monit/prometheus/api/v1/label/{label_name}/values?app_key="
req, _ := http.NewRequest("GET", url, nil)
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.flashcat.cloud/monit/prometheus/api/v1/label/{label_name}/values?app_key=")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/monit/prometheus/api/v1/label/{label_name}/values?app_key=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"status": "success",
"data": [
"api",
"db",
"worker"
]
}<string>{
"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."
}
}<string>告警数据源
查询 Prometheus 标签值列表
通过监控代理从 Prometheus 兼容数据源读取标签值列表。
GET
/
monit
/
prometheus
/
api
/
v1
/
label
/
{label_name}
/
values
查询 Prometheus 标签值列表
curl --request GET \
--url 'https://api.flashcat.cloud/monit/prometheus/api/v1/label/{label_name}/values?app_key='import requests
url = "https://api.flashcat.cloud/monit/prometheus/api/v1/label/{label_name}/values?app_key="
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://api.flashcat.cloud/monit/prometheus/api/v1/label/{label_name}/values?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/prometheus/api/v1/label/{label_name}/values?app_key=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$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.flashcat.cloud/monit/prometheus/api/v1/label/{label_name}/values?app_key="
req, _ := http.NewRequest("GET", url, nil)
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.flashcat.cloud/monit/prometheus/api/v1/label/{label_name}/values?app_key=")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/monit/prometheus/api/v1/label/{label_name}/values?app_key=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"status": "success",
"data": [
"api",
"db",
"worker"
]
}<string>{
"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."
}
}<string>限制说明
| 项目 | 说明 |
|---|---|
| 速率限制 | 每个账户 1,000 次/分钟;50 次/秒 |
| 权限要求 | 任意有效的 app_key(只读,不受特定权限分类限制) |
| Edge 版本要求 | 查询指定数据源要求 monit-edge v0.35.0 或更高版本 |
使用说明
- 通过
X-DSID请求头传入目标数据源 ID。数据源必须属于当前账户且为 Prometheus 类型;可用/monit/datasource/list获取 ID。 - 若数据源限制了可查询的团队,只有这些团队的成员、其管理团队以及账户所有者或管理员可以查询,其他人会收到 403。数据源 ID 不存在时返回 400。
- 200 响应体是数据源原生的 Prometheus HTTP API 结构,不是统一的
{ request_id, data }envelope。查询字符串参数会原样转发,因此 Prometheus 自身的match[]、start、end等参数都可使用。 - 省略
X-DSID,或数据源所在集群中有任意 monit-edge 低于 v0.35.0 时,请求会由平台自有的 Prometheus 响应,而不是您的数据源。请携带该请求头并保持 monit-edge 为较新版本,才能获得数据源自身的取值。 - 到达数据源之前发生的失败以
text/plain返回,并携带对应的 4xx/5xx 状态码。数据源自身返回的 400 及以上状态码会连同其响应体一并透传。
授权
在 Flashduty 控制台 我的 → APP Key 中创建的 APP Key。可通过 query 参数 app_key 或请求头 Fd-App-Key 传入。实际可访问范围是该 APP Key 的权限范围与创建者当前角色权限的交集,请妥善保管。
请求头
要查询的数据源 ID,十进制字符串。必须是当前账户下的 Prometheus 类型数据源。省略时由平台自有的 Prometheus 响应,而不是您的数据源。
路径参数
要枚举取值的标签名,例如 job。
响应
数据源返回的原生 Prometheus 标签值响应。
所查询数据源返回的原生 Prometheus HTTP API 响应。本接口不会把结果包装进 Flashduty 统一响应 envelope。
此页面对您有帮助吗?