此操作用来添加监控配置。
说明
添加监控配置时,默认携带下列label:job、集群ID、集群名称、ServerIP、hostname。用户有权限修改或删除集群ID、集群名称、ServerIP、hostname,但不建议修改和删除。用户添加的自定义label与默认label同名时,则label取值以用户设置的为准。
请求语法
添加Pushgateway监控配置
POST /rest/v1/system/config/monitor?serverId=serverid1,serverid2,serveridN HTTP/1.1
Date: date
Content-Type: application/json; charset=utf-8
Content-Length: length
Host: ip:port
Authorization: authorization
{
"metricDataformat": "pushgateway",
"pushgateway": address:port,
"pushgatewayLabels": {
key1: value1,
key2": value2,
key3: value3,
...
keyN: valueN
}
}添加Prometheus文本格式的监控配置
POST /rest/v1/system/config/monitor?serverId=serverid1,serverid2,serveridN HTTP/1.1
Date: date
Content-Type: application/json; charset=utf-8
Content-Length: length
Host: ip:port
Authorization: authorization
{
"metricDataformat": "prometheusTextBased",
"receiverUrl": receiverUrl,
"method": method,
"authType": authType,
"basicUsername": basicUsername,
"basicPassword": basicPassword,
"bearerToken": bearerToken,
"metricLabels": {
key1: value1,
key2": value2,
key3: value3,
...
keyN: valueN
}
}请求参数
添加Pushgateway监控配值
| 参数 | 类型 | 描述 | 是否必须 |
|---|---|---|---|
| serverId | String | 指定添加监控配置的HBlock服务器ID。一次可以指定多个HBlock服务器的ID,以英文逗号(,)分开。如果不填写,默认为所有HBlock服务器添加监控配置。 | 否 |
| metricDataformat | String | 指定metric的数据格式。 取值:pushgateway:表示添加Pushgateway监控配置。默认值为pushgateway。 | 否 |
| pushgateway | String | 指定Pushgateway的地址和接口。 取值:格式为IPv4:port、[IPv6]:port或者domain-name:port。 | 是 |
| pushgatewayLabels | Object | 指定Pushgateway对应的标签值。 取值:格式为"key":"value"。 | 否 |
添加Prometheus文本格式的监控配置
| 参数 | 类型 | 描述 | 是否必须 |
|---|---|---|---|
| serverId | String | 指定添加监控配置的HBlock服务器ID。一次可以指定多个HBlock服务器的ID,以英文逗号(,)分开。如果不填写,默认为所有HBlock服务器添加监控配置。 | 否 |
| metricDataformat | String | 指定metric的数据格式。 取值:prometheusTextBased:表示添加Prometheus文本格式的监控配置。 | 是 |
receiverUrl | String | 指定监控数据推送地址URL,格式为:http://hostname:port/uri。 | 是 |
| method | String | 指定推送监控数据的请求方法。 取值:
默认值为POST。 | 否 |
| authType | String | 指定认证鉴权类型。 取值:
默认值为None。 | 否 |
| basicUsername | String | 鉴权类型为Basic时,basic的用户名。 取值:字符串,不能包含冒号(:)、空格。 说明 鉴权类型为Basic时,必填。 | 条件 |
| basicPassword | String | 鉴权类型为Basic时,basic的密码。 取值:字符串,不能包含空格。 说明 鉴权类型为Basic时,必填。 | 条件 |
bearerToken | String | 鉴权类型为Bearer时,Bearer的token。 取值:字符串,不能包含空格。 说明 鉴权类型为Bearer时,必填。 | 条件 |
| metricLabels | Object | 指定监控数据推送地址对应的标签值,格式为KEY:VALUE。一次可以添加多个标签值,以英文逗号(,)分开,最多可以添加64个标签值。 其中:
| 否 |
请求示例1
为服务器hblock_2、hblock_3添加Pushgateway监控配置。
POST /rest/v1/system/config/monitor?serverId=hblock_3,hblock_2 HTTP/1.1
Date: Fri, 24 May 2024 02:24:01 GMT
Content-Type: application/json; charset=utf-8
Authorization: HBlock userName:signature
Content-Length: 138
Host: 192.168.0.110:1443
{
"pushgateway": "192.168.0.1:9091",
"pushgatewayLabels": {
"agent": "agentname",
"idc": "idcname"
}
}响应示例1
HTTP/1.1 200 OK
x-hblock-request-id: 65ba83698f7742de82c2a26fcd57e6e1
Connection: keep-alive
Content-Length: 0
Date: Fri, 24 May 2024 02:24:01 GMT
Server: HBlock请求示例2
为所有服务器添加Pushgateway监控配置。
POST /rest/v1/system/config/monitor HTTP/1.1
Date: Fri, 24 May 2024 02:43:57 GMT
Content-Type: application/json; charset=utf-8
Authorization: HBlock userName:signature
Content-Length: 130
Host: 192.168.0.110:1443
{
"pushgateway": "192.168.0.1:9091",
"pushgatewayLabels": {
"agent":"ctyun",
"idc": "idc8"
}
}响应示例2
HTTP/1.1 200 OK
x-hblock-request-id: 9949f15915b24eada38615013e93ea53
Connection: keep-alive
Content-Length: 0
Date: Fri, 24 May 2024 02:43:57 GMT
Server: HBlock请求示例3
添加数据格式为prometheusTextBased监控配置。
POST /rest/v1/system/config/monitor HTTP/1.1
Date: Fri, 12 Jun 2026 02:26:21 GMT
Content-Type: application/json; charset=utf-8
Authorization: HBlock userName:signature
Content-Length: 298
Host: 192.168.0.65:1443
{
"metricDataformat": "prometheusTextBased",
"receiverUrl": "http://192.168.0.1:9093/metrics",
"method": "PUT",
"authType": "Basic",
"basicUsername": "user1",
"basicPassword": "pwd1",
"metricLabels": {
"agent": "ctyun",
"idc": "idc1"
}
}响应示例3
HTTP/1.1 200 OK
x-hblock-request-id: d069172a8b184db69d4c178ee1f4a908
Connection: keep-alive
Content-Length: 0
Date: Fri, 12 Jun 2026 02:26:21 GMT
Server: HBlock