当前位置: 首页 > news >正文

学校网站怎么查询录取政府免费培训 面点班

学校网站怎么查询录取,政府免费培训 面点班,家具设计手绘,个人网站用移动硬盘做服务器日志分析 场景 运维嫌弃生产环境打印日志过多,而且日志存储需要费用,让我们减少打印日志大小,所以需要分析日志在哪里打印的过多 解决方案 读取生产日志文件,统计分析打印日志的地方,最后删除代码中打印日志的地方…

日志分析

场景

运维嫌弃生产环境打印日志过多,而且日志存储需要费用,让我们减少打印日志大小,所以需要分析日志在哪里打印的过多

解决方案

读取生产日志文件,统计分析打印日志的地方,最后删除代码中打印日志的地方

实现-LogParAnalyzer

public class LogParAnalyzer {//日志原始文件private File log;private List<Pattern> list;private ExecutorService executorService;//生成的分割文件private String subPath = "D:\\split\\";private List<File> files;public LogParAnalyzer(File log, List<String> patterns) {this.log = log;executorService = Executors.newFixedThreadPool(30);list = new ArrayList<>();try {for (String pattern : patterns) {Pattern p = Pattern.compile(pattern);list.add(p);}} catch (Exception e) {throw new RuntimeException(e);}}public void analyze() throws Exception {// 使用 try-with-resources 自动关闭 BufferedReaderint chunkSize = 100000;try (BufferedReader reader = new BufferedReader(new FileReader(log))) {File file = new File(subPath);if (!file.exists()) {file.mkdirs();}String line;List<CompletableFuture<?>> task = new ArrayList<>();int cur = 0;List<String> list = new ArrayList<>();AtomicInteger batch = new AtomicInteger(0);while ((line = reader.readLine()) != null) {//sb 会通过Arrays.copy复制字节数组,内存频繁复制list.add(line);cur++;if ((cur % chunkSize) == 0) {//深拷贝List<String> tt = list.stream().map(String::new).collect(Collectors.toList());list.clear();CompletableFuture f =CompletableFuture.runAsync(() -> processChunk(tt, batch.get()), executorService);task.add(f);batch.incrementAndGet();}}if (list.size()>0) {CompletableFuture f =CompletableFuture.runAsync(() -> processChunk(list, batch.get()), executorService);task.add(f);}//等待所有任务结束CompletableFuture.allOf(task.toArray(new CompletableFuture[0])).get();System.out.println("task execute finished");}}private void processChunk(List<String> lines, int batch) {try {System.out.println(Thread.currentThread().getName()+" execute "+ batch+".txt start");Map<String, AtomicInteger> map = new HashMap<>();try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(subPath + batch + ".txt"))) {lines.forEach(line -> {for (Pattern pattern : list) {Matcher matcher = pattern.matcher(line);if (matcher.find()) {String group = matcher.group(0);map.computeIfAbsent(group, k -> new AtomicInteger(1)).incrementAndGet();}}if (map.size() > 0) {//每个文件只保存100前100条writeBatchToFile(writer, map);}});}System.out.println(Thread.currentThread().getName()+" execute "+ batch+".txt end");} catch (Exception e) {e.printStackTrace();}}private void writeBatchToFile(BufferedWriter writer, Map<String, AtomicInteger> map) {Map<String, AtomicInteger> limit = limit(map, 100);try {for (Map.Entry<String, AtomicInteger> entry : limit.entrySet()) {writer.write(entry.getKey() + "=" + entry.getValue().get());writer.newLine();}} catch (IOException e) {e.printStackTrace();}//清除缓存map.clear();limit.clear();}public void mergeAndSort() throws Exception {files = Files.list(Paths.get(subPath)).map(Path::toFile).filter(f -> f.length() > 0).collect(Collectors.toList());// 创建 ForkJoinPoolForkJoinPool forkJoinPool = new ForkJoinPool();MergeFileTask mergeFileTask = new MergeFileTask(files.toArray(new File[0]), forkJoinPool);Path finalPath = mergeFileTask.invoke();System.out.println("final path: " + finalPath.toAbsolutePath());try (BufferedReader reader = Files.newBufferedReader(finalPath)) {String line;while ((line = reader.readLine()) != null) {System.out.println(line);}}mergeFileTask.finished();}public void finished() throws IOException {if (!CollectionUtils.isEmpty(files)){files.stream().parallel().forEach(File::delete);}Files.deleteIfExists(Paths.get(subPath));}public Map<String, AtomicInteger> limit(Map<String, AtomicInteger> map, int limit) {// 排序并过滤结果return map.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.comparing(AtomicInteger::get).reversed())).limit(limit).collect(Collectors.toMap(Map.Entry::getKey,Map.Entry::getValue,(oldValue, newValue) -> oldValue, // 解决键冲突LinkedHashMap::new));}}

测试

@Test
public void bb() throws Exception {StopWatch stopWatch = new StopWatch();stopWatch.start();File log = new File("E:\\log_total.log\\log_total.log");//2023-09-26 11:10:00.123 INFO - none --- [main] com.example.service.UserService.create:42 - User service started successfully.//匹配出 com.example.service.UserService.create:42//c.y.c.w..*指文件名太长,缩写List<String> list = Arrays.asList("(com\\.xx\\.[\\w\\.\\*]*:\\d*)", "(c\\.y\\.c\\.[\\w\\.\\*]*:\\d*)");LogParAnalyzer logAnalyzer = new LogParAnalyzer(log, list);logAnalyzer.analyze();logAnalyzer.mergeAndSort();logAnalyzer.finished();stopWatch.stop();System.out.println(stopWatch.prettyPrint());//最后统计格式//c.y.c.s.service.impl.Service.complete:98 count: 6
}

good luck!

http://www.dinnco.com/news/51852.html

相关文章:

  • 专业做网站建设公司有哪些寻找客户的12种方法
  • 东台市住房和城乡建设局网站百度总部
  • 做网站需要交税seo点击排名工具有用吗
  • asp动态网页开发seo的中文含义
  • 注册一个公司需要哪些资料南京网络优化公司有哪些
  • 网站备案管理360搜索引擎推广
  • 河南企起网站建设0元做游戏代理
  • 哪里有免费建站平台上海网站快速优化排名
  • 个人网站毕业设计论文南宁百度关键词排名公司
  • 怎么做hs网站哪里有永久免费建站
  • 政府网站群建设的意义b站视频推广网站2023年
  • wordpress调用分类目录文章企业seo优化服务
  • 商城购物网站定制策划方案怎么做
  • 芜湖建设机械网站北京优化网站建设
  • 免费的logo设计网站百度网址大全官网旧版
  • 网站维护需要哪些知识百度指数的数值代表什么
  • 大陆手机如何安装台湾appseo搜索排名优化是什么意思
  • 做商业网站怎么制作一个简单的网页
  • 玉树州网站建设公司策划是做什么的
  • 站长 网站对比seo视频教程
  • 创业网站怎么做的代运营是什么意思
  • 广州自助建站服务热线品牌公关公司
  • 毕业设计网站开发要做什么电子商务推广方式
  • 免费网站制作新闻网站定制
  • 网站的登录界面是怎么做的网络平台推广方式
  • 课程网站开发背景郑州网站推广哪家专业
  • 如何选择合适的建站公司怎样推广品牌
  • 哪家公司做移动网站官网优化 报价
  • 山东德州网站建设站长之家seo概况查询
  • 个人站长做哪些网站好竞价托管如何托管