问题描述
App Service上可以收.NET 应用的Profile Trace文件,并且可以自动分析报告。
Collect a Profiler Trace
If your app is down or performing slow, you can collect a profiling trace to identify the root cause of the issue. Profiling is light weight and is designed for production scenarios.
What you should know before collecting a Profiler trace
- Once the profiler trace is started, reproduce the issue by browsing to the web app.
- The profiler trace will automatically stop after 60 seconds.
- If thread report option is enabled, then raw stack traces of threads inside the process will be collected as well.
- With thread report option, your App may be paused for a few seconds till all the threads are dumped.
- Your web app will not be restarted as a result of running the profiler.
- A profiler trace will help to identify issues in an ASP.NET or ASP.NET Core application.
只是,查看的报告中,所以数据均无法显示,如下图:
如何来解决这个问题呢?
问题解答
在报告页面中打开“开发者模式”,查看Console日志或者是Networks日志,发现问题是因为 js /css 文件无法访问导致。
GET https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js net::ERR_CONNECTION_TIMED_OUT
因为中国区Azure所部署的位置位于北京,上海区域。所以无法正常访问 Google API,无法直接获取 angular.min.js 资源。所以可以通过修改html的 js应用路径来解决问题。
第一步:找到一个在中国区Azure可以访问的 1.2.15 版本的 angular.min.js
可以使用 https://cdn.bootcdn.net/ajax/libs/angular.js/1.2.15/angular.min.js 替换 https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js
第二步:打开App Service的Kudu站点,进入DebugConsole
寻找 Data/DaaS/Reports/240701_1119225346/240701_1121184125/dw0sdwk00002D/index.html 文件, 然后编辑。 注意 “/240701_1119225346/240701_1121184125/dw0sdwk00002D/” 这部分内容会根据具体的时间,实例名发生变动。
第三步:在HTML文件种替换 angular.min.js
## 把 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script> ## 替换为 <script src="https://cdn.bootcdn.net/ajax/libs/angular.js/1.2.15/angular.min.js"></script>
再次打开 Profiler Report 页面,加载数据成功!
参考资料
Angular JS: https://www.bootcdn.cn/angular.js/
Collect .NET Profiler Trace : https://appserviceblog.com/en/collect-net-profiler-trace/
App Service Diagnostics – Profiling an ASP.NET Web App on Azure App Service : https://azure.github.io/AppService/2018/06/06/App-Service-Diagnostics-Profiling-an-ASP.NET-Web-App-on-Azure-App-Service.html
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!