Skip to content

Modify



POST /api/v1/aggs_to_metric/{rule_uuid}/modify

Overview

Modify a Generate Metrics rule.

Route Parameters

Parameter Name Type Required Description
rule_uuid string Y ID of the Generate Metrics aggregation 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 information
Allow empty: False
jsonScript.metricInfo json Y Metric configuration information
Allow empty: False
jsonScript.metricInfo.every string Y Frequency; supports an integer with a unit. Allowed values: 1m~59m or 1h~24h. Cron is 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 Data wait window, in seconds. Allowed values: 0, 60, 120, 180, 300, 600, 900, 1200, 1800. Default 0 means no delay.
Example: 60
Allowed values: [0, 60, 120, 180, 300, 600, 900, 1200, 1800]
skipRepeatNameCheck boolean Whether to skip the duplicate-name check for the measurement and metric. Default: false. false performs the duplicate-name check; true skips it.
Example: false
Allow empty: False

Additional Parameter Notes

Data notes.

1. Parameter description for jsonScript

Parameter Type Required Description
type String Required Data source type, enum type
query Json Required Query information
metricInfo Json Required Measurement configuration information

2. Description of jsonScript.type values

key Description
rumToMetric Generate Metrics from RUM
apmToMetric Generate Metrics from APM
logToMetric Generate Metrics from Logging
metricToMetric Generate Metrics from Metric
securityToMetric Generate Metrics from Security Check

3. Description of jsonScript.metricInfo

Parameter Type Required Description
every String Required Frequency; supports an integer with a unit. Allowed values: 1m~59m or 1h~24h. Cron is not supported.
metric String Required Measurement name
metricField String Required Metric name
unit String Unit
desc String Description
delaySeconds Integer Data wait window, in seconds. Allowed values: 0, 60, 120, 180, 300, 600, 900, 1200, 1800. Default 0 means no delay.

3.1 Unit description for jsonScript.metricInfo.unit

Unit format: custom/["unit type","unit"], example: custom/["time","ms"]
Custom unit format: custom/["custom","custom unit"], example: custom/["custom","tt"]
For standard unit types, see Unit Description


4. Description of jsonScript.query

Parameter Type Required Description
q String Required Query statement
qtype String Query syntax type: dql/promql
qmode String Query type. Selector mode: selectorQuery; manual entry: customQuery. This field affects the display style of the query in the front end.

5. Parameter description for extend

Parameter Type Required Description
filters Array[dict] List of filter conditions for non-log types
groupBy Array[str] Grouping information
funcName string Required Aggregation function. Enum values: ("count", "avg", "max", "sum", "min", "count_distinct", "distribution", "p75", "p95", "p99")
fieldKey string Required Aggregation field
index string Index name for log types
source string This field has different meanings for different types: log type: source; APM type: service; RUM type: application (app_id); metric type: measurement; Security Check: category
filterString string Filter condition for log types, raw filter string. Example: 'host:hangzhou123 -service:coredns internal:true'

Note: All fields in extend are used only for front-end display. The actual Generate Metrics query is based on the query information configured in jsonScript.query. When Distribution is used in selector mode, pass distribution as extend.funcName, and use histogram_auto(<field>) for jsonScript.query.q.


6. Description of the extend.filters structure

Parameter Type Required Description
condition string Relationship to the previous filter condition. Allowed values: and, or. Default: and.
name string Field name to filter
op string Operator. Allowed values: =, !=, match, not match
values array List of values
values[#] string/int/boolean Can be a string, numeric, or boolean value. When comparing data, a specific element is taken from values according to the characteristics of operation. For example, when operation is =, only values[0] is used in the comparison.

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"
        }
      }
    }

Example Request

curl 'https://openapi.guance.com/api/v1/aggs_to_metric/rul_xxxx/modify' \
-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"
} 

Feedback

Is this page helpful?