# Message size added as Attribute

**URL:** <https://discuss.elastic.co/t/message-size-added-as-attribute/89922>\
**Category:** Logstash\
**Created:** [June 19, 2017, 12:01pm UTC](https://discuss.elastic.co/t/message-size-added-as-attribute/89922 "2017-06-19T12:01:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![raisinpit](https://avatars.discourse-cdn.com/v4/letter/r/0ea827/32.png) [@raisinpit](https://discuss.elastic.co/u/raisinpit)\
**Post date:** [June 19, 2017, 12:01pm UTC](https://discuss.elastic.co/t/message-size-added-as-attribute/89922/1 "2017-06-19T12:01:05Z")

</div>

Hi,

I want to add the size in Bytes of a message to as an attribute of that message, is this possible? I have seen a some try this before with the ruby plugin, but I have been unable to get this to work.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![paz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paz/32/28003_2.png) [@paz](https://discuss.elastic.co/u/paz)\
**Post date:** [June 19, 2017, 12:10pm UTC](https://discuss.elastic.co/t/message-size-added-as-attribute/89922/2 "2017-06-19T12:10:53Z")

</div>

Try this one

```auto
filter {
    ruby {
        code => "event.set('message_size', event.get('message').bytesize)"
    }
}
```

---

<div class="post-metadata">

**Author:** ![raisinpit](https://avatars.discourse-cdn.com/v4/letter/r/0ea827/32.png) [@raisinpit](https://discuss.elastic.co/u/raisinpit)\
**Post date:** [June 19, 2017, 12:20pm UTC](https://discuss.elastic.co/t/message-size-added-as-attribute/89922/3 "2017-06-19T12:20:52Z")

</div>

Thanks a ton, I was working with length and I couldn't get it to work. This works perfectly.

---

<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:** [July 17, 2017, 12:20pm UTC](https://discuss.elastic.co/t/message-size-added-as-attribute/89922/4 "2017-07-17T12:20:53Z")

</div>

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