zoukankan      html  css  js  c++  java
  • 一次日志请求次数统计

    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操作

  • 相关阅读:
    五月杂题选做
    BJOI 2021 游记&题解
    U149858
    CF1037简要题解
    CF Round706简要题解
    联合省选 2020
    九省联考 2018 IIIDX
    九省联考 2018 秘密袭击
    AGC006F Balckout
    概率生成函数学习笔记
  • 原文地址:https://www.cnblogs.com/gaoguofeng/p/5850439.html
Copyright © 2011-2022 走看看