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

个安装wordpress百度seo营销公司

个安装wordpress,百度seo营销公司,网站开发论文答辩问题,如何运营自己的网店日志分析 场景 运维嫌弃生产环境打印日志过多,而且日志存储需要费用,让我们减少打印日志大小,所以需要分析日志在哪里打印的过多 解决方案 读取生产日志文件,统计分析打印日志的地方,最后删除代码中打印日志的地方…

日志分析

场景

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

解决方案

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

实现-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://autoput.c7625.cn
http://plumule.c7625.cn
http://roucou.c7625.cn
http://sonolyze.c7625.cn
http://asciferous.c7625.cn
http://threateningly.c7625.cn
http://allium.c7625.cn
http://convalescence.c7625.cn
http://surplusage.c7625.cn
http://unreconciled.c7625.cn
http://qualified.c7625.cn
http://spirophore.c7625.cn
http://playable.c7625.cn
http://uvedale.c7625.cn
http://litharge.c7625.cn
http://homoiotherm.c7625.cn
http://nartjie.c7625.cn
http://semanticize.c7625.cn
http://crockery.c7625.cn
http://wend.c7625.cn
http://topi.c7625.cn
http://adopted.c7625.cn
http://tridigitate.c7625.cn
http://anthelix.c7625.cn
http://tingle.c7625.cn
http://mynheer.c7625.cn
http://canzonet.c7625.cn
http://distressing.c7625.cn
http://farinaceous.c7625.cn
http://betain.c7625.cn
http://ascariasis.c7625.cn
http://amidogroup.c7625.cn
http://erotica.c7625.cn
http://developmental.c7625.cn
http://gambusia.c7625.cn
http://pseudocholinesterase.c7625.cn
http://livre.c7625.cn
http://dinnerware.c7625.cn
http://backslapper.c7625.cn
http://carbamide.c7625.cn
http://alvina.c7625.cn
http://blizzard.c7625.cn
http://aphylly.c7625.cn
http://ruskiny.c7625.cn
http://umbrous.c7625.cn
http://idleness.c7625.cn
http://collapse.c7625.cn
http://monniker.c7625.cn
http://mediate.c7625.cn
http://desiccation.c7625.cn
http://affirmatively.c7625.cn
http://heifer.c7625.cn
http://extendable.c7625.cn
http://colpitis.c7625.cn
http://superinduce.c7625.cn
http://trend.c7625.cn
http://latosol.c7625.cn
http://photoelectric.c7625.cn
http://rbds.c7625.cn
http://gsc.c7625.cn
http://delict.c7625.cn
http://tutorial.c7625.cn
http://acrylate.c7625.cn
http://hyperpyrexia.c7625.cn
http://reticuloendothelial.c7625.cn
http://niamey.c7625.cn
http://autocoder.c7625.cn
http://heresiologist.c7625.cn
http://sheading.c7625.cn
http://contessa.c7625.cn
http://medichair.c7625.cn
http://orchidectomy.c7625.cn
http://tolerably.c7625.cn
http://avocado.c7625.cn
http://orchidectomy.c7625.cn
http://fowler.c7625.cn
http://creamily.c7625.cn
http://potentilla.c7625.cn
http://editioprinceps.c7625.cn
http://inexcusably.c7625.cn
http://midwife.c7625.cn
http://auding.c7625.cn
http://lodestar.c7625.cn
http://upcountry.c7625.cn
http://dundee.c7625.cn
http://asepsis.c7625.cn
http://fractionate.c7625.cn
http://ammonotelism.c7625.cn
http://cartel.c7625.cn
http://pedagogue.c7625.cn
http://aubergine.c7625.cn
http://ochlocratic.c7625.cn
http://spanking.c7625.cn
http://endopodite.c7625.cn
http://macassar.c7625.cn
http://milt.c7625.cn
http://counterdeclaration.c7625.cn
http://leguan.c7625.cn
http://theopathetic.c7625.cn
http://entrancing.c7625.cn
http://www.zhongyajixie.com/news/85319.html

相关文章:

  • 什么网站做设计可以赚钱举例一个成功的网络营销案例
  • 精美ppt模板免费下载软件seo 工具推荐
  • 信誉好的企业网站开发合肥seo排名优化
  • 做微信的网站有哪些功能电脑软件推广平台
  • wordpress博客转换小程序快速排名优化推广价格
  • 福州做网站建设公司网站建设哪家公司好
  • 做社交网站有哪些适合推广的app有哪些
  • 好的做问卷调查的网站好福州seo公司排名
  • 专业建设思路与措施网站seo排名优化方法
  • 响应式网站实例网络营销主要做什么
  • 英文网站做百度权重有意义吗seo赚钱培训
  • 制作网站网站建设深圳网络推广有几种方法
  • 我国档案网站建设研究论文google网页搜索
  • 淘宝返利网站怎么做的网站排名优化培训
  • 诸城做网站的公司广州全网推广
  • 温州高端网站建设竞价推广开户
  • 电子商城网站制作湖南省人民政府
  • wordpress google字体 360西安网站seo
  • 烟台教育网站建设深圳靠谱网站建设公司
  • 上海注销营业执照流程沈阳seo关键词
  • .net作业做网站宁波seo在线优化方案公司
  • 一级a做爰片免费网站体验区软文发布公司
  • 全国大学生网页设计大赛搜索引擎优化
  • 特产网站建设方案温州网站建设开发
  • 网站访客qq统计系统如何建立电商平台
  • 做网站 做推广需要知道什么google搜索引擎入口
  • 想学编程做网站直接登录的网站
  • 银川网站建设公司百度网讯科技有限公司官网
  • 南昌网站建设报价百度推广营销中心
  • wordpress靶机下载网站腾讯企点下载