# How to add up values from list and send only that value to elasticserach

**URL:** https://discuss.elastic.co/t/how-to-add-up-values-from-list-and-send-only-that-value-to-elasticserach/254441
**Category:** Logstash
**Created:** [November 5, 2020, 5:31pm UTC](https://discuss.elastic.co/t/how-to-add-up-values-from-list-and-send-only-that-value-to-elasticserach/254441 "2020-11-05T17:31:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Adriann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adriann/32/77780_2.png) [@Adriann](https://discuss.elastic.co/u/Adriann)
#### Post date: [November 5, 2020, 5:31pm UTC](https://discuss.elastic.co/t/how-to-add-up-values-from-list-and-send-only-that-value-to-elasticserach/254441/1 "2020-11-05T17:31:04Z")

</div>

Hello,

I want to write logstash script that use snmpwalk to get cpu values form network devices average them and send one field to elasticsearch. I guess I can do this in ruby plugin but I have so fare only expiernce in Java nad Python. How can I do this using ruby filter or other logstash capabilities?

This is how my document looks like before any manipulation.

```
{
                       "tags" => [
        [0] "snmp",
        [1] "metrics"
    ],
                    "host.ip" => "ip",
                 "@timestamp" => 2020-11-05T14:43:20.707Z,
                   "@version" => "1",
    "cisco.device.system.cpu" => [
        [0] {
                                                                 "index" => "1",
            "iso.org.dod.internet.private.enterprises.9.9.109.1.1.1.1.7" => 15
        },
        [1] {
                                                                 "index" => "2",
            "iso.org.dod.internet.private.enterprises.9.9.109.1.1.1.1.7" => 15
        },
        [2] {
                                                                 "index" => "3",
            "iso.org.dod.internet.private.enterprises.9.9.109.1.1.1.1.7" => 15
        }
    ],
              "host.hostname" => "name"
}
```

---

<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: [November 5, 2020, 6:22pm UTC](https://discuss.elastic.co/t/how-to-add-up-values-from-list-and-send-only-that-value-to-elasticserach/254441/2 "2020-11-05T18:22:38Z")

</div>

You could try something like

```
ruby {
    code => '
        cpus = event.get("cisco.device.system.cpu")
        if cpus
            count = 0
            total = 0
            cpus.each { |x|
                count += 1
                total += x["iso.org.dod.internet.private.enterprises.9.9.109.1.1.1.1.7"]
            }
            event.set("averageCpu", total/count)
        end
    '
}
```

---

<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: [December 3, 2020, 6:22pm UTC](https://discuss.elastic.co/t/how-to-add-up-values-from-list-and-send-only-that-value-to-elasticserach/254441/3 "2020-12-03T18:22:47Z")

</div>

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