🦋
Butterfly 用户手册
  • Introduction
  • 一 前言
  • 二 开始
    • 安装部署
    • 五分钟体验指南
    • 单机使用手册
    • 应用规范
      • handler specs
      • middleware specs
      • xingqiao_plugin specs
      • yiqiu_program specs
  • 三 客户端功能
    • MySQL 原生协议
    • MySQL ORM
    • Redis 原生协议
      • redis_config
      • redis_tls
    • Redis ORM
    • Redis mcpack
    • Localcache
    • Kazoo
  • 四 应用(通用服务)
    • API JSON 规范
    • 异步任务 BaiChuan(百川)
    • 任务调度 RuQi(如期)
    • 任务编排 XingQiao(星桥)
    • 配置管理 WuXing(五行)
    • 运筹决策 BaiCe(百策)
  • 五 部署运维
    • 单机容器化部署
    • 监控
    • 异常排查
      • CPU Load spike every 7 hours
    • 升级
    • 安全
    • 其他
  • 六 前端
    • butterfly_template
    • butterfly_fe
    • butterfly-admin(json2web)
      • amis
      • sso
      • pangu
    • NoahV
    • PyWebIO
  • 七 潘多拉魔盒
    • 装饰器
      • localcache_decorator
      • retry_decorator
      • custom_decorator
      • command2http_decorator
    • 算法
      • 算法-分位数
      • 算法-变异系数
    • 实用工具
      • host_util
      • shell_util
      • http_util
      • time_util
      • random_util
      • concurrent
      • jsonschema
      • blinker
      • toml
      • command_util
      • config_util
      • picobox
      • 对称加密
        • des
        • aes
      • ascii_art
        • ttable
        • chart
      • business_rules
      • python-mysql-replication
      • dict_util
    • 中间件
      • middleware_status
      • middleware_whitelist
    • test_handler.py
  • 八 最佳实践
    • 分布式架构
    • Code practice
    • Log practice
    • Daemon process
  • 附录
Powered by GitBook
On this page
  • 1 进程监控
  • 2 日志监控
  • 2.1 请求数
  • 2.2 平响
  1. 五 部署运维

监控

如下配置需要监控系统的配合,具体监控请参照自己厂内的监控配置说明

1 进程监控

butterfly_process

介绍:采集进程的 CPU/Memmory/ 网络句柄 / 磁盘 io 等信息
--------------------------------------------- 监控配置
类型:进程
采集任务名称:butterfly_process
进程路径:/home/work/.jumbo/bin/python2.7 wuxing_4200
采集周期:10s

--------------------------------------------- 备注
进程路径:"解释器路径 + 可执行程序名"
(1) 解释器路径:/proc/${pid}/exe 的软链接,如 ll /proc/{pid}/exe
(2) 可执行程序名:/proc/${pid}/cmdline 字符串的子串,此子串可唯一标识此进程

项目目录软连之后 proc 下项的变化(pid 是 21700)

$ ll | grep butterfly

drwxr-xr-x 7 work work 4096 2月 11 16:12 butterfly

lrwxrwxrwx 1 work work 9 2月 21 17:12 butterfly_testxxxx -> butterfly

$ ps -ef | grep 21700

work 21700 1 0 17:12 ? 00:00:00 python2.7 /tmp/butterfly_testxxxx/butterfly/main.py 954216e9

$ ll /proc/21700

lrwxrwxrwx. 1 work work 0 2月 21 17:12 cwd -> /tmp/butterfly/butterfly

lrwxrwxrwx. 1 work work 0 2月 21 17:12 exe -> /home/work/.jumbo/bin/python2.7

-r--r--r--. 1 work work 0 2月 21 17:12 cmdline

$ cat /proc/21700/cmdline

python2.7/tmp/butterfly_testxxxx/butterfly/main.py954216e9

可以看出 /proc/${pid}/exe 和 /proc/${pid}/cwd 均为文件的物理路径

/proc/${pid}/cmdline 中的内容是 ps 看到的命令行(cat 时不显示分割符号,可以重定向到文件中,使用 vim 打开,会发现是使用 ^@ 分割的)

2 日志监控

2.1 请求数

2.1.1 pv

pv(page view)

介绍:请求 pv, 监控上的 pv/10 是真正的 pv
--------------------------------------------- 监控配置
日志路径:${DEPLOY_DIR}/logs/acc.log
采集周期:10s
匹配字符:httpgateway.py

--------------------------------------------- 监控项
pv_cnt:(count) 周期内匹配数,此监控项表示周期内匹配到关键词的行数,因为 acc.log 为访问日志,即为 10s 内的请求个数
pv_cps:(count per second) 周期内每秒匹配数,这个数字可以代表咱们服务的 RPS(requests per second)

2.1.2 async_pv

介绍:开启百川后,butterfly 服务将会自动处理 MQ 中的任务,此监控项表示当前 butterfly 的处理任务量
--------------------------------------------- 监控配置
日志路径:${DEPLOY_DIR}/logs/acc.log
采集周期:10s
匹配字符:worker.py

--------------------------------------------- 监控项
async_pv_cnt:(count) 周期内匹配数,此监控项表示周期内匹配到关键词的行数,因为 acc.log 为访问日志,即为 10s 内的请求个数
async_pv_cps:(count per second) 周期内每秒匹配数,这个数字可以代表咱们服务的 RPS(requests per second)

2.2 平响

cost

介绍:响应时间
--------------------------------------------- 监控配置
日志路径:${DEPLOY_DIR}/logs/acc.log
采集周期:10s
匹配字符:cost:(-?\d+\.\d+|-?\d+)
--------------------------------------------- 监控项
cost_cnt:同上
cost_cps:同上
cost_min:周期内,响应时间最小值
cost_avg: 周期内,响应时间平均值
cost_max: 周期内,响应时间最大值
cost_sum: 周期内,响应时间之和
--------------------------------------------- 正则表达式解释
(零次或一次 '-' 号)(一次或多次 '\d' 数字)(小数点 '.')(一次或多次 '\d' 数字) ===> 比如:0.25、-3.6
或者
(零次或一次 '-' 号)(一次或多次 '\d' 数字) ===================================> 比如:21、-6

自定义其他监控

如何新增自定义监控采集项:
可以通过在:
req.log_res.add("item:xxx"), 然后通过类似 cost 方式进行采集
Previous单机容器化部署Next异常排查

Last updated 3 months ago