# Logstash Event Size

**URL:** <https://discuss.elastic.co/t/logstash-event-size/269972>\
**Category:** Logstash\
**Created:** [April 13, 2021, 7:43am UTC](https://discuss.elastic.co/t/logstash-event-size/269972 "2021-04-13T07:43:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dawiro](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@dawiro](https://discuss.elastic.co/u/dawiro)\
**Post date:** [April 13, 2021, 7:43am UTC](https://discuss.elastic.co/t/logstash-event-size/269972/1 "2021-04-13T07:43:50Z")

</div>

Hi,  
Can anyone tell me how I can get the size of an entire event using the ruby filter please?

Thx  
D

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 13, 2021, 3:15pm UTC](https://discuss.elastic.co/t/logstash-event-size/269972/2 "2021-04-13T15:15:28Z")

</div>

It really depends what you mean by the 'size of an entire event'. See [here](https://discuss.elastic.co/t/logstash-output-to-kafka-server/197710/6) and [here](https://discuss.elastic.co/t/event-get-message-bytesize/267004/2).

---

<div class="post-metadata">

**Author:** ![dawiro](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@dawiro](https://discuss.elastic.co/u/dawiro)\
**Post date:** [April 14, 2021, 8:30am UTC](https://discuss.elastic.co/t/logstash-event-size/269972/3 "2021-04-14T08:30:12Z")

</div>

I'm interested in the size in bytes of the event as it will be shipped to elasticsearch. I imagine the serialisation approach may be best for that. Is that a super expensive operation to perform?

---

<div class="post-metadata">

**Author:** ![dawiro](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@dawiro](https://discuss.elastic.co/u/dawiro)\
**Post date:** [April 14, 2021, 9:15am UTC](https://discuss.elastic.co/t/logstash-event-size/269972/4 "2021-04-14T09:15:07Z")

</div>

One issue that I can foresee with this is that I will be serialising metadata too. I want to get the size of the log event only, if possible.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 14, 2021, 2:43pm UTC](https://discuss.elastic.co/t/logstash-event-size/269972/5 "2021-04-14T14:43:58Z")

</div>

> [@dawiro](#):
>
> I'm interested in the size in bytes of the event as it will be shipped to elasticsearch.

You could try

```
ruby { code => ' event.set("[@metadata][eventSize]", event.to_json.length) ' }

```

I would not call it super expensive, but your judgement may differ.

---

<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:** [May 12, 2021, 2:44pm UTC](https://discuss.elastic.co/t/logstash-event-size/269972/6 "2021-05-12T14:44:14Z")

</div>

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