注:本文会持续更新

  • 以冒号为分隔符,将字符串切分为数组
1
IFS=: read -r -a config <<< "$d"
  • 获取一分钟前的时刻
1
2
TIME=$(date -d "1 minute ago" "+%Y-%m-%d %H:%M")
echo $TIME
  • 日志分析脚本

分析接口运行时间的分布

1
awk '{split($6, request, "?"); api_stat[request[1], "count"] += 1; time=$(NF-2); gsub(/[\[|\]]/, "", time); if (time <= 0.5) {api_stat[request[1], "count1"] += 1;} if (time > 0.5 && time <= 1.0) {api_stat[request[1], "count2"] += 1;} if (time > 1.0 && time <= 1.5) {api_stat[request[1], "count3"] += 1;} if (time > 1.5 && time <= 2.0) {api_stat[request[1], "count4"] += 1;} if (time > 2.0 && time <= 2.5) {api_stat[request[1], "count5"] += 1;} if (time > 2.5 && time <= 3.0) {api_stat[request[1], "count6"] += 1;} if (time > 3.0) {api_stat[request[1], "count7"] += 1;}} END {for (api in api_stat) { split(api, key, SUBSEP); print key[1], key[2], api_stat[api];} }'
1
awk -F '[][]' '{api_stat[$6, "count"] += 1; if ($8 <= 50.0) {api_stat[$6, "count1"] += 1;} if ($8 > 50.0 && $8 <= 100.0) {api_stat[$6, "count2"] += 1;} if ($8 > 100.0 && $8 <= 150.0) {api_stat[$6, "count3"] += 1;} if ($8 > 150.0 && $8 <= 200.0) {api_stat[$6, "count4"] += 1;} if ($8 > 200.0 && $8 <= 250.0) {api_stat[$6, "count5"] += 1;} if ($8 > 250.0 && $8 <= 300.0) {api_stat[$6, "count6"] += 1;} if ($8 > 300.0 && $8 <= 350.0) {api_stat[$6, "count7"] += 1;} if ($8 > 350.0 && $8 <= 400.0) {api_stat[$6, "count8"] += 1;} if ($8 > 400.0 && $8 <= 450.0) {api_stat[$6, "count9"] += 1;} if ($8 > 450.0 && $8 <= 500.0) {api_stat[$6, "count10"] += 1;} if ($8 > 500.0) {api_stat[$6, "count11"] += 1;} } END {for(api in api_stat) { split(api, key, SUBSEP); print key[1], key[2], api_stat[api];}}' doota_curl_time_003*
  • 命令行格式化json
1
python -mjson.tool