github.com/Jeffail/benthos/v3@v3.65.0/website/docs/components/processors/metric.md (about)

     1  ---
     2  title: metric
     3  type: processor
     4  status: stable
     5  categories: ["Utility"]
     6  ---
     7  
     8  <!--
     9       THIS FILE IS AUTOGENERATED!
    10  
    11       To make changes please edit the contents of:
    12       lib/processor/metric.go
    13  -->
    14  
    15  import Tabs from '@theme/Tabs';
    16  import TabItem from '@theme/TabItem';
    17  
    18  Emit custom metrics by extracting values from messages.
    19  
    20  
    21  <Tabs defaultValue="common" values={[
    22    { label: 'Common', value: 'common', },
    23    { label: 'Advanced', value: 'advanced', },
    24  ]}>
    25  
    26  <TabItem value="common">
    27  
    28  ```yaml
    29  # Common config fields, showing default values
    30  label: ""
    31  metric:
    32    type: counter
    33    name: ""
    34    labels: {}
    35    value: ""
    36  ```
    37  
    38  </TabItem>
    39  <TabItem value="advanced">
    40  
    41  ```yaml
    42  # All config fields, showing default values
    43  label: ""
    44  metric:
    45    type: counter
    46    name: ""
    47    labels: {}
    48    value: ""
    49    parts: []
    50  ```
    51  
    52  </TabItem>
    53  </Tabs>
    54  
    55  This processor works by evaluating an [interpolated field `value`](/docs/configuration/interpolation#bloblang-queries) for each message and updating a emitted metric according to the [type](#types).
    56  
    57  Custom metrics such as these are emitted along with Benthos internal metrics, where you can customize where metrics are sent, which metric names are emitted and rename them as/when appropriate. For more information check out the [metrics docs here](/docs/components/metrics/about).
    58  
    59  ## Examples
    60  
    61  <Tabs defaultValue="Counter" values={[
    62  { label: 'Counter', value: 'Counter', },
    63  { label: 'Gauge', value: 'Gauge', },
    64  ]}>
    65  
    66  <TabItem value="Counter">
    67  
    68  In this example we emit a counter metric called `Foos`, which increments for every message processed, and we label the metric with some metadata about where the message came from and a field from the document that states what type it is. We also configure our metrics to emit to CloudWatch, and explicitly only allow our custom metric and some internal Benthos metrics to emit.
    69  
    70  ```yaml
    71  pipeline:
    72    processors:
    73      - metric:
    74          name: Foos
    75          type: counter
    76          labels:
    77            topic: ${! meta("kafka_topic") }
    78            partition: ${! meta("kafka_partition") }
    79            type: ${! json("document.type").or("unknown") }
    80  
    81  metrics:
    82    aws_cloudwatch:
    83      namespace: ProdConsumer
    84      region: eu-west-1
    85      path_mapping: |
    86        root = if ![
    87          "Foos",
    88          "input.received",
    89          "output.sent"
    90        ].contains(this) { deleted() }
    91  ```
    92  
    93  </TabItem>
    94  <TabItem value="Gauge">
    95  
    96  In this example we emit a gauge metric called `FooSize`, which is given a value extracted from JSON messages at the path `foo.size`. We then also configure our Prometheus metric exporter to only emit this custom metric and nothing else. We also label the metric with some metadata.
    97  
    98  ```yaml
    99  pipeline:
   100    processors:
   101      - metric:
   102          name: FooSize
   103          type: gauge
   104          labels:
   105            topic: ${! meta("kafka_topic") }
   106          value: ${! json("foo.size") }
   107  
   108  metrics:
   109    prometheus:
   110      path_mapping: 'if this != "FooSize" { deleted() }'
   111  ```
   112  
   113  </TabItem>
   114  </Tabs>
   115  
   116  ## Fields
   117  
   118  ### `type`
   119  
   120  The metric [type](#types) to create.
   121  
   122  
   123  Type: `string`  
   124  Default: `"counter"`  
   125  Options: `counter`, `counter_by`, `gauge`, `timing`.
   126  
   127  ### `name`
   128  
   129  The name of the metric to create, this must be unique across all Benthos components otherwise it will overwrite those other metrics.
   130  
   131  
   132  Type: `string`  
   133  Default: `""`  
   134  
   135  ### `labels`
   136  
   137  A map of label names and values that can be used to enrich metrics. Labels are not supported by some metric destinations, in which case the metrics series are combined.
   138  This field supports [interpolation functions](/docs/configuration/interpolation#bloblang-queries).
   139  
   140  
   141  Type: `object`  
   142  Default: `{}`  
   143  
   144  ```yaml
   145  # Examples
   146  
   147  labels:
   148    topic: ${! meta("kafka_topic") }
   149    type: ${! json("doc.type") }
   150  ```
   151  
   152  ### `value`
   153  
   154  For some metric types specifies a value to set, increment.
   155  This field supports [interpolation functions](/docs/configuration/interpolation#bloblang-queries).
   156  
   157  
   158  Type: `string`  
   159  Default: `""`  
   160  
   161  ### `parts`
   162  
   163  An optional array of message indexes of a batch that the processor should apply to.
   164  If left empty all messages are processed. This field is only applicable when
   165  batching messages [at the input level](/docs/configuration/batching).
   166  
   167  Indexes can be negative, and if so the part will be selected from the end
   168  counting backwards starting from -1.
   169  
   170  
   171  Type: `array`  
   172  Default: `[]`  
   173  
   174  ## Types
   175  
   176  ### `counter`
   177  
   178  Increments a counter by exactly 1, the contents of `value` are ignored
   179  by this type.
   180  
   181  ### `counter_by`
   182  
   183  If the contents of `value` can be parsed as a positive integer value
   184  then the counter is incremented by this value.
   185  
   186  For example, the following configuration will increment the value of the
   187  `count.custom.field` metric by the contents of `field.some.value`:
   188  
   189  ```yaml
   190  pipeline:
   191    processors:
   192      - metric:
   193          type: counter_by
   194          name: CountCustomField
   195          value: ${!json("field.some.value")}
   196  ```
   197  
   198  ### `gauge`
   199  
   200  If the contents of `value` can be parsed as a positive integer value
   201  then the gauge is set to this value.
   202  
   203  For example, the following configuration will set the value of the
   204  `gauge.custom.field` metric to the contents of `field.some.value`:
   205  
   206  ```yaml
   207  pipeline:
   208    processors:
   209      - metric:
   210          type: gauge
   211          path: GaugeCustomField
   212          value: ${!json("field.some.value")}
   213  ```
   214  
   215  ### `timing`
   216  
   217  Equivalent to `gauge` where instead the metric is a timing.
   218