Skip to content

Commit

Permalink
add new md
Browse files Browse the repository at this point in the history
  • Loading branch information
LYDongD committed Aug 13, 2019
1 parent 25adf17 commit 7675dab
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
* [脚本分析](dev-ops/shell/script/README.md)
* [快速生成md图片链接](dev-ops/shell/script/pushimage.md)
* [基于地理位置查询脚本](dev-ops/shell/script/geo_search.md)
* [分组统计](dev-ops/shell/script/statistic.md)
* [文本处理](dev-ops/shell/text/README.md)
* [shell](dev-ops/shell/text/shell.md)
* [打印](dev-ops/shell/text/echo.md)
Expand Down
77 changes: 77 additions & 0 deletions dev-ops/shell/script/statistic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
## 分组统计脚本

### 方法执行时间耗时统计

> 模式:
2019-08-13 10:26:54.446 [pool-15-thread-18] INFO com.fcbox.service.function.BoxUsedRateExecutor.doBus (BoxUsedRateExecutor.java:181) [TxId : , SpanId : ] doBus:edcode=FC5750840,count=183,cost=313

> 涉及语法
* 关联数组(字典)
* sed 模式提取
* grep 过滤
* 父子shell
* 循环判断

> 脚本
```
#!/bin/bash
LOG_FILE=/app/applogs/edmssvr/svrs.log
SYNC_FILE=/tmp/tmpSync.log
#fork sub shell to grep data
(grep "doBus:edcode" $LOG_FILE > $SYNC_FILE)
declare -A cost_dic
count=0
max=0
min=100000
#遍历行,提取耗时并分组统计,保存到字典
while read line
do
line=${line}
cost=$(echo ${line} | sed "s/.*cost=\([0-9]*\).*/\1/g" | bc)
if test $[cost] -gt 2000; then
let cost_dic[">2000ms"]+=1
elif test $[cost] -gt 1000; then
let cost_dic["1000-2000ms"]+=1
elif test $[cost] -gt 500; then
let cost_dic["500-1000ms"]+=1
elif test $[cost] -gt 400; then
let cost_dic["400-500ms"]+=1
elif test $[cost] -gt 300; then
let cost_dic["300-400ms"]+=1
elif test $[cost] -gt 200; then
let cost_dic["200-300ms"]+=1
elif test $[cost] -gt 100; then
let cost_dic["100-200ms"]+=1
elif test $[cost] -gt 0; then
let cost_dic["<100ms"]+=1
fi
if test $[cost] -gt $[max]; then
let max=$cost
elif test $[cost] -lt $[min]; then
let min=$cost
fi
let ++count
done < $SYNC_FILE
#打印字典
echo 总数:$count 最大耗时: $max ms 最小耗时: $min ms
echo 分布 数量 占比
for key in ${!cost_dic[*]}; do
percent=$(echo "scale=2;${cost_dic[$key]}*100/$count" | bc)
echo $key ${cost_dic[$key]} $percent%
done
#删除临时文件
rm $SYNC_FILE
```

0 comments on commit 7675dab

Please sign in to comment.