简体   繁体   English

聚合Java中来自远程Linux服务器的日志文件?

[英]Aggregating log files from remote linux servers in Java?

I have never worked with reading files from linux machines and have no idea how to proceed. 我从没有从Linux机器上读取文件,也不知道如何进行。 I have multiple linux servers which are accessible via ssh. 我有多个可通过ssh访问的linux服务器。 Each machine has a log file which has some data, say some ip addresses. 每台机器都有一个日志文件,其中包含一些数据,例如一些IP地址。 Now how do I write Java code to find the count of each ip address from these log files? 现在如何编写Java代码以从这些日志文件中查找每个IP地址的计数?

I read in another post that I can use JSch library to ssh to linux servers and read the file. 我在另一篇文章中读到,我可以使用JSch库将ssh切换到linux服务器并读取文件。 But then how do I aggregate all the files? 但是,我该如何聚合所有文件? I'm assuming that copying these files in to local machine and then performing an aggregation would be very inefficient? 我假设将这些文件复制到本地计算机中,然后执行聚合会非常低效吗?

You can use exec.java example to start with. 您可以使用exec.java示例开始。 The command would be grep "ip address" /path/to/log_file | wc -l 该命令将是grep "ip address" /path/to/log_file | wc -l grep "ip address" /path/to/log_file | wc -l

However, if the log files are too big and grep is taking more resources, you will have to copy them locally and perform string search on them. 但是,如果日志文件太大并且grep正在占用更多资源,则您将不得不在本地复制它们并对它们执行字符串搜索。 In that case, you may want to start with scpfrom.java or sftp.java 在这种情况下,您可能要从scpfrom.javasftp.java开始

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM