# Autodiscovery setting in Metricbeat

**URL:** <https://discuss.elastic.co/t/autodiscovery-setting-in-metricbeat/273732>\
**Category:** Elastic Cloud on Kubernetes (ECK)\
**Created:** [May 22, 2021, 5:10pm UTC](https://discuss.elastic.co/t/autodiscovery-setting-in-metricbeat/273732 "2021-05-22T17:10:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkaramol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pkaramol/32/22610_2.png) [@pkaramol](https://discuss.elastic.co/u/pkaramol)\
**Post date:** [May 22, 2021, 5:10pm UTC](https://discuss.elastic.co/t/autodiscovery-setting-in-metricbeat/273732/1 "2021-05-22T17:10:15Z")

</div>

I was going through this [nice](https://youtu.be/_aJ1BdaG2n8?t=1665) and comprehensive presentation by @pebrc

At the point in time where the link points to, the presenter makes a configuration change to the `Elasticsearch` resource definition so that the label `scrape: es` is added, given that there is a corresponding `spec.config.metricbeat.autodiscover.providers[0].templates[0].condition` in the `Beat` resource.

However I don't see such an entry [here](https://raw.githubusercontent.com/elastic/cloud-on-k8s/1.5/config/recipes/beats/metricbeat_hosts.yaml).

Do I have to manually add it or is everything by default scraped in `7.12.0` since perhaps there were changes introduced since `7.10.0` and operator `1.2` (versions of the presentation).

I am using ECK `1.5` and ES `7.12.0`.

---

<div class="post-metadata">

**Author:** ![pebrc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pebrc/32/101790_2.png) [@pebrc](https://discuss.elastic.co/u/pebrc)\
**Post date:** [May 22, 2021, 5:24pm UTC](https://discuss.elastic.co/t/autodiscovery-setting-in-metricbeat/273732/2 "2021-05-22T17:24:00Z")

</div>

This [example](https://github.com/elastic/cloud-on-k8s/blob/master/config/recipes/beats/stack_monitoring.yaml) is very close to what was presented in the video you linked. You still need to add the labels in order to set up the Elastic Stack specific monitoring modules.

You can however scrape generic metrics without adding additional metadata and conditions as is shown in the example you linked to.

---

<div class="post-metadata">

**Author:** ![pkaramol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pkaramol/32/22610_2.png) [@pkaramol](https://discuss.elastic.co/u/pkaramol)\
**Post date:** [May 22, 2021, 5:26pm UTC](https://discuss.elastic.co/t/autodiscovery-setting-in-metricbeat/273732/3 "2021-05-22T17:26:12Z")

</div>

Thank you. So to get this straight, if I **don't** add this to the `Beat` definition

```auto
            templates:
              - condition:
                  contains:
                    kubernetes.labels.scrape: es

```

everything or nothing will be scraped?

(i.e. in case **no condition at all** is present in `Beat`)

---

<div class="post-metadata">

**Author:** ![Thibault\_Richard](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thibault_richard/32/50513_2.png) [@Thibault\_Richard](https://discuss.elastic.co/u/Thibault_Richard)\
**Post date:** [June 1, 2021, 4:34pm UTC](https://discuss.elastic.co/t/autodiscovery-setting-in-metricbeat/273732/4 "2021-06-01T16:34:49Z")

</div>

Without condition, every pods will be scraped. I don't know what do you want to achieve but no condition is often a conceptual mistake. It might have some sense with the [`unique`](https://www.elastic.co/guide/en/beats/metricbeat/current/configuration-autodiscover.html) flag that autodiscover now offers, but not otherwise.

---

<div class="post-metadata">

**Author:** ![eedugon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eedugon/32/45404_2.png) [@eedugon](https://discuss.elastic.co/u/eedugon)\
**Post date:** [June 1, 2021, 8:16pm UTC](https://discuss.elastic.co/t/autodiscovery-setting-in-metricbeat/273732/5 "2021-06-01T20:16:46Z")

</div>

@pkaramol , let me add something else to the previous comments by Peter and Thibault.

What you showed [here](https://raw.githubusercontent.com/elastic/cloud-on-k8s/1.5/config/recipes/beats/metricbeat_hosts.yaml) is a proposal for a Metricbeat `DaemonSet` in charge of doing monitoring of each kubernetes host (with an extra `autodiscover` section with `hints enabled` that in my view should only be added if it's really wanted ([1])).

What Peter showed is an example of a Metricbeat `Deployment` configured to perform monitoring of Elasticsearch pods. In order to scrape specific pods with the specified module the condition is needed, as otherwise you might end up scraping all kubernetes pods even if they are not elasticsearch pods (hence the module `elasticsearch` configured in the input would fail).

I would strongly recommend to take a deep look at all the manifest and `docs` I share at [this repo](https://github.com/eedugon/eck-logs-and-metrics), as I try to explain and add comments to both of the examples showed here (among other use cases).

- Documented example of a similar manifest for Elasticsearch and Kibana monitoring [here](https://github.com/eedugon/eck-logs-and-metrics/blob/main/docs/es_monitoring_simple.md)

- Documented example for Kubernetes hosts monitoring [here](https://github.com/eedugon/eck-logs-and-metrics/blob/main/docs/default_metrics_kubernetes.md) (in this example I explain what I mentioned above [1]).

It's important to understand every possibility of autodiscover and its implications, because thank to the flexibility it offers we might end up in unwanted configuration or duplicating our metrics retrieval without need.

For example, taking a look at both examples, you could build a single DaemonSet to perform everything (Kubernetes monitoring at host level + scraping elasticsearch pods based on some conditions), but again, the config should be different because Autodiscover when running in a `DaemonSet` makes sense at `node level` and Autodiscover when running in a `Deployment` usually makes sense at `cluster` level.

I hope this helps a bit, take a look also at the official [autodiscover docs](https://www.elastic.co/guide/en/beats/metricbeat/current/configuration-autodiscover.html), because there are a lot of ways to achieve the same.

---

<div class="post-metadata">

**Author:** ![pkaramol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pkaramol/32/22610_2.png) [@pkaramol](https://discuss.elastic.co/u/pkaramol)\
**Post date:** [June 2, 2021, 7:54am UTC](https://discuss.elastic.co/t/autodiscovery-setting-in-metricbeat/273732/6 "2021-06-02T07:54:27Z")

</div>

many thanks for this elaborate answer @eedugon

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 30, 2021, 7:55am UTC](https://discuss.elastic.co/t/autodiscovery-setting-in-metricbeat/273732/7 "2021-06-30T07:55:18Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
