# JMX plugin, grok, add\_field and type

**URL:** https://discuss.elastic.co/t/jmx-plugin-grok-add-field-and-type/161672
**Category:** Logstash
**Created:** [December 20, 2018, 10:57am UTC](https://discuss.elastic.co/t/jmx-plugin-grok-add-field-and-type/161672 "2018-12-20T10:57:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ncasaux](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ncasaux/32/46950_2.png) [@ncasaux](https://discuss.elastic.co/u/ncasaux)
#### Post date: [December 20, 2018, 10:57am UTC](https://discuss.elastic.co/t/jmx-plugin-grok-add-field-and-type/161672/1 "2018-12-20T10:57:53Z")

</div>

Hello,

I managed to set-up a successfull pipeline with Logstash and the jmx plugin.

```
filter {
  grok {
    match => { "metric_path" => "(?<alias>[^\.]*)\.(?<jmx_path>.*)\.(?<jmx_attribute>[^\.]*)" }
  }
}

```

With this, I have some fields in Elasticsearch :

```
  "_source": {
    "metric_path": "localhost_9010.org.apache.activemq:type=Broker,brokerName=8d9f096158ae.MemoryPercentUsage",
    "host": "localhost",
    "metric_value_number": 17,
    "type": "jmx",
    "jmx_path": "org.apache.activemq:type=Broker,brokerName=8d9f096158ae",
    "jmx_attribute": "MemoryPercentUsage",
    "@version": "1",
    "@timestamp": "2018-12-20T10:29:07.498Z",
    "path": "/usr/share/logstash/jmx",
    "alias": "localhost_9010"
  }

```

What I would like to achieve now is to have a field named `MemoryPercentUsage`.  
So I added the `add_field`:

```
filter {
  grok {
    match => { "metric_path" => "(?<alias>[^\.]*)\.(?<jmx_path>.*)\.(?<jmx_attribute>[^\.]*)" }
    add_field => {
      "%{jmx_attribute}" => "%{metric_value_number}"
    }
  }
}

```

My issue is that the type of the field is not correct. The default field `metric_value_number` field is identified as an number, but not my added field `MemoryPercentUsage`

![image](https://us1.discourse-cdn.com/elastic/original/3X/9/2/92700ddb547d182c72ed6ffb449fe7338543f1dd.png)

Is there something I'm doing wrong ?

Thanks in advance for your feedback 🙂

---

<div class="post-metadata">

### Author: ![ncasaux](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ncasaux/32/46950_2.png) [@ncasaux](https://discuss.elastic.co/u/ncasaux)
#### Post date: [December 21, 2018, 6:26pm UTC](https://discuss.elastic.co/t/jmx-plugin-grok-add-field-and-type/161672/2 "2018-12-21T18:26:42Z")

</div>

managed to do it this way:

```
filter {
  grok {
    match => { "metric_path" => "(?<alias>[^\.]*)\.(?<jmx_path>.*)\.(?<jmx_attribute>[^\.]*)" }
    add_field => {
      "%{jmx_attribute}" => "%{metric_value_number}"
    }
  }
}

filter {
  mutate {
    convert => {
      "QueueSize" => "integer"
      "ConsumerCount" => "integer"
      "StoreMessageSize" => "integer"
      "MemoryUsageByteCount" => "integer"
      "StorePercentUsage" => "integer"
      "MemoryPercentUsage" => "integer"
      
    }
  }
}
```

---

<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: [January 18, 2019, 6:26pm UTC](https://discuss.elastic.co/t/jmx-plugin-grok-add-field-and-type/161672/3 "2019-01-18T18:26:43Z")

</div>

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