Linux Command - CRON

Linux CRON 命令 CREATE A CRON SCRIPT TO CLEAN Edit the /opt/daily-clean.sh file #!/bin/bash # docker docker system prune -f docker builder prune -f docker volume prune -f # /home/puaiuc/ find /home/puaiuc/ -maxdepth 1 -type f \( -iname "*" ! -iname ".*" \) -delete Now give the file executable permission chmod a+x /opt/daily-clean.sh Edit the crontab file to schedule it crontab -e In our case, we have scheduled it to every day at the start of the day

Read more

Use brew install python2 and python3 on macOS

使用 pyenv 可以很灵活的配置版本环境 环境说明 我的 macbook 上默认已经安装了 python3,但是我还需要一个 python2 环境编译一些老的项目 python3 --version Python 3.11.2 安装 安装 pyenv $ brew install pyenv 允许在 bash 中启用 pyenv $ eval "$(pyenv init -)" 使用 一旦你安装了pyenv并激活了它,你可以安装不同版本的python并选择你可以使用的版本。 $ pyenv install 2.7.18 你可以用以下命令检查安装的版本 $ pyenv versions 你可以使用如下命令切换全局版本 $ pyenv global 3.3.1 你可以使用如下命令在当前目录设置版本 $ pyenv local 3.5.2 你能够运行以下命令检查版本 $ python --version Python 2.7.18

Git Pick Commits to Another Reps

从上游仓库中选取 commits 提交到另一个仓库 附加修改作者,消息,时间 前期准备 你要准备一个要同步的库 # 下载这个库 git clone git@github.com:coolbeevip/git-commits-replay.git # 查看这个库的所有 commits git --git-dir=./git-commits-replay/.git log --pretty=format:"%H,%an,%ae,%ad,%s" --date=format:'%Y-%m-%d %H:%M:%S' --reverse 52d099240f6da63193ba309106dad77d060836a7,Lei Zhang,zhanglei@apache.org,2023-02-18 10:49:43,Create A.md 516e406615c0020919939bafe59b35359a03c33b,Lei Zhang,zhanglei@apache.org,2023-02-18 10:50:09,Create B.md 551e5c88440396b73f3b1642bf765dcb9136fd1f,Lei Zhang,zhanglei@apache.org,2023-02-18 10:50:30,Create C.md 5dacf876b6f0b4a0d3ead7ec3daaac924b1b37f4,Lei Zhang,zhanglei@apache.org,2023-02-18 10:51:02,Create ALL.md 72a7a54c48286e9a7c92d1201108baa61cbd7db4,Lei Zhang,zhanglei@apache.org,2023-02-18 10:52:13,删除 A B C 新建一个仓库并关联要同步的库 # 新建一个本地仓库 mkdir git-commits-replay-local cd git-commits-replay-local git init git config --global init.defaultBranch master git branch -m master # 关联上游仓库 git remote add upstream git@github.com:coolbeevip/git-commits-replay.git 重放 commit 并修改提交信息 例如要将 52d099240f6da63193ba309106dad77d060836a7,Lei Zhang,zhanglei@apache.

Read more

Linux Command - Supervisory

定时收集当前用户的CPU和内存利用率 创建如下 user_usage.sh #!/usr/bin/bash echo -e TIME\\tCPU%\\tMEM% while true do top -b -n 1 -u "$user" | awk -v user="$user" -v date="$(date '+%Y/%m/%d %H:%M:%S')" 'NR>7 { cpu_utilization_sum += $9; mem_utilization_sum += $10;} END { printf "%s\t%.2f\t%.2f\n",date,cpu_utilization_sum,mem_utilization_sum; }' sleep $1 done 每 3 秒采集一次 sh user_usage.sh 3 TIME CPU% MEM% 2023/01/06 17:26:56 64.80 82.10 2023/01/06 17:26:57 70.60 82.10 2023/01/06 17:26:58 393.60 82.10 2023/01/06 17:26:59 137.50 82.20 定时收集某个进程的CPU和内存利用率 创建如下 proc_usage.sh #!/usr/bin/bash echo proc $2 echo -e TIME\\tCPU%\\tMEM% while true do top -b -n 1 -p `ps -ef | grep $2 | grep -v grep | awk '{ print $2 }' | paste -s -d ','` | awk -v user="$user" -v date="$(date '+%Y/%m/%d %H:%M:%S')" 'NR>7 { cpu_utilization_sum += $9; mem_utilization_sum += $10;} END { printf "%s\t%.

Read more

Linux Command - CPU

Linux CPU 相关命令 查看 CPU 信息 $ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 4 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 85 Model name: Intel Xeon Processor (Skylake, IBRS) Stepping: 4 CPU MHz: 2299.996 BogoMIPS: 4599.99 Hypervisor vendor: KVM Virtualization type: full L1d cache: 32K L1i cache: 32K L2 cache: 4096K L3 cache: 16384K NUMA node0 CPU(s): 0-3 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 arat pku ospke spec_ctrl intel_stibp PI 值计算 $ time echo "scale=5000; 4*a(1)" | bc -l -q 7-Zip 基准测试 使用 7-Zip 自带的 LZMA 压缩基准测试测量 CPU 性能

Read more

常用日志统计脚本

常用日志分析脚本,日志样例如下 2022-12-02 17:00:02,580 [reactor-http-epoll-7] O [com.my.gateway.filter.RequestGlobalFilter] RequestGlobalFilter.java:46 - request http://gateway/myapp/graphql remote address 110.242.12.19 统计文件中匹配规则的行数 统计 2022-12-02 日 17 点至 18 点包含 RequestGlobalFilter 关键字的行数 $ cat my-gateway_9999.log | grep '2022-12-02 17.*RequestGlobalFilter' | wc -l 24003 统计 2022-12-02 日 17 点至 18 点包含 RequestGlobalFilter 并且请求路径包含 myapp 关键字的行数 $ cat my-gateway_9999.log | grep '2022-12-02 17.*RequestGlobalFilter.*myapp.*' | wc -l 6369 分组统计 统计 2022-12-02 日 17 点至 18 点包含 RequestGlobalFilter 按照客户端 IP 地址统计每个客户端的请求行数 $ cat my-gateway_9999.

Read more

使用 Checkstyle Plugin 检查 Java 代码(风格)质量

本文记录了如何在 Maven 项目中使用 Apache Maven Checkstyle Plugin 检查代码风格质量 一个 Maven 项目 假设我有一个 Maven 项目,这个项目包含若干子模块。根目录的 pom.xml 看起来如下: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>my</groupId> <artifactId>my-project</artifactId> <version>${revision}</version> <packaging>pom</packaging> <properties> <revision>0.1.0-SNAPSHOT</revision> </properties> <modules> <module>module-dependencies</module> <module>module-bar</module> <module>module-foo</module> </modules> </project> 在根项目 pom.xml 中增加 maven-checkstyle-plugin 插件 增加 maven-checkstyle-plugin 插件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>my</groupId> <artifactId>my-project</artifactId> <version>${revision}</version> <packaging>pom</packaging> <properties> <maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version> <com.puppycrawl.tools.version>9.3</com.puppycrawl.tools.version> </properties> <modules> <module>module-dependencies</module> <module>module-bar</module> <module>module-foo</module> </modules> <build> <pluginManagement> <plugins> <plugin> <groupId>org.

Read more

在 Maven 项目中使用 PMD Plugin 检查 Java 代码(Java源代码)质量

本文记录了如何在 Maven 项目中使用 Apache Maven PMD Plugin 检查代码(Java 代码)质量 一个 Maven 项目 假设我有一个 Maven 项目,这个项目包含若干子模块。根目录的 pom.xml 看起来如下: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>my</groupId> <artifactId>my-project</artifactId> <version>${revision}</version> <packaging>pom</packaging> <properties> <revision>0.1.0-SNAPSHOT</revision> </properties> <modules> <module>module-dependencies</module> <module>module-bar</module> <module>module-foo</module> </modules> </project> 在根项目 pom.xml 中增加 maven-pmd-plugin 插件 增加 maven-pmd-plugin 插件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>my</groupId> <artifactId>my-project</artifactId> <version>${revision}</version> <packaging>pom</packaging> <properties> <maven-pmd-plugin.version>3.19.0</maven-pmd-plugin.version> </properties> <modules> <module>module-dependencies</module> <module>module-bar</module> <module>module-foo</module> </modules> <build> <pluginManagement> <plugins> <plugin> <groupId>org.

Read more

在 Maven 项目中使用 Spotbugs Plugin 检查 Java 代码(字节码)质量

本文记录了如何在 Maven 项目中使用 SpotBugs Maven Plugin 检查代码(字节码)质量 一个 Maven 项目 假设我有一个 Maven 项目,这个项目包含若干子模块。根目录的 pom.xml 看起来如下: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>my</groupId> <artifactId>my-project</artifactId> <version>${revision}</version> <packaging>pom</packaging> <properties> <revision>0.1.0-SNAPSHOT</revision> </properties> <modules> <module>module-dependencies</module> <module>module-bar</module> <module>module-foo</module> </modules> </project> 在根项目 pom.xml 中增加 spotbugs-maven-plugin 插件 增加 spotbugs-maven-plugin 插件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>my</groupId> <artifactId>my-project</artifactId> <version>${revision}</version> <packaging>pom</packaging> <properties> <spotbugs-maven-plugin.version>4.7.1.1</spotbugs-maven-plugin.version> </properties> <modules> <module>module-dependencies</module> <module>module-bar</module> <module>module-foo</module> </modules> <build> <pluginManagement> <plugins> <plugin> <groupId>com.

Read more

在 Maven 多模块项目中使用 JaCoCo 检查测试覆盖率

本文记录了如何在 Maven 多模块项目中使用 JaCoCo 生成覆盖率报告并推送到 Sonar 中 一个多模块项目 假设我有一个多模块项目,这个项目包含若干子模块,并且有若干测试用例。根目录的 pom.xml 看起来如下: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>my</groupId> <artifactId>my-project</artifactId> <version>${revision}</version> <packaging>pom</packaging> <properties> <revision>0.1.0-SNAPSHOT</revision> </properties> <modules> <module>module-dependencies</module> <module>module-bar</module> <module>module-foo</module> </modules> </project> 关于 module-dependencies 模块的作用,可以查看我之前写的MAVEN PROJECTS BEST PRACTICES 在根项目 pom.xml 中增加 jacoco-maven-plugin 插件,并增加 module-coverage 模块 增加 jacoco-maven-plugin 插件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>my</groupId> <artifactId>my-project</artifactId> <version>${revision}</version> <packaging>pom</packaging> <properties> <jacoco-maven-plugin.version>0.8.6</jacoco-maven-plugin.version> </properties> <modules> <module>module-dependencies</module> <module>module-bar</module> <module>module-foo</module> <module>module-coverage</module> </modules> <build> <pluginManagement> <plugins> <plugin> <groupId>org.

Read more