设置应用程序见解需要10分钟。 它为我创造了两天的工作时间。

I've been upgrading my podcast site from a 10 year old WebMatrix site to modern open-source ASP.NET Core with Razor Pages. The site is now off the IIS web server and  running cross-platform in Azure.

我一直在将播客站点从具有10年历史的WebMatrix站点升级到带有Razor Pages的现代开源ASP.NET Core 。 该站点现在不在IIS Web服务器上,并且在Azure中运行跨平台。

I added Application Insights to the site in about 10 min just a few days ago. It was super easy to setup and basically automatic in Visual Studio 2017 Community. I left the defaults, installed a bit of script on the client, and enabled the server-side profiler, and AppInsights already found a few interesting things.

我是在几天前大约10分钟内将Application Insights添加到该站点的。 它在Visual Studio 2017 Community中非常容易设置并且基本上是自动的。 我保留了默认值,在客户端上安装了一些脚本,并启用了服务器端分析器,AppInsights已经发现了一些有趣的东西。

It took 10 minutes to set up App Insights. It took two days (and work continues) to fix what it found. I love it. This tool has already given me a deeper insight into how my code runs and how it's behaving - and I'm just scratching the service. I'll need to do some videos and/or more blog posts to dig deeper. Truly, you need to try it.

设置App Insights花了10分钟。 修复发现的内容花了两天时间(并且工作仍在继续)。 我喜欢它。 这个工具已经使我对代码的运行方式和行为有了更深入的了解-而我只是在抓紧服务。 我需要做一些视频和/或更多博客文章,以进行更深入的研究。 确实,您需要尝试一下。

在其他国家/地区表现不佳 (Slow performance in other countries)

I could fill this blog post with dozens of awesome screenshots of the useful charts, graphs, and filters that I got by just turning on AppInsights. But the most interesting part is that I turned it on really expecting nothing. I figured I'd get some "Google Analytics"-type behavior.

我可以在此博客文章中添加数十个很棒的屏幕快照,这些截图是通过打开AppInsights获得的有用的图表,图形和过滤器。 但是最有趣的部分是,我真的没有期望打开它。 我想我会得到一些“ Google Analytics(分析)”类型的行为。

Then I got this email:

然后我收到了这封电子邮件:

Browser Time is slow in Bangladesh

Huh. I had set up the Azure CDN at images.hanselminutes.com to handle all the faces for each episode. I then added lazy loading so that the webite only loads the images that enter the browser's viewport. I figured I was pretty much done.

嗯我已经在images.hanselminutes.com上设置了Azure CDN,以处理每一集的所有面Kong。 然后,我添加了延迟加载,以便网站仅加载进入浏览器视口的图像。 我想我已经完成了。

However I didn't really think about the page itself as it loads for folks from around the world - given that it's hosted on Azure in the West US.

但是,由于该页面托管在美国西部的Azure上,因此它不会真正为世界各地的人加载,因此我并没有真正考虑过该页面本身。

18.4 secs to load the page in Bangladesh

Ideally I'd want the site to load in less than a second, but this is my archives page with 600 shows so it's pretty heavy.

理想情况下,我希望网站在不到一秒钟的时间内加载,但这是我的存档页面,其中包含600场演出,因此非常繁琐。

That's some long load times

Yuck. I have a few options. I could pay and load up another copy of the site in South Asia and then do some global load balancing. However, I'm hosting this on a single small (along with a dozen other sites) so I don't want to really pay much to fix this.

uck 我有几个选择。 我可以支付并加载该站点在南亚的另一个副本,然后进行一些全局负载平衡。 但是,我将其托管在一个小型站点(以及其他十二个站点)上,所以我不想花很多钱来解决这个问题。

I ended up signing up for a free account at CloudFlare and set up caching for my HTML. The images stay the same. served by the Azure CDN.

我最终在CloudFlare上注册了一个免费帐户,并为HTML设置了缓存。 图像保持不变。 由Azure CDN提供服务。

Lots of requests from Cloudflare

修复随机和常规Server 500错误 (Fixing Random and regular Server 500 errors)

I left the site up for a while and came back later to a warning. You can see my site availability is just 93%. Note that there's "2 Servers?" That's because one is my local machine! Very cool that AppInsights also (optionally) tracks your local development server as well.

我离开网站一会儿,稍后再返回警告。 您可以看到我的网站可用性仅为93%。 请注意,这里有“ 2台服务器?” 那是因为一台是我的本地机器! AppInsights还可(可选)也跟踪您的本地开发服务器,这一点非常酷。

1 Alert!

When I dig in I see a VERY interesting sawtooth pattern.

当我深入挖掘时,会看到一个非常有趣的锯齿图案。

Pro Tip - Recognizing that a Sawtooth Pattern is a Bad Thing (tm) is an important DevOps thing. Why is this happening regularly? Is it exactly regularly (like every 4 hours on a schedule?) or somewhat regularly (like a garbage collection issue?)

专家提示-认识到锯齿模式是一件坏事(tm)是DevOps的重要一件事。 为什么会定期发生这种情况? 是完全定期(例如按计划每4个小时进行一次)还是定期(例如垃圾回收问题?)?

What do these operations have in common? Look closely.

这些操作有什么共同点? 仔细看。

scarygraph

It's not a GET it's a HEAD. Remember that HTTP Verbs are more than GET, POST, PUT, DELETE. There's also HEAD. It literally is a HEADer call. Like a GET, but no body.

不是GET,而是HEAD。 请记住,HTTP动词不仅仅是GET,POST,PUT,DELETE。 还有头。 它实际上是一个HEADer调用。 像一个GET,但没有身体。

HTTP HEAD - The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.

HTTP HEAD- HEAD方法与GET相同,不同之处在于服务器在响应中不得返回消息正文。

I installed HTTPie - which is like curl or wget for humans - and issue a HEAD command from my local machine while under the debugger.

我安装了HTTPie(对于人类来说就像curl或wget一样),并在调试器下从本地计算机发出HEAD命令。

C:>http --verify=no HEAD https://localhost:5001
HTTP/1.1 500 Internal Server Error
Content-Type: text/html; charset=utf-8
Date: Tue, 13 Mar 2018 03:41:51 GMT
Server: Kestrel

Ok that is bad. See the 500? I check out AppInsights and see it has the full call stack. See it's getting a NullReferenceException as it tries to Render() the Razor page?

好的,这很糟糕。 看到500了吗? 我检查了AppInsights,发现它具有完整的调用堆栈。 看到它试图渲染Razor页面时看到NullReferenceException吗?

Null Reference Exception

It turns out since I'm using Razor Pages, I have implemented "OnGet" where I do my data base work then pass a model to the pages to generate HTML. However, if someone issues a HEAD, then the pages still run but the local data work never happened (I have no OnHead() call). I have a few options here. I could handle HEAD myself. I could no-op it, but that'd be a lie.

事实证明,由于我使用的是Razor页面,因此我实现了“ OnGet”,我在其中进行数据库工作,然后将模型传递给页面以生成HTML。 但是,如果有人发出HEAD,则页面仍然运行,但是本地数据工作从未发生(我没有OnHead()调用)。 我在这里有一些选择。 我自己可以应付HEAD。 我无法操作,但这是一个谎言。

THOUGHT: I think this behavior is sub-optimal. While GET and POST are distinct and it makes sense to require an OnGet() and OnPost(), I think that HEAD is special. It's basically a GET with a "don't return the body" flag set. So why not have Razor Pages automatically delegate OnHead to OnGet, unless there's an explicit OnHead() declared? I'll file an issue on GitHub because I don't like this behavior and I find it counter-intuitive. I could also register a global IPageFilter to make this work for all my site's pages.

思想:我认为这种行为不是最佳的。 尽管GET和POST是不同的,并且需要OnGet()和OnPost()有意义,但我认为HEAD很特殊。 从根本上说,这是一个带有“不退回身体”标志的GET。 那么,为什么没有Razor Pages自动将OnHead委托给OnGet,除非声明了一个明确的OnHead()? 我将在GitHub上提出问题,因为我不喜欢这种行为,并且发现它违反直觉。 我还可以注册一个全局IPageFilter来使我的所有网站页面都可以使用。

The simplest thing to do is just to delegate the OnHead to to the OnGet handler.

最简单的事情就是将OnHead委托给OnGet处理程序。

public Task OnHeadAsync(int? id, string path) => OnGetAsync(id, path);

Then double check and test it with HTTPie:

然后仔细检查并使用HTTPie进行测试:

C:\>http --verify=no HEAD https://localhost:5001
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Date: Tue, 13 Mar 2018 03:53:55 GMT
Request-Context: appId=cid-v1:e310025f-88e9-4133-bc15-e775513c67ac
Server: Kestrel

奖金-应用地图 (Bonus - Application Map)

Since I have AppInsights enabled on both the client and the server, I can see this cool live Application Map. I'll check again in a few days to see if I have fewer errors. You can see where my Podcast Site calls into the backend data service at Simplecast.

由于我在客户端和服务器上均启用了AppInsights,因此可以看到此实时应用程序映射。 几天后我将再次检查以查看错误是否减少。 您可以在Simplecast上看到我的Podcast网站在哪里调用后端数据服务。

An application map that shows all the components, both client and server

I saw a few failures in my call to SimpleCast's API as I was failing to consistently set my API key. Everything in this map can be drilled down into.

在调用SimpleCast API时遇到了一些失败,因为我未能始终如一地设置API密钥。 该地图中的所有内容均可深入查看。

奖金-网站性能测试 (Bonus - Web Performance Testing)

I figured while I was in the Azure Portal I would also take advantage of the free performance testing. I did a simulated aggressive 250 users beating on the site. Average response time is 1.22 seconds and I was doing over 600 req/second.

当我在Azure门户中时,我发现我还将利用免费的性能测试。 我在网站上模拟了激进的250名用户。 平均响应时间为1.22秒,我的响应速度超过600请求/秒。

38097 successful calls

I am learning a ton of stuff. I have more things to fix, more improvements to make, and more insights to dig into. I LOVE that it's creating all this work for me because it's giving me a better application/website!

我正在学习很多东西。 我还有更多要修复的事情,需要改进的地方以及需要挖掘的更多见解。 我喜欢它为我创造了所有这些工作,因为它为我提供了更好的应用程序/网站!

You can get a free Azure account at http://azure.com/free or check out Azure for Startups https://azure.microsoft.com/overview/startups/ and get a bunch of free Azure time. AppInsights works with Node, Docker, Java, ASP.NET, ASP.NET Core, and other platforms. It even supports telemetry in Electron or Windows Apps.

您可以在http://azure.com/free上获得免费的Azure帐户,或通过Azure for Startups https://azure.microsoft.com/overview/startups/查看并获得大量的免费Azure时间。 AppInsights可与NodeDockerJavaASP.NETASP.NET Core和其他平台一起使用。 它甚至支持Electron或Windows Apps中的遥测

翻译自: https://www.hanselman.com/blog/setting-up-application-insights-took-10-minutes-it-created-two-days-of-work-for-me

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值