最忌服务器不稳定一直出现各种问题,莫名其妙的出现404,500的等错误,并且时好时坏。
只有分析web 服务器的日志,上去一看,我滴个神呢~~~2G。
工具各种尝试,各种卡死,各种缓慢。折腾半天,,没辙~~
只好使用java写个读取的吧,开始打算使用commons-io来读取,一运行,OOM了。
看来只能使用一点点读取了,写了下面的代码。居然可以了。
public class AnlyLogApache {
public static void main(String[] args) throws Exception {
// List<String> lines = FileUtils.readLines(new File("D:/工作资料-微软/项目资料/市民网(一期)/2011-10-28_102apache分析/access20111026.log"));
// for (String string : lines) {
// if(string.indexOf("HTTP/1.1\" 500") != -1 && string.indexOf("HTTP/1.1\" 404")!=-1) {
// System.out.println(string);
// }
// }
File file = new File("access20111027.log");
BufferedReader
bin = new BufferedReader(new InputStreamReader(new FileInputStream( file)));
String str= null;
Map<String, String> map = new HashMap<String, String>();
int sum = 0;
int start = 0;
int end = 0;
while((str= bin.readLine()) != null)
{
if( (str.indexOf("/gzns") != -1 || str.indexOf("/p-homepage") != -1 )&&(str.indexOf("HTTP/1.1\" 500") != -1 /*|| str.indexOf("HTTP/1.1\" 404")!=-1*/)) {
start = str.indexOf("GET");
if(start == -1) {
start = str.indexOf("POST");
}
if(start == -1) {
start = 0;
}
end = str.indexOf("Mozilla/4.0");
if(end == -1) {
end = str.length();
}
sum++;
//System.out.println(start+" "+end);
map.put(str.substring(start,end), str);
}
}
Set<String> keys = map.keySet();
for (String string : keys) {
System.out.println(map.get(string));
}
System.out.println("==================="+sum+"=================");
bin.close();
}