Ruby Map Counter not working fine

Hi all,
I have the following piece of code where I am just using an orderCounter to count the orders but I end up getting wrong count in my FILE_SAVED logs. I have checked my log file. There isn't any issue in it, and all the groks are working fine as I am getting the right status field against my logs which I add in my groks.
Please let me know if I am doing anything wrong.

  if [status] == "FILE_CREATED"
  {
    ruby
    {
      init => "@@map = {}"
      code => "@@map['orderCounter'] = 0;"
    }
  } 
  else if [status] == "ORDER_SAVED"
  {
      ruby
      {
        code =>  "@@map['orderCounter']+=1;"
      } 
  }
  else if [status] == "FILE_SAVED"
  {
    ruby
    {
      code => "event.set('orderCount', @@map['orderCounter']);" 
    }
  }

It might be some thread concurrency issue, try running it with 1 worker and see if the counter matches the documents.

1 Like

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