title: logstash sum values from jdbc input
body: <p>I'm new on logstash and i'm trying to sum the value from two colums from my database and generate a new metric.</p>
  
  <p>I've exhausted all my alternatives.</p>
  
  <p>this is my conf file. the new varible that I'm creating is the 'tod_ped'
  I created another variable to try to understand what is happenig with the value of 'TOT_PROD', the variable is 'valor'.</p>
  
  <p>the two colums that i`m trying to sum is 'TOT_PROD' and 'TOT_SERV'.</p>
  
  <pre><code>input {
    jdbc {
      jdbc_driver_library =&gt; "jtds-1.3.1.jar"
      jdbc_driver_class =&gt; "Java::net.sourceforge.jtds.jdbc.Driver"
      jdbc_connection_string =&gt; "jdbc:jtds:sqlserver://xxxxxx:1433/dbPHXPSS"
      jdbc_user =&gt; "readonly"
      jdbc_password =&gt; "xxxxx"
      statement =&gt; "SELECT [NVENDA]
                ,[CPROJETO]
                ,[TECNOLOGIA]
                ,[PREVISAO]
                ,[APROVACAO]
                ,[STATUS]
                ,[CLIENTE]
                ,[TITULO]
                ,[TOT_PROD]
                ,[TOT_SERV]
                ,[QTD_H_FE]
                ,[QTD_H_SE]
                ,[QTD_H_PM]
                ,[QTD_H_DES]
                ,[TOT_DESPESA]
                ,[VENDEDOR]
          ,[TIPO_SOLICITACAO]
          ,[TECNOLOGIAPROJ]
            FROM [dbPHXPSS].[dbo].[VW_PROVISAOPROJETOS]
    where QTD_H_PM IS NOT NULL"
  }
  }
  filter {
  
     ruby {
          code =&gt;"
  
          hash = event.to_hash
          hash.each do |k,v|
                  if v == nil
                          event.set(k,'0')
                  end
                  if k == 'TOT_PROD'
                          event.set(teste, v)
                  end
          end
       # testing the content from de varible 'TOT_PROD'
       event.set('valor', event.get('teste'))
          "
          }
  
   mutate {
          convert =&gt; ["TOT_PROD","float_eu"]
    }
  
  ruby {
          code =&gt;"
          # adding the values to 'tot_ped'
          event.set('tot_ped', (event.get('TOT_PROD').to_f + event.get('TOT_SERV').to_f ))
          "
          }
  }
  output {
          elasticsearch {
                  hosts =&gt; "localhost"
                  index =&gt; "phoenix"
                  document_type =&gt; "phxdb"
      }
          stdout {}
  }
  </code></pre>
  
  <p>this is the return code from logstash.
  What i've noticed is that the varible 'tot_ped' is not adding the values, and the test varible is returning the value of 'TOT_PROD' as nil.</p>
  
  <pre><code>{
              "@version" =&gt; "1",
               "cliente" =&gt; "OAB SP                        ",
              "vendedor" =&gt; "Sxxxxxxxx",
                "status" =&gt; "MEDIA",
      "tipo_solicitacao" =&gt; "0",
             "aprovacao" =&gt; "0",
              "tot_serv" =&gt; 0.0,
              "cprojeto" =&gt; "0",
              "qtd_h_se" =&gt; 132.0,
              "qtd_h_pm" =&gt; 24.0,
                 "valor" =&gt; nil,
               "tot_ped" =&gt; 0.0,
             "qtd_h_des" =&gt; "0",
            "@timestamp" =&gt; 2019-03-15T13:42:15.243Z,
             "tot_prod" =&gt; 134133.7195,
           "tot_despesa" =&gt; "0",
                "titulo" =&gt; "Projeto Wifi",
              "previsao" =&gt; "0",
            "tecnologia" =&gt; "VSF",
        "tecnologiaproj" =&gt; "0",
              "qtd_h_fe" =&gt; 56.0,
                "nvenda" =&gt; 20361.0
  }
  </code></pre>
  
  <p>Thank you advanced.</p>