一.目的
1.开发环境中可以通过监控报表来快速发现/定位问题,提高开发人员排查错误,优化代码的便捷性
二.方案
1.集成 [Tideways](https://github.com/tideways/php-xhprof-extension) ,监控面板 项目使用Xhgui
2.日志 存储服务使用mongo,设置创建对应的存储数据库,设置索引,设置监控记录过期时常(10h/20h/30h)
3.每一次 请求都把相应的监控报表地址写入到Response Header中(Xhprof:xxxxx/disable)
三.实现步骤
1.Nginx镜像集成[headers-more-nginx-module](https://github.com/openresty/headers-more-nginx-module#installation)
2.开发环境添加mongo服务(docker pull mongo)
3.PHP 镜像安装[mongodb](https://docs.mongodb.com/php-library/current/tutorial/install-php-library/)/[tideways_xhprof](https://github.com/tideways/php-xhprof-extension)扩展 (mongodb.so tideways_xhprof.so)
4.开发环境部署xhgui中文版项目(composer 安装好依赖包)
5.修改需要监控的本地服务的 nginx配置文件xxx.conf (示例文件:./etc/nginx/conf.d/shop_old.conf)
四.效果示范

image.png

image.png

image.png
五.项目地址
1.Docker环境项目 [git@code.aliyun.com:baqianxin/local-dev.git](http://code.aliyun.com:baqianxin/local-dev.git)
2.Xhgui面板项目 [git@code.aliyun.com:baqianxin/xhgui.git](http://code.aliyun.com:baqianxin/xhgui.git)
参考文档: