# Trouble with simple ruby code calculation

**URL:** <https://discuss.elastic.co/t/trouble-with-simple-ruby-code-calculation/75094>\
**Category:** Logstash\
**Created:** [February 14, 2017, 6:51pm UTC](https://discuss.elastic.co/t/trouble-with-simple-ruby-code-calculation/75094 "2017-02-14T18:51:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cuenca](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cuenca](https://discuss.elastic.co/u/cuenca)\
**Post date:** [February 14, 2017, 6:51pm UTC](https://discuss.elastic.co/t/trouble-with-simple-ruby-code-calculation/75094/1 "2017-02-14T18:51:12Z")

</div>

Hi,

I am getting a ruby exception error for the calculation, but not sure what could causing it.

```
input {
    file {
       type => "csv"
    path => "/Users/path/perf.csv"
    start_position => beginning
    # to read from the beginning of file
    sincedb_path => "/dev/null"
  }
}

filter {
    csv {
        columns => ["page_id","unloadEventEnd","responseEnd","responseStart","domInteractive","domainLookupEnd","unloadEventStart","domComplete","domContentLoadedEventStart","domainLookupstart","redirectEnd","redirectStart","connectEnd","toJSON","connectStart","loadEventStart","navigationStart","requestStart","secureConnectionStart","fetchStart","domContentLoadedEventEnd","domLoading","loadEventEnd"]
    }

            
       grok {
   match => { "page_id" => "%{WORD:page}-%{INT:page_ts}" }
   remove_field => ["page_id", "message", "path"]
   }
    
mutate {
    convert => { "unloadEventEnd" => "integer" }
    convert => { "responseEnd" => "integer" }
    convert => { "responseStart" => "integer" }
    convert => { "domInteractive" => "integer" }
    convert => { "domainLookupEnd" => "integer" }
    convert => { "unloadEventStart" => "integer" }
    convert => { "domComplete" => "integer" }
    convert => { "domContentLoadedEventStart" => "integer" }
    convert => { "domainLookupstart" => "integer" }
    convert => { "redirectEnd" => "integer" }
    convert => { "redirectStart" => "integer" }
    convert => { "connectEnd" => "integer" }
    convert => { "toJSON" => "string" }
    convert => { "connectStart" => "integer" }
    convert => { "loadEventStart" => "integer" }
    convert => { "navigationStart" => "integer" }
    convert => { "requestStart" => "integer" }
    convert => { "secureConnectionStart" => "integer" }
    convert => { "fetchStart" => "integer" }
    convert => { "domContentLoadedEventEnd" => "integer" }
    convert => { "domLoading" => "integer" }
    convert => { "loadEventEnd" => "integer" }

  }
       
ruby {
             code => "event['TTFB'] = event['responseStart'].to_i - event['navigationStart'].to_i"
       }
       
   date {
       match => ["page_ts", "UNIX_MS"]
        target => "timestamp"
        remove_field => ["page_ts"]
        }
    }
output {
  elasticsearch { hosts => ["localhost:9200"] }
  stdout { codec => rubydebug }
  }

```

Any help would be greatly appreciated,

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [February 14, 2017, 8:18pm UTC](https://discuss.elastic.co/t/trouble-with-simple-ruby-code-calculation/75094/2 "2017-02-14T20:18:30Z")

</div>

Please quote the exact error message.

---

<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:** [March 14, 2017, 8:18pm UTC](https://discuss.elastic.co/t/trouble-with-simple-ruby-code-calculation/75094/3 "2017-03-14T20:18:32Z")

</div>

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