Create¶
POST /api/v1/aggs_to_metric/add
Overview¶
Create a new metric generation rule.
Body Request Parameters¶
| Parameter Name | Type | Required | Description |
|---|---|---|---|
| extend | json | Y | Additional information Allow empty: False |
| jsonScript | json | Y | Rule configuration Allow empty: False |
| jsonScript.type | string | Y | Type Example: rumToMetric Allow empty: False Allow empty string: False Allowed values: ['logToMetric', 'rumToMetric', 'apmToMetric', 'metricToMetric', 'securityToMetric', 'dialingToMetric'] |
| jsonScript.query | json | Y | DQL query related information Allow empty: False |
| jsonScript.metricInfo | json | Y | Metric configuration information Allow empty: False |
| jsonScript.metricInfo.every | string | Y | Frequency, supports integers with units; optional 1m~59m or 1h~24h, cron not supported Example: 5m Allow empty string: False |
| jsonScript.metricInfo.metric | string | Y | Measurement name Example: cpu Allow empty string: False |
| jsonScript.metricInfo.metricField | string | Y | Metric name Example: load5s Allow empty string: False |
| jsonScript.metricInfo.unit | string | Unit Example: load5s Allow empty string: True |
|
| jsonScript.metricInfo.desc | string | Description Example: xxx Allow empty string: True |
|
| jsonScript.metricInfo.delaySeconds | integer | Delay seconds after the scheduled task triggers, default 0 means no delay Example: 60 $minValue: 0 $maxValue: 86400 |
|
| skipRepeatNameCheck | boolean | Whether to skip duplicate name detection for measurement and metric, default false, false performs duplicate detection, true skips duplicate detection Example: false Allow empty: False |
Parameter Supplementary Description¶
Request parameter description.
1. **Parameter description in jsonScript
| Parameter Name | type | Required | Description |
|---|---|---|---|
| type | String | Required | Data source type, enumeration type |
| query | Json | Required | Query information |
| metricInfo | Json | Required | Measurement configuration information |
2. Description of check type jsonScript.type
| key | Description |
|---|---|
| rumToMetric | RUM to metric |
| apmToMetric | APM to metric |
| logToMetric | Logging to metric |
| metricToMetric | Metric to metric |
| securityToMetric | Security Check to metric |
3. Description of check type jsonScript.metricInfo
| Parameter Name | type | Required | Description |
|---|---|---|---|
| every | String | Required | Frequency, supports integers with units; optional 1m~59m or 1h~24h, cron not supported |
| metric | String | Required | Measurement name |
| metricField | String | Required | Metric name |
| unit | String | Unit | |
| desc | String | Description | |
| delaySeconds | Integer | Delay seconds after the scheduled task triggers, default 0 means no delay |
3.1 Description of unit jsonScript.metricInfo.unit
Unit format: custom/["unit type","unit"] , example: custom/["time","ms"]
Custom unit format: custom/["custom","custom unit"], example: custom/["custom","tt"]
Standard unit types, refer to Unit Description
4. Description of check type jsonScript.query
| Parameter Name | type | Required | Description |
|---|---|---|---|
| q | String | Required | Query statement |
| qtype | String | Query syntax type, dql/promql | |
| qmode | String | Query type, dropdown: selectorQuery , manual: customQuery, this field affects the frontend query display style |
5. **Parameter description in extend
| Parameter Name | type | Required | Description |
|---|---|---|---|
| filters | Array[dict] | Filter condition list for non-log types | |
| groupBy | Array[str] | Grouping information | |
| funcName | string | Required | Aggregation function (required when qmode is dropdown mode, for frontend display), enum values("count", "avg", "max", "sum", "min", "count_distinct", "p75", "p95", "p99") |
| fieldKey | string | Required | Aggregation field (required when qmode is dropdown mode, for frontend display) |
| index | string | Index name for log type | |
| source | string | This field represents different meanings for different types: log type: source, APM type: service, RUM type: app_id, metric type: measurement, Security Check: category | |
| filterString | string | Filter condition for log type, original filter string, example: 'host:hangzhou123 -service:coredns internal:true' |
Note:
All fields in the extend field are only used for frontend display. The actual metric generation query statement is based on the query information configured in jsonScript.query.
6. Main structure description of extend.filters
| Parameter Name | type | Required | Description |
|---|---|---|---|
| condition | string | Relationship with the previous filter condition, optional values:and, or; default: and |
|
| name | string | Field name to filter | |
| op | string | Operator, optional values: =, !=, match, not match |
|
| values | array | Value list | |
| values[#] | string/int/boolean | Can be string/numeric/boolean type. When comparing data, specific elements from values will be taken based on the characteristics of operation. For example, when operation is =, only values[0] participates in the operation. |
6.1 Example of extend.filters:
[
{
"name": "A",
"condition": "and",
"op": "match",
"values": ["error"]
},
{
"name": "tagC",
"condition": "and",
"op": "=",
"values": ["ok"]
}
]
7. **Overall structure example:
{
"extend": {
"filters": [],
"groupBy": ["host_ip"],
"funcName": "count",
"fieldKey": "*",
"index": "default",
"source": "*",
"filterString": "host:hangzhou123 region:guanzhou"
},
"jsonScript": {
"type": "logToMetric",
"metricInfo": {
"every": "1m",
"metric": "test",
"metricField": "001-test",
"unit": "custom/[\"timeStamp\",\"ms\"]",
"desc": "",
"delaySeconds": 60
},
"query": {
"q": "L('default')::RE(`.*`):(count(`*`)) { `host`='hangzhou123' and `region`='guanzhou' } BY `host_ip`",
"qtype": "dql"
}
}
}
Request Example¶
curl 'https://openapi.guance.com/api/v1/aggs_to_metric/add' \
-H 'DF-API-KEY: <DF-API-KEY>' \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-raw '{"extend":{"filters":[],"groupBy":["host_ip"],"funcName":"count","fieldKey":"*","index":"default","source":"*","filterString":"host:hangzhou123 region:guanzhou"},"jsonScript":{"type":"logToMetric","metricInfo":{"every":"1m","metric":"test","metricField":"001-test","unit":"custom/[\"timeStamp\",\"ms\"]","desc":"","delaySeconds":60},"query":{"q":"L('default')::RE(`.*`):(count(`*`)) { `host`='hangzhou123' and `region`='guanzhou' } BY `host_ip`","qtype":"dql"}}}' \
--compressed
Response¶
{
"code": 200,
"content": {
"workspaceUUID": "wksp_xxxx",
"monitorUUID": "",
"updator": null,
"type": "aggs",
"refKey": "",
"secret": null,
"jsonScript": {
"type": "logToMetric",
"metricInfo": {
"every": "1m",
"metric": "test",
"metricField": "001-test",
"unit": "custom/[\"timeStamp\",\"ms\"]",
"desc": "",
"delaySeconds": 60
},
"query": {
"q": "L('default')::RE(`.*`):(count(`*`)) { `host`='hangzhou123' and `region`='guanzhou' } BY `host_ip`",
"qtype": "dql"
}
},
"crontabInfo": {
"id": "cron-4VdviPep3oHc",
"crontab": null
},
"extend": {
"filters": [],
"groupBy": [
"host_ip"
],
"funcName": "count",
"fieldKey": "*",
"index": "default",
"source": "*",
"filterString": "host:hangzhou123 region:guanzhou"
},
"createdWay": "manual",
"isLocked": false,
"openPermissionSet": false,
"permissionSet": [],
"id": null,
"uuid": "rul_xxxx",
"status": 0,
"creator": "acnt_xxxx",
"createAt": 1734594428,
"deleteAt": -1,
"updateAt": null,
"__operation_info": {
"uuid": "rul_xxxx"
}
},
"errorCode": "",
"message": "",
"success": true,
"traceId": "1111139030457458757"
}