|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * monitoring/configuring-the-monitoring-stack.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="setting-the-body-size-limit-for-metrics-scraping_{context}"] |
| 7 | += Setting the body size limit for metrics scraping |
| 8 | + |
| 9 | +By default, no limit exists for the uncompressed body size for data returned from scraped metrics targets. |
| 10 | +You can set a body size limit to help avoid situations in which Prometheus consumes excessive amounts of memory when scraped targets return a response that contains a large amount of data. |
| 11 | +In addition, by setting a body size limit, you can reduce the impact that a malicious target might have on Prometheus and on the cluster as a whole. |
| 12 | + |
| 13 | +After you set a value for `enforcedBodySizeLimit`, the alert `PrometheusScrapeBodySizeLimitHit` fires when at least one Prometheus scrape target replies with a response body larger than the configured value. |
| 14 | + |
| 15 | +[NOTE] |
| 16 | +==== |
| 17 | +If metrics data scraped from a target has an uncompressed body size exceeding the configured size limit, the scrape fails. |
| 18 | +Prometheus then considers this target to be down and sets its `up` metric value to `0`, which can trigger the `TargetDown` alert. |
| 19 | +==== |
| 20 | + |
| 21 | +.Prerequisites |
| 22 | + |
| 23 | +* You have access to the cluster as a user with the `cluster-admin` role. |
| 24 | +* You have installed the OpenShift CLI (`oc`). |
| 25 | +
|
| 26 | +.Procedure |
| 27 | + |
| 28 | +. Edit the `cluster-monitoring-config` `ConfigMap` object in the `openshift-monitoring` namespace: |
| 29 | ++ |
| 30 | +[source,terminal] |
| 31 | +---- |
| 32 | +$ oc -n openshift-monitoring edit configmap cluster-monitoring-config |
| 33 | +---- |
| 34 | + |
| 35 | +. Add a value for `enforcedBodySizeLimit` to `data/config.yaml/prometheusK8s` to limit the body size that can be accepted per target scrape: |
| 36 | ++ |
| 37 | +[source,yaml] |
| 38 | +---- |
| 39 | +apiVersion: v1 |
| 40 | +kind: ConfigMap |
| 41 | +metadata: |
| 42 | + name: cluster-monitoring-config |
| 43 | + namespace: openshift-monitoring |
| 44 | +data: |
| 45 | + config.yaml: |- |
| 46 | + prometheusK8s: |
| 47 | + enforcedBodySizeLimit: 40MB <1> |
| 48 | +---- |
| 49 | +<1> Specify the maximum body size for scraped metrics targets. |
| 50 | +This `enforcedBodySizeLimit` example limits the uncompressed size per target scrape to 40 megabytes. |
| 51 | +Valid numeric values use the Prometheus data size format: B (bytes), KB (kilobytes), MB (megabytes), GB (gigabytes), TB (terabytes), PB (petabytes), and EB (exabytes). |
| 52 | +The default value is `0`, which specifies no limit. |
| 53 | +You can also set the value to `automatic` to calculate the limit automatically based on cluster capacity. |
| 54 | + |
| 55 | +. Save the file to apply the changes automatically. |
| 56 | ++ |
| 57 | +[WARNING] |
| 58 | +==== |
| 59 | +When you save changes to a `cluster-monitoring-config` config map, the pods and other resources in the `openshift-monitoring` project might be redeployed. |
| 60 | +The running monitoring processes in that project might also restart. |
| 61 | +==== |
0 commit comments