小白求问:我用logstash的tcp-input 插件监听某个端口,然后用java的socket发送网络数据,但是logstash接收不到?测试过java程序和logstash的配置应该没问题。
Logstash | 作者 mjcr | 发布于2017年11月26日 | 阅读数:4956
java发送数据代码:
public static void main(String args) {
try {
//创建socket
Socket socket = new Socket("192.168.0.9", 5551);
//获取输出流,用于发送信息
OutputStream os = socket.getOutputStream(); //字节输出流
PrintWriter pw = new PrintWriter(os); //将输出流包装成打印流
pw.write("name:xiaoah");
pw.flush();
socket.shutdownOutput(); //关闭输出流
//关闭其他资源
pw.close();
os.close();
socket.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
logstash的配置:
input {
tcp{
mode => "server"
port => 5551
id => "tcp_plugin"
}
}
filter{
}
output{
stdout{
codec => rubydebug
}
}
public static void main(String args) {
try {
//创建socket
Socket socket = new Socket("192.168.0.9", 5551);
//获取输出流,用于发送信息
OutputStream os = socket.getOutputStream(); //字节输出流
PrintWriter pw = new PrintWriter(os); //将输出流包装成打印流
pw.write("name:xiaoah");
pw.flush();
socket.shutdownOutput(); //关闭输出流
//关闭其他资源
pw.close();
os.close();
socket.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
logstash的配置:
input {
tcp{
mode => "server"
port => 5551
id => "tcp_plugin"
}
}
filter{
}
output{
stdout{
codec => rubydebug
}
}
0 个回复