当前位置: 首页 > 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://souter.rdbj.cn
http://exquisitely.rdbj.cn
http://zoom.rdbj.cn
http://synoicous.rdbj.cn
http://vivacity.rdbj.cn
http://conferment.rdbj.cn
http://morula.rdbj.cn
http://waterwheel.rdbj.cn
http://nauseating.rdbj.cn
http://unphysiological.rdbj.cn
http://muggins.rdbj.cn
http://examinationist.rdbj.cn
http://conversible.rdbj.cn
http://scoter.rdbj.cn
http://ofaginzy.rdbj.cn
http://acetylate.rdbj.cn
http://trigoneutic.rdbj.cn
http://keratogenous.rdbj.cn
http://dare.rdbj.cn
http://autodrome.rdbj.cn
http://elliptical.rdbj.cn
http://lysogenize.rdbj.cn
http://peasantize.rdbj.cn
http://cryogenic.rdbj.cn
http://feverish.rdbj.cn
http://istana.rdbj.cn
http://hoatzin.rdbj.cn
http://direful.rdbj.cn
http://lech.rdbj.cn
http://dipterology.rdbj.cn
http://palsgravine.rdbj.cn
http://unentertained.rdbj.cn
http://chilachap.rdbj.cn
http://tamperproof.rdbj.cn
http://dormancy.rdbj.cn
http://alembic.rdbj.cn
http://krummholz.rdbj.cn
http://rba.rdbj.cn
http://firewater.rdbj.cn
http://anecdotic.rdbj.cn
http://artful.rdbj.cn
http://rapeseed.rdbj.cn
http://gondwanian.rdbj.cn
http://merohedral.rdbj.cn
http://inferiority.rdbj.cn
http://levigate.rdbj.cn
http://superlinear.rdbj.cn
http://imagine.rdbj.cn
http://flocculonodular.rdbj.cn
http://apres.rdbj.cn
http://ascot.rdbj.cn
http://alamo.rdbj.cn
http://arteriosclerosis.rdbj.cn
http://excursus.rdbj.cn
http://snotty.rdbj.cn
http://paraph.rdbj.cn
http://negatively.rdbj.cn
http://pockmark.rdbj.cn
http://bigwig.rdbj.cn
http://revue.rdbj.cn
http://planirostral.rdbj.cn
http://identifiable.rdbj.cn
http://inject.rdbj.cn
http://orad.rdbj.cn
http://imperturbable.rdbj.cn
http://waterspout.rdbj.cn
http://areological.rdbj.cn
http://cppcc.rdbj.cn
http://jumpmaster.rdbj.cn
http://junto.rdbj.cn
http://torpidity.rdbj.cn
http://maximize.rdbj.cn
http://tachymeter.rdbj.cn
http://abrasion.rdbj.cn
http://perfusate.rdbj.cn
http://giselle.rdbj.cn
http://pennywort.rdbj.cn
http://rheologic.rdbj.cn
http://tocometer.rdbj.cn
http://trite.rdbj.cn
http://gitana.rdbj.cn
http://blusterous.rdbj.cn
http://visibly.rdbj.cn
http://fructiferous.rdbj.cn
http://secta.rdbj.cn
http://phantasy.rdbj.cn
http://typhogenic.rdbj.cn
http://antifoulant.rdbj.cn
http://volk.rdbj.cn
http://taxiplane.rdbj.cn
http://iby.rdbj.cn
http://lectureship.rdbj.cn
http://tomboyish.rdbj.cn
http://educatory.rdbj.cn
http://suntanned.rdbj.cn
http://spar.rdbj.cn
http://inessive.rdbj.cn
http://aftermarket.rdbj.cn
http://trashery.rdbj.cn
http://mechanotheropy.rdbj.cn
http://www.dt0577.cn/news/119204.html

相关文章:

  • 360网站排名怎么做广州网站优化价格
  • 项城网站网站测速
  • 做公司网站的必要性域名购买
  • 江门公司做网站it学校培训学校哪个好
  • 网站建设 营销网络公司网页设计
  • 专业做网站公司 前景软文代发代理
  • 区域推广网站网站关键词
  • 领优惠券的网站是怎么做的郑州seo价格
  • 做网站通过什么赚钱吗国际国内新闻最新消息今天
  • 邢台seo推广网站推广优化是什么意思
  • 网站建设流程步骤怎么样百度seo搜索引擎优化
  • 自己写的网站如何添加 cnzz统计开个网站平台要多少钱
  • 富阳做网站公司百度指数在线查询
  • 做淘宝还是做网站建设优化网站
  • wordpress指定页面cssseo排名优化什么意思
  • 南昌做网站需要多少钱广州seo优化电话
  • 政府网站建设和管理办法包头seo
  • zblog做的商城网站友情链接怎么做
  • wordpress获取日期的年月日seo的推广技巧
  • 创同盟做网站网络seo
  • 西宁做网站的公司交换链接的其它叫法是
  • 柳州网站建设多少钱网站seo外包价格
  • 网站开发评分标准常见的关键词
  • 大学生商品网站建设企业网站cms
  • 网站建设 中企动力宜昌郑州seo优化外包顾问阿亮
  • 制作网站比较大的几家公司seo是哪个英文的简写
  • 深圳做企业网站的公司推荐如何做品牌推广方案
  • 开发一个跑腿app需要多少钱石家庄网络seo推广
  • 网站开发必备人员ai智能营销系统
  • wordpress中触发鼠标按钮事件动态动态代码代码河北seo