# Inject extra fields into metricbeat stats

**URL:** https://discuss.elastic.co/t/inject-extra-fields-into-metricbeat-stats/93917
**Category:** Beats
**Created:** [July 20, 2017, 10:49am UTC](https://discuss.elastic.co/t/inject-extra-fields-into-metricbeat-stats/93917 "2017-07-20T10:49:36Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ld\_pvl](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@ld\_pvl](https://discuss.elastic.co/u/ld_pvl)
#### Post date: [July 20, 2017, 10:49am UTC](https://discuss.elastic.co/t/inject-extra-fields-into-metricbeat-stats/93917/1 "2017-07-20T10:49:36Z")

</div>

Hi Elastic Team,

I've been reading about creating a beat and creating metricsets for metricbeat but would like your advise on creating extra fields.

What I would like to do is to add one extra field such as datacenter\_name but in all available metricsets in the metric module system - would I have to download the metricbeat source code and amend each individual metricsets?

Cheers,

---

<div class="post-metadata">

### Author: ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)
#### Post date: [July 20, 2017, 2:49pm UTC](https://discuss.elastic.co/t/inject-extra-fields-into-metricbeat-stats/93917/2 "2017-07-20T14:49:30Z")

</div>

You can add this data to all events generated by using [fields](https://www.elastic.co/guide/en/beats/metricbeat/current/configuration-general.html#_fields_under_root).

```auto
fields_under_root: true
fields:
  datacenter_name: mydc

```

If you are deploying in a cloud environment you could use our [add\_cloud\_metadata processor](https://www.elastic.co/guide/en/beats/metricbeat/master/add-cloud-metadata.html) to automatically determine this info and add it.

```auto
processors:
- add_cloud_metadata: ~

```

For example on AWS this would add this type of info to each event:

```auto
{
  "meta": {
    "cloud": {
      "availability_zone": "us-east-1c",
      "instance_id": "i-4e123456",
      "machine_type": "t2.medium",
      "provider": "ec2",
      "region": "us-east-1"
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![ld\_pvl](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@ld\_pvl](https://discuss.elastic.co/u/ld_pvl)
#### Post date: [July 20, 2017, 3:36pm UTC](https://discuss.elastic.co/t/inject-extra-fields-into-metricbeat-stats/93917/3 "2017-07-20T15:36:55Z")

</div>

We're not deploying in a cloud environment unfortunately.

Is there a way to do this programmatically/dynamically? I have a way to extract the data center name based on the host where metricbeat is installed/running and I want to inject that dynamic value into an extra field into all the metricsets - using fields it looks like requires hard coding in metricbeat.yml if I'm not wrong.

---

<div class="post-metadata">

### Author: ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)
#### Post date: [July 20, 2017, 3:40pm UTC](https://discuss.elastic.co/t/inject-extra-fields-into-metricbeat-stats/93917/4 "2017-07-20T15:40:28Z")

</div>

The only way I can think of would be to inject the data into the process's environment then reference the environment var from the config. [https://www.elastic.co/guide/en/beats/metricbeat/5.5/using-environ-vars.html](https://www.elastic.co/guide/en/beats/metricbeat/5.5/using-environ-vars.html)

---

<div class="post-metadata">

### Author: ![ld\_pvl](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@ld\_pvl](https://discuss.elastic.co/u/ld_pvl)
#### Post date: [July 21, 2017, 9:21am UTC](https://discuss.elastic.co/t/inject-extra-fields-into-metricbeat-stats/93917/5 "2017-07-21T09:21:59Z")

</div>

That sounds like it could be a simple solution - I'll report back with my findings.

---

<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: [August 10, 2017, 10:49am UTC](https://discuss.elastic.co/t/inject-extra-fields-into-metricbeat-stats/93917/6 "2017-08-10T10:49:53Z")

</div>

This topic was automatically closed after 21 days. New replies are no longer allowed.
