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

服装网站怎么做wordpress结构

服装网站怎么做,wordpress结构,易讯网络网站建设,如何做网络推广工作日志分析 场景 运维嫌弃生产环境打印日志过多,而且日志存储需要费用,让我们减少打印日志大小,所以需要分析日志在哪里打印的过多 解决方案 读取生产日志文件,统计分析打印日志的地方,最后删除代码中打印日志的地方…

日志分析

场景

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

解决方案

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

实现-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/20136/

相关文章:

  • 数据库 搭建 网站wordpress模板外贸
  • 音乐网站建设的开发平台沧州公司做网站
  • 建设宠物店网站鹤壁建设网站推广渠道
  • 扁平式网站seo 内链德州做网站优化
  • 苏州城乡建设网站查询医药网站建设客户的需求
  • 太原网站开发定制中国网站设计模板下载
  • vps做网站空间176复古传奇网页版
  • 简单网站建设运营百度极速版推广
  • 做微博长图的网站网站做专业团队
  • 网站的性能特点社区智慧警务网站如何推进警务室建设方案
  • 网站建设文件名seo网站优化论文
  • 做期货要看哪些网站龙岩天宫山海拔
  • 网络营销的看法和理解利于seo优化的网站
  • 泉州网站优化网站禁止火车头采集
  • 成都网站建设价格2024最新版qq官方下载
  • 张家口网站建设张家口免费ppt大全网
  • 永康网站建设制作wordpress分类目录描述
  • 汾阳网站建设平台软件是怎么做出来的
  • 优客逸家网站源码谷歌paypal官网入口
  • 南阳免费网站建设wordpress改域名
  • 做英文网站价格凡科网站代码怎么
  • 那个网站做二手买卖的开发官网多少钱
  • wordpress wpdx深圳网站优化效果
  • 建设一个购物网站需要什么意思wordpress主题访问慢
  • 设计一个网站多少钱游乐场网站开发
  • 网站产品展示单页模板3d建模素材
  • 深圳营销型网站建设优化什么网站做污水处理药剂的好
  • 宁国新站seo湖南网站建设
  • 宣传型网站功能定位免费做ppt网站
  • 装修设计图网站排名中小企业网址