github.com/GuanceCloud/cliutils@v1.1.21/pipeline/ptinput/funcs/md/agg_metric.en.md (about)

     1  ### `agg_metric()` {#fn-agg-metric}
     2  
     3  [:octicons-tag-24: Version-1.5.10](../datakit/changelog.md#cl-1.5.10)
     4  
     5  Function prototype: `fn agg_metric(bucket: str, new_field: str, agg_fn: str, agg_by: []string, agg_field: str, category: str = "M")`
     6  
     7  Function description: According to the field name in the input data, the value is automatically taken as the label of the aggregated data, and the aggregated data is stored in the corresponding bucket. This function does not work with central Pipeline.
     8  
     9  Function parameters:
    10  
    11  - `bucket`: String type, the bucket created by the agg_create function, if the bucket has not been created, the function will not perform any operations.
    12  - `new_field`: The name of the field in the aggregated data, the data type of its value is `float`.
    13  - `agg_fn`: Aggregation function, can be one of `"avg"`, `"sum"`, `"min"`, `"max"`, `"set"`.
    14  - `agg_by`: The name of the field in the input data will be used as the tag of the aggregated data, and the value of these fields can only be string type data.
    15  - `agg_field`: The field name in the input data, automatically obtain the field value for aggregation.
    16  - `category`: Data category for aggregated data, optional parameter, the default value is "M", indicating the indicator category data.
    17  
    18  Example:
    19  
    20  Take `logging` category data as an example:
    21  
    22  Multiple inputs in a row:
    23  
    24  - Sample log one: `{"a": 1}`
    25  - Sample log two: `{"a": 2}`
    26  
    27  script:
    28  
    29  ```python
    30  agg_create("cpu_agg_info", on_interval="10s", const_tags={"tag1":"value_user_define_tag"})
    31  
    32  set_tag("tag1", "value1")
    33  
    34  field1 = load_json(_)
    35  
    36  field1 = field1["a"]
    37  
    38  agg_metric("cpu_agg_info", "agg_field_1", "sum", ["tag1", "host"], "field1")
    39  ```
    40  
    41  metric output:
    42  
    43  ```json
    44  {
    45      "host": "your_hostname",
    46      "tag1": "value1",
    47      "agg_field_1": 3
    48  }
    49  ```