我是 logstash 的新手,我正在尝试将数据库中两列的值相加并生成一个新指标。
我已经用尽了所有的选择。
这是我的 conf 文件。我正在创建的新变量是“tod_ped”,我创建了另一个变量以尝试了解“TOT_PROD”的值发生了什么,该变量是“valor”。
我试图求和的两个列是“TOT_PROD”和“TOT_SERV”。
input {
jdbc {
jdbc_driver_library => "jtds-1.3.1.jar"
jdbc_driver_class => "Java::net.sourceforge.jtds.jdbc.Driver"
jdbc_connection_string => "jdbc:jtds:sqlserver://xxxxxx:1433/dbPHXPSS"
jdbc_user => "readonly"
jdbc_password => "xxxxx"
statement => "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 =>"
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 => ["TOT_PROD","float_eu"]
}
ruby {
code =>"
# 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 => "localhost"
index => "phoenix"
document_type => "phxdb"
}
stdout {}
}
这是logstash的返回码。我注意到的是变量“tot_ped”没有添加值,而测试变量将“TOT_PROD”的值返回为零。
{
"@version" => "1",
"cliente" => "OAB SP ",
"vendedor" => "Sxxxxxxxx",
"status" => "MEDIA",
"tipo_solicitacao" => "0",
"aprovacao" => "0",
"tot_serv" => 0.0,
"cprojeto" => "0",
"qtd_h_se" => 132.0,
"qtd_h_pm" => 24.0,
"valor" => nil,
"tot_ped" => 0.0,
"qtd_h_des" => "0",
"@timestamp" => 2019-03-15T13:42:15.243Z,
"tot_prod" => 134133.7195,
"tot_despesa" => "0",
"titulo" => "Projeto Wifi",
"previsao" => "0",
"tecnologia" => "VSF",
"tecnologiaproj" => "0",
"qtd_h_fe" => 56.0,
"nvenda" => 20361.0
}
谢谢先进。