首页 > 其他 > 详细

一次日志请求次数统计

时间:2016-09-07 19:24:54      阅读:166      评论:0      收藏:0      [点我收藏+]
package  test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.TreeMap;

public class Count {
    
    public static void main(String[] args) throws Exception {
        File file = new File("d:/kht_d2.log");
        BufferedReader in = new BufferedReader(
                new InputStreamReader(
                        new FileInputStream(file), "UTF-8"));
        Map<String, Integer> map = read(in);
        for(String str : map.keySet()) {
            System.out.println(str + "=" + map.get(str));
        }
        in.close();
    }
    
    public static Map<String, Integer> read(BufferedReader in) throws Exception {
        Map<String, Integer> map = new TreeMap<String, Integer>();
        String str = null;
        int count = 0;
        while((str = in.readLine()) != null) {
            if(str.length() > 20 && (str.indexOf("") != -1 )) {
                String date = str.substring(str.indexOf(":") + 1,
                        str.indexOf(":") + 11);
                if(map.get(date) == null) {
                    count = 0;
                    map.put(date, ++count);
                } else {
                    map.put(date, ++count);
                }
            }
        }
        return map;
    }
    
}

说明:

      这次是统计从我们平台发往其他平台的请求次数,思路就是对每一行的关键字进行验证,如果存在进行加1操作

一次日志请求次数统计

原文:http://www.cnblogs.com/gaoguofeng/p/5850439.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!