Ruby code works in an online IDE but not in logstash pipeline

`Hi, Im using ruby scan method to get the values of some metrics in a line

examples:

73% virtual memory used,4442MB virtual memory free,0.10955 pages-sec`
0% swap space used,6125MB swap space free,0 pages-sec; 88% physical memory used,910MB physical memory free

this is my ruby code:

            ruby {
                code => "
                    testa = event.get('status')

                    vmu = testa.scan(/([^[:space:]]+)% virtual memory used,/).join()
                    vmf = testa.scan(/,([^[:space:]]+)MB virtual memory free,/).join()
                    ssu = testa.scan(/([^[:space:]]+)% swap space used,/).join()
                    ssf = testa.scan(/,([^[:space:]]+)MB swap space free,/).join()
                    pmu = testa.scan(/([^[:space:]]+)% physical memory used,/).join()
                    pmf = testa.scan(/,([^[:space:]]+)MB physical memory free/).join()

                    unless vmu.empty?
                    event.set('virtual_memused_per', 'vmu')
                    end
                    unless vmf.empty?
                    event.set('virtual_memfree_mb', 'vmf')
                    end
                    unless ssu.empty?
                    event.set('memory_swapused_per', 'ssu')
                    end
                    unless ssf.empty?
                    event.set('memory_swapfree', 'ssf')
                    end
                    unless pmu.empty?
                    event.set('memory_memused_per', 'pmu')
                    end
                    unless pmf.empty?
                    event.set('memory_memfree', 'pmf')
                    end
                            "
                }

But I only get zeros in the created fields, what Im doing wrong?

That sets [virtual_memused_per] to the literal string vmu.

1 Like

:man_facepalming: thanks Badger!

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