当前位置: 首页 > 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.yayakq.cn/news/779908/

相关文章:

  • 网站开发面试自我介绍免费建立网站软件
  • 番禺网站建设优化wordpress ckplay播放
  • 闽侯县住房和城乡建设局官方网站h5网站和传统网站
  • 足球个人网站模板网站是如何做的
  • 在哪个网站做视频可以赚钱匈牙利网站后缀
  • wordpress total主题关于seo如何优化
  • 相馆网站建设费用预算南昌网站定制开发公司
  • 中国化工网官网 网站建设湖州企业做网站
  • 免费制作永久个人网站wordpress ftp
  • 网站建设的所需解决的技术问题dede网站幻灯片
  • vs2017 做c 网站做网站讯息
  • 手机网站qq代码主图详情页模板
  • 建设集团网站方案设计专业招聘信息
  • 全托管跨境电商平台有哪些国外seo
  • 南昌网站建设公司收费企业网站建设方案书模板
  • 传媒公司做网站编辑_如何?门户网站怎么做才好看
  • 炽乐清网站建设付费下载网站源码
  • php网站怎么做做数据可视化图的网站
  • 网站建设海南男生女生在床上做的那个网站
  • 衡水提供网站制作公司哪家专业ui设计培训学校哪里好
  • 网站淘客宝怎么做做知识付费哪个平台好做
  • 小学最好的网站建设黄冈网站建设报价表
  • 擅自使用他人产品做网站宣传顺德网站建设公司有哪些
  • 潍坊大型网站建设做pc端网站资讯
  • 门户网站建设重建方案如何在手机使用wordpress
  • 设置本机外网ip做网站高端网站设计官网
  • 金融网站 改版方案wordpress动漫二次元主题
  • asp网站关键字卡一卡二卡四卡视频免费观看
  • 怎么在文档中做网站一点就开wordpress 邮件功能
  • 做网站还有意义吗响应式网站空间服务器要求