创建数据源
curl --request POST \
--url 'https://api.flashcat.cloud/monit/datasource/create?app_key=' \
--header 'Content-Type: application/json' \
--data '
{
"type_ident": "prometheus",
"name": "Prometheus Prod",
"note": "Production Prometheus",
"address": "http://prometheus.example.com:9090",
"edge_cluster_name": "default",
"payload": {
"prometheus": {
"basic_auth_enabled": false
}
}
}
'import requests
url = "https://api.flashcat.cloud/monit/datasource/create?app_key="
payload = {
"type_ident": "prometheus",
"name": "Prometheus Prod",
"note": "Production Prometheus",
"address": "http://prometheus.example.com:9090",
"edge_cluster_name": "default",
"payload": { "prometheus": { "basic_auth_enabled": False } }
}
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({
type_ident: 'prometheus',
name: 'Prometheus Prod',
note: 'Production Prometheus',
address: 'http://prometheus.example.com:9090',
edge_cluster_name: 'default',
payload: {prometheus: {basic_auth_enabled: false}}
})
};
fetch('https://api.flashcat.cloud/monit/datasource/create?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/datasource/create?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([
'type_ident' => 'prometheus',
'name' => 'Prometheus Prod',
'note' => 'Production Prometheus',
'address' => 'http://prometheus.example.com:9090',
'edge_cluster_name' => 'default',
'payload' => [
'prometheus' => [
'basic_auth_enabled' => false
]
]
]),
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/datasource/create?app_key="
payload := strings.NewReader("{\n \"type_ident\": \"prometheus\",\n \"name\": \"Prometheus Prod\",\n \"note\": \"Production Prometheus\",\n \"address\": \"http://prometheus.example.com:9090\",\n \"edge_cluster_name\": \"default\",\n \"payload\": {\n \"prometheus\": {\n \"basic_auth_enabled\": false\n }\n }\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/datasource/create?app_key=")
.header("Content-Type", "application/json")
.body("{\n \"type_ident\": \"prometheus\",\n \"name\": \"Prometheus Prod\",\n \"note\": \"Production Prometheus\",\n \"address\": \"http://prometheus.example.com:9090\",\n \"edge_cluster_name\": \"default\",\n \"payload\": {\n \"prometheus\": {\n \"basic_auth_enabled\": false\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/monit/datasource/create?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 \"type_ident\": \"prometheus\",\n \"name\": \"Prometheus Prod\",\n \"note\": \"Production Prometheus\",\n \"address\": \"http://prometheus.example.com:9090\",\n \"edge_cluster_name\": \"default\",\n \"payload\": {\n \"prometheus\": {\n \"basic_auth_enabled\": false\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"data": {
"id": 10,
"account_id": 10023,
"type_ident": "prometheus",
"name": "Prometheus Prod",
"enabled": true,
"note": "Production Prometheus",
"address": "http://prometheus.example.com:9090",
"payload": {
"prometheus": {
"basic_auth_enabled": false,
"basic_auth_username": "",
"basic_auth_password": "",
"tls_skip_verify": false
}
},
"edge_cluster_name": "default",
"updated_at": 1712000000,
"alerting_enabled": true,
"manage_team_id": null,
"readonly_team_ids": null,
"creator_id": 20001
}
}{
"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."
}
}告警数据源
创建数据源
创建一个监控数据源(支持 15 种类型),并将其绑定到某个 Monitors edge 集群。
POST
/
monit
/
datasource
/
create
创建数据源
curl --request POST \
--url 'https://api.flashcat.cloud/monit/datasource/create?app_key=' \
--header 'Content-Type: application/json' \
--data '
{
"type_ident": "prometheus",
"name": "Prometheus Prod",
"note": "Production Prometheus",
"address": "http://prometheus.example.com:9090",
"edge_cluster_name": "default",
"payload": {
"prometheus": {
"basic_auth_enabled": false
}
}
}
'import requests
url = "https://api.flashcat.cloud/monit/datasource/create?app_key="
payload = {
"type_ident": "prometheus",
"name": "Prometheus Prod",
"note": "Production Prometheus",
"address": "http://prometheus.example.com:9090",
"edge_cluster_name": "default",
"payload": { "prometheus": { "basic_auth_enabled": False } }
}
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({
type_ident: 'prometheus',
name: 'Prometheus Prod',
note: 'Production Prometheus',
address: 'http://prometheus.example.com:9090',
edge_cluster_name: 'default',
payload: {prometheus: {basic_auth_enabled: false}}
})
};
fetch('https://api.flashcat.cloud/monit/datasource/create?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/datasource/create?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([
'type_ident' => 'prometheus',
'name' => 'Prometheus Prod',
'note' => 'Production Prometheus',
'address' => 'http://prometheus.example.com:9090',
'edge_cluster_name' => 'default',
'payload' => [
'prometheus' => [
'basic_auth_enabled' => false
]
]
]),
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/datasource/create?app_key="
payload := strings.NewReader("{\n \"type_ident\": \"prometheus\",\n \"name\": \"Prometheus Prod\",\n \"note\": \"Production Prometheus\",\n \"address\": \"http://prometheus.example.com:9090\",\n \"edge_cluster_name\": \"default\",\n \"payload\": {\n \"prometheus\": {\n \"basic_auth_enabled\": false\n }\n }\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/datasource/create?app_key=")
.header("Content-Type", "application/json")
.body("{\n \"type_ident\": \"prometheus\",\n \"name\": \"Prometheus Prod\",\n \"note\": \"Production Prometheus\",\n \"address\": \"http://prometheus.example.com:9090\",\n \"edge_cluster_name\": \"default\",\n \"payload\": {\n \"prometheus\": {\n \"basic_auth_enabled\": false\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/monit/datasource/create?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 \"type_ident\": \"prometheus\",\n \"name\": \"Prometheus Prod\",\n \"note\": \"Production Prometheus\",\n \"address\": \"http://prometheus.example.com:9090\",\n \"edge_cluster_name\": \"default\",\n \"payload\": {\n \"prometheus\": {\n \"basic_auth_enabled\": false\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"data": {
"id": 10,
"account_id": 10023,
"type_ident": "prometheus",
"name": "Prometheus Prod",
"enabled": true,
"note": "Production Prometheus",
"address": "http://prometheus.example.com:9090",
"payload": {
"prometheus": {
"basic_auth_enabled": false,
"basic_auth_username": "",
"basic_auth_password": "",
"tls_skip_verify": false
}
},
"edge_cluster_name": "default",
"updated_at": 1712000000,
"alerting_enabled": true,
"manage_team_id": null,
"readonly_team_ids": null,
"creator_id": 20001
}
}{
"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."
}
}限制说明
| 项目 | 说明 |
|---|---|
| 速率限制 | 每个账户 300 次/分钟;20 次/秒 |
| 权限要求 | 数据源管理(monit) |
使用说明
type_ident必须为以下之一:prometheus,loki,mysql,oracle,postgres,clickhouse,elasticsearch,sls,tencent_cls,victorialogs,redis_node,redis_sentinel,mongodb_mongod,mongodb_mongos,kafka。后五种(redis_node、redis_sentinel、mongodb_mongod、mongodb_mongos、kafka)仅用于诊断,不能评估告警,因此alerting_enabled不能为true。name在账户内唯一(不区分类型),重名时返回InvalidParameter。edge_cluster_name必须是账户下已存在的 Monitors edge 集群;该集群负责评估规则并执行该数据源的查询。- 类型专属配置放在
payload.<type_ident>中。elasticsearch必须设置payload.elasticsearch.deployment(cloud或self-managed)。tencent_cls要求集群内所有 edge 实例均为 Monitors edge v0.66.0 或更高版本。 - 省略
enabled时默认为true;省略alerting_enabled时,告警类默认true,仅诊断类默认false。两者显式传null都会被拒绝。 manage_team_id和readonly_team_ids用于限制谁能管理或查询该数据源;两者都省略则对所有成员开放。- 响应会原样返回非诊断类型的凭据(例如 Prometheus 的 Basic Auth 密码);诊断类型的密码和 Kafka 私钥仅在它们是
${env:NAME}引用时才返回。请将响应视为敏感信息。 - 每次调用都会记录到账户审计日志。
授权
请求体
application/json
创建或更新数据源的请求体。id 仅更新时必填,创建时忽略。更新会用请求中的值整体替换 type_ident、name、note、address、payload 和 edge_cluster_name,因此必须全部重新发送;仅 enabled、alerting_enabled、manage_team_id、readonly_team_ids 在省略时保持原值。除 deployment=cloud 的 Elasticsearch 外,address 对所有类型必填。
数据源类型。
告警类(可用于告警规则评估):
prometheus:兼容 Prometheus 的指标数据源。loki:Grafana Loki 日志。mysql:MySQL。oracle:Oracle 数据库。postgres:PostgreSQL。clickhouse:ClickHouse。elasticsearch:Elasticsearch。sls:阿里云日志服务(SLS)。tencent_cls:腾讯云日志服务(CLS)。victorialogs:VictoriaLogs。
仅诊断类(不能用于告警评估,alerting_enabled 恒为 false):
redis_node:单个 Redis 节点。redis_sentinel:Redis Sentinel。mongodb_mongod:MongoDB mongod 实例。mongodb_mongos:MongoDB mongos 路由。kafka:Kafka 集群。
存放类型专属配置的 payload 键与类型同名。
可用选项:
prometheus, loki, mysql, oracle, postgres, clickhouse, elasticsearch, sls, tencent_cls, victorialogs, redis_node, redis_sentinel, mongodb_mongod, mongodb_mongos, kafka 连接地址;除 deployment: cloud 的 elasticsearch 外,所有类型都必填。规范化后最长 4096 个字符。各类型格式:
prometheus、loki、victorialogs:HTTP URL;不以http开头时自动补http://。mysql、oracle、postgres:host:port。clickhouse:一个或多个以逗号分隔的host:port,重复地址会被拒绝。self-managed的elasticsearch:一个或多个以逗号分隔的 HTTP(S) URL(缺省协议为http://),各 URL 的查询参数必须一致,重复地址会被拒绝;cloud部署无需填写。sls:不带http://或https://前缀的 endpoint。tencent_cls:只能是cls.tencentcloudapi.com或cls.internal.tencentcloudapi.com(要求 Monitors edge >= v0.66.0)。redis_node、redis_sentinel、mongodb_mongod、mongodb_mongos:单个host:port(IPv6 须加方括号),不能含 URI、用户信息或查询串。kafka:1-32 个互不重复、以逗号分隔的host:port引导地址(payload 中没有 broker 列表)。
Maximum string length:
4096此页面对您有帮助吗?